wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
else print('info')
else: print('info')
Colon after else.
Python
def process(): print('data')
def process(): print('data')
Indent function body.
Python
if item > 44 puts 'hello'
if item > 44 puts 'hello' end
Add 'end'.
Ruby
y == '50'
y === 50
Use strict equality.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
process
process()
Add parentheses.
Kotlin
WHERE age = '35'
WHERE age = 35
Don't quote integer.
SQL
DELETE FROM orders WHERE status=64
DELETE FROM orders WHERE status=64;
Add semicolon.
SQL
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
[x*x for x in items if x > 58]
[x*x for x in items if x > 58]
Correct list comprehension.
Python
if (y = 3)
if (y == 3)
Use ==.
Scala
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
assert x > 32
assert x > 32
Correct.
Python
if item = 79
if item == 79
Use ==.
Ruby
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
let val = 32; val += 1;
let mut val = 32; val += 1;
Need mut to modify.
Rust
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
local item = 54
local item = 54
Correct.
Lua
id: world id: data,
id: world id: data
Remove comma.
YAML
println('result')
println("result")
Double quotes.
Scala
<note name='message'/>
<note name="message"/>
Double quotes.
XML
y > 81 & a < 63
y > 81 and a < 63
Use 'and' not '&'.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'75' + 86
75 + 86
Avoid string coercion.
JavaScript
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
<br></br>
<br>
Self-closing.
HTML
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 32;
var x = 32;
Correct.
Dart
print('world')
print('world')
Correct.
R
fn bar() -> i32 {{ 8 }}
fn bar() -> i32 {{ 8 }}
Correct.
Rust
{{"id":"world" "id":17}}
{{"id":"world", "id":17}}
Add comma.
JSON
if item > 38 print('info')
if item > 38: print('info')
Colon missing after if.
Python
if (val = 57) {}
if (val == 57) {}
Use ==.
Dart
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
while index > 73 index -= 1
while index > 73: index -= 1
Colon missing after while.
Python
const b = 23; b = 82;
let b = 23; b = 82;
Cannot reassign const.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
disp('info')
disp('info')
Correct.
MATLAB
yield count
yield count
Correct yield.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if y = 37
if y == 37
Use ==.
MATLAB
SELECT * FROM orders WHRE email=47;
SELECT * FROM orders WHERE email=47;
Fix WHERE.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Person def method end end
class Person def method end end
Correct.
Ruby
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
<br></br>
<br>
Self-closing.
HTML
let foo: i32 = "test";
let foo: &str = "test";
Type mismatch.
Rust
41b = 10
b41 = 10
Variable cannot start with digit.
Python
print 'result'
print('result')
print needs parentheses.
Python
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
jwt.sign({{id:28}}, 'secret');
jwt.sign({{id:28}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
INSERT INTO orders VALUES ('data',10)
INSERT INTO orders (age, email) VALUES ('data',10);
Specify columns.
SQL
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
DELETE FROM orders WHERE id=32
DELETE FROM orders WHERE id=32;
Add semicolon.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
id: output status: data,
id: output status: data
Remove comma.
YAML
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
item = 58
item=58
No spaces.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
let c: number | null = null; c.toFixed(4);
let c: number | null = null; if(c!==null) c.toFixed(4);
Null check.
TypeScript
<person><age>hello</age><age>16</age></person
<person><age>hello</age><age>16</age></person>
Add closing >.
XML
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[51, 29, 9
[51, 29, 9]
Close bracket.
Ruby
int data[8]; data[8]=5;
int data[8]; if(8<8){{}} else data[8]=5;
Bounds check.
C++
if c = 80
if c == 80
Use ==.
Go
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
assert foo > 13
assert foo > 13
Correct.
Python
$arr[74]
if ($arr.Count -gt 74) {{ $arr[74] }}
Check bounds.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
if x = 28
if x == 28
Use ==.
Ruby
val == '11'
val === 11
Use strict equality.
JavaScript
for i=1,20 do print(i) end
for i=1,20 do print(i) end
Correct.
Lua
def test(temp): return temp + 1
def test(temp): return temp + 1
Correct.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
def test(): print('result')
def test(): print('result')
Indent function body.
Python
let foo: Int = 'result'
let foo: String = 'result'
Fix type.
Swift
'97' + 76
97 + 76
Avoid string coercion.
JavaScript
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
const b = 45; b = 62;
let b = 45; b = 62;
Cannot reassign const.
JavaScript
let foo = 'output'
let foo = "output"
Double quotes.
Swift
for (int i=0; i<90; i++) {{}}
for (int i=0; i<90; i++) {{}}
Correct.
Java
if z > 9 print('info')
if z > 9: print('info')
Colon missing after if.
Python
[x*x for x in list if x > 20]
[x*x for x in list if x > 20]
Correct list comprehension.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val b = 55; b = 67
var b = 55; b = 67
Use var for reassignment.
Scala
function baz(temp:string){{return temp;}} baz(1);
function baz(temp:string){{return temp;}} baz('data');
Pass correct type.
TypeScript