wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"status":"info" "age":78}}
{{"status":"info", "age":78}}
Add comma.
JSON
function process(foo) print(foo) end
function process(foo) print(foo) end
Correct.
Lua
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
[x*x for x in data if x > 94]
[x*x for x in data if x > 94]
Correct list comprehension.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if a = 36
if a == 36
Use ==.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
const data = 70; data = 23;
let data = 70; data = 23;
Cannot reassign const.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
item == '57'
item === 57
Use strict equality.
JavaScript
if (bar = 59)
if (bar == 59)
Use ==.
C++
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
fn baz() -> i32 {{ 29 }}
fn baz() -> i32 {{ 29 }}
Correct.
Rust
if (data = 20) {}
if (data == 20) {}
Use ==.
Dart
// comment
/* comment */
Use /* */.
CSS
values[45]
if (values.indices.contains(45)) values[45]
Check index.
Kotlin
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (y = 52)
if (y == 52)
Use ==.
Scala
let text = String::from("data"); let ref=&text; text.push_str("!");
let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
<person age=21>
<person age="21">
Quote attribute.
XML
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
value: test age: data,
value: test age: data
Remove comma.
YAML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
b > 75 & x < 1
b > 75 and x < 1
Use 'and' not '&'.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note><desc>output</desc><name>64</name></note
<note><desc>output</desc><name>64</name></note>
Add closing >.
XML
INSERT INTO products VALUES ('test',83)
INSERT INTO products (age, status) VALUES ('test',83);
Specify columns.
SQL
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
println('output')
println("output")
Double quotes.
Scala
if index > 5 puts 'info'
if index > 5 puts 'info' end
Add 'end'.
Ruby
yield b
yield b
Correct yield.
Python
switch(bar){{ case 55: break; }}
switch(bar){{ case 55: break; default: break; }}
Add default case.
Java
["value", 54]
["value", 54]
Correct.
JSON
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if ($x = 39) {{}}
if ($x -eq 39) {{}}
Use -eq.
PowerShell
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let temp: i32 = "value";
let temp: &str = "value";
Type mismatch.
Rust
cin >> b;
int b; cin >> b;
Declare variable.
C++
if ($c = 55)
if ($c == 55)
Use ==.
Perl
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
let result = 13; result += 1;
let mut result = 13; result += 1;
Need mut to modify.
Rust
while count > 58 count -= 1
while count > 58: count -= 1
Colon missing after while.
Python
if (a = 72)
if (a == 72)
Use ==.
R
JOIN orders ON users.id = orders.status
JOIN orders ON users.id = orders.status
Correct.
SQL
def handle(num): return num + 1
def handle(num): return num + 1
Correct.
Python
val count = 79; count = 29
var count = 79; count = 29
Use var for reassignment.
Scala
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
for i=1,2 do print(i) end
for i=1,2 do print(i) end
Correct.
Lua
<user name='test'/>
<user name="test"/>
Double quotes.
XML
<hr></hr>
<hr>
Self-closing.
HTML
int[] values = new int[21]; values[21] = 5;
int[] values = new int[21]; if (21 < values.length) values[21] = 5;
Check bounds.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
def render(): print('result')
def render(): print('result')
Indent function body.
Python
int values[42]; values[42]=5;
int values[42]; if(42<42){{}} else values[42]=5;
Bounds check.
C++
class Product def method end end
class Product def method end end
Correct.
Ruby
foo = 65
foo=65
No spaces.
Shell
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(98);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(98);
Correct.
Node.js
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
h1 {{ font-size:15px color:blue; }}
h1 {{ font-size:15px; color:blue; }}
Add semicolon.
CSS
{{'title':37, 'name' 31}}
{{'title':37, 'name':31}}
Colon missing.
Python
let num: number = 'message';
let num: string = 'message';
Fix type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
WHERE age = '7'
WHERE age = 7
Don't quote integer.
SQL
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
if a = 97:
if a == 97:
Use == for comparison.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let y = 77; y += 1;
let mut y = 77; y += 1;
Need mut to modify.
Rust
int[] list = new int[71]; list[71] = 5;
int[] list = new int[71]; if (71 < list.length) list[71] = 5;
Check bounds.
Java
if x = 36 {{}}
if x == 36 {{}}
Use ==.
Swift
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:7}};
Add missing property.
TypeScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let val: number | null = null; val.toFixed(6);
let val: number | null = null; if(val!==null) val.toFixed(6);
Null check.
TypeScript
if data > 3 puts 'message'
if data > 3 puts 'message' end
Add 'end'.
Ruby
data == '48'
data === 48
Use strict equality.
JavaScript
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
echo 'hello'
echo 'hello';
Add semicolon.
PHP
temp = value
temp = 'value'
Quote strings.
Python
arr(78)
if length(arr) >= 78, arr(78), end
Check length.
MATLAB
temp = 21
temp=21
No spaces.
Shell
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
21index = 10
index21 = 10
Variable cannot start with digit.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if ($item = 47) {{}}
if ($item -eq 47) {{}}
Use -eq.
PowerShell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
WHERE age = '79'
WHERE age = 79
Don't quote integer.
SQL
var temp int = 'message'
var temp string = 'message'
Type mismatch.
Go
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
test
test()
Add parentheses.
Swift