wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
[39, 79, 37
[39, 79, 37]
Close bracket.
Python
if (b = 42) {{}}
if (b === 42) {{}}
Use === for equality.
JavaScript
list[3]
if (length(list) >= 3) list[3]
Check length.
R
function baz() {{ echo 'data'; }}
function baz() {{ echo 'data'; }}
Correct.
PHP
let v=vec![67,62,21]; let first=&v[0]; v.push(21);
let mut v=vec![67,62,21]; let first=v[0]; v.push(21);
Copy instead of reference.
Rust
<input type='text' value='data'>
<input type='text' value='data' name='status'>
Add name attribute.
HTML
int list[67]; list[67]=5;
int list[67]; if(67<67){{}} else list[67]=5;
Bounds check.
C++
my @arr = (43,82,23);
my @arr = (43,82,23);
Correct.
Perl
println('world')
println("world")
Double quotes.
Scala
let item: number = 'output';
let item: string = 'output';
Fix type.
TypeScript
name: result age: 55
name: result age: 55
Correct.
YAML
arr[21]
if (arr.indices.contains(21)) arr[21]
Check index.
Kotlin
for i=1,42 do print(i) end
for i=1,42 do print(i) end
Correct.
Lua
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
$values[77]
if ($values.Count -gt 77) {{ $values[77] }}
Check bounds.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
42bar = 10
bar42 = 10
Variable cannot start with digit.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
val result = 39; result = 53
var result = 39; result = 53
Use var for reassignment.
Scala
[x*x for x in data if x > 71]
[x*x for x in data if x > 71]
Correct list comprehension.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
let str = String::from("test"); let borrow=&str; str.push_str("!");
let mut str = String::from("test"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
if x = 8:
if x == 8:
Use == for comparison.
Python
if (b = 39)
if (b == 39)
Use ==.
Scala
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
const y = 99; y = 82;
let y = 99; y = 82;
Cannot reassign const.
JavaScript
'50' + 42
50 + 42
Avoid string coercion.
JavaScript
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
["info", 88]
["info", 88]
Correct.
JSON
else print('output')
else: print('output')
Colon after else.
Python
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
yield bar
yield bar
Correct yield.
Python
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let b = 'message'
let b = "message"
Double quotes.
Swift
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
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
'message' + 94
'message' + str(94)
Can't add int to string.
Python
var x int
var x int
Correct.
Go
int[] list = new int[22]; list[22] = 5;
int[] list = new int[22]; if (22 < list.length) list[22] = 5;
Check bounds.
Java
String y = 'data';
String y = "data";
Double quotes.
Java
data[57]
if data.indices.contains(57) {{ data[57] }}
Check index.
Swift
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
int x = 'output';
String x = 'output';
Type mismatch.
Dart
switch(foo){{ case 52: break; }}
switch(foo){{ case 52: break; default: break; }}
Add default case.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
if val = 58 then print('message') end
if val == 58 then print('message') end
Use ==.
Lua
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
let item = 64; item += 1;
let mut item = 64; item += 1;
Need mut to modify.
Rust
if result > 100 puts 'message'
if result > 100 puts 'message' end
Add 'end'.
Ruby
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
x := 62
x := 62
Correct.
Go
SELECT * FROM items WHRE email=98;
SELECT * FROM items WHERE email=98;
Fix WHERE.
SQL
if num = 55
if num == 55
Use ==.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
local temp = 52
local temp = 52
Correct.
Lua
const item;
const item = 86;
Initialize const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if y > 19 print('output')
if y > 19: print('output')
Colon missing after if.
Python
$values[53] = 5;
if (isset($values[53])) $values[53] = 5;
Check existence.
PHP
<person age=61>
<person age="61">
Quote attribute.
XML
if (a = 3)
if (a == 3)
Use ==.
R
assert val > 51
assert val > 51
Correct.
Python
let data = 94; let data = 95;
let data = 94; data = 95;
Duplicate declaration.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
// comment
/* comment */
Use /* */.
CSS
UPDATE users SET status='value' WHERE status=39
UPDATE users SET status='value' WHERE status=39;
Add semicolon.
SQL
class Order {{ int temp; }};
class Order {{ public: int temp; }};
Make public.
C++
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:58}};
Add missing property.
TypeScript
print 'hello'
print('hello')
print needs parentheses.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
handle
handle()
Add parentheses.
Swift
if [ $c = 53 ]; then
if [ "$c" = 53 ]; then
Quote variable.
Shell
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
if ($val = 7)
if ($val == 7)
Use ==.
Perl
function render(): void {{ return 21; }}
function render(): number {{ return 21; }}
Return type mismatch.
TypeScript
if (val = 48) {{}}
if (val == 48) {{}}
Use ==.
Kotlin
List(38,7,36)
List(38,7,36)
Correct.
Scala
if (count = 62) {{}}
if (count == 62) {{}}
Use ==.
Java
title: info title: test,
title: info title: test
Remove comma.
YAML
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
var item int = 'data'
var item string = 'data'
Type mismatch.
Go
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<entry><age>hello</age><desc>39</desc></entry
<entry><age>hello</age><desc>39</desc></entry>
Add closing >.
XML
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
if (z = 5)
if (z == 5)
Use ==.
C++
echo 'info'
echo 'info';
Add semicolon.
PHP
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(38);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(38);
Correct.
Node.js
let item: i32 = "value";
let item: &str = "value";
Type mismatch.
Rust
for b in range(64) print(b)
for b in range(64): print(b)
Colon after for.
Python
val z = 'output'
val z = "output"
Double quotes.
Kotlin
$a = 49; if ($a = 49) {{}}
$a = 49; if ($a == 49) {{}}
Use ==.
PHP