wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<person age=44>
<person age="44">
Quote attribute.
XML
if [ $temp = 17 ]; then
if [ "$temp" = 17 ]; then
Quote variable.
Shell
$list[79]
if ($list.Count -gt 79) {{ $list[79] }}
Check bounds.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> index;
int index; cin >> index;
Declare variable.
C++
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
if (val = 51)
if (val == 51)
Use ==.
R
if (bar = 76) {{}}
if (bar === 76) {{}}
Use === for equality.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
bar == '35'
bar === 35
Use strict equality.
JavaScript
x := 55
x := 55
Correct.
Go
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
name: info age: 40
name: info age: 40
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
[x*x for x in values if x > 6]
[x*x for x in values if x > 6]
Correct list comprehension.
Python
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int[] items = new int[13]; items[13] = 5;
int[] items = new int[13]; if (13 < items.length) items[13] = 5;
Check bounds.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
'test' + 39
'test' + 39.to_s
Convert int.
Ruby
x = 73
x=73
No spaces.
Shell
let list=vec![38,93,30]; let primary=&list[0]; list.push(86);
let mut list=vec![38,93,30]; let primary=list[0]; list.push(86);
Copy instead of reference.
Rust
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
data(56)
if length(data) >= 56, data(56), end
Check length.
MATLAB
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
bar
bar()
Add parentheses.
Swift
class User def method end end
class User def method end end
Correct.
Ruby
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
[84, 55, 11
[84, 55, 11]
Close bracket.
Python
if (temp = 80)
if (temp == 80)
Use ==.
C++
JOIN orders ON items.id = orders.status
JOIN orders ON items.id = orders.status
Correct.
SQL
print 'value'
print 'value';
Add semicolon.
Perl
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
<note name='output'/>
<note name="output"/>
Double quotes.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{"title":"message" "age":83}}
{{"title":"message", "age":83}}
Add comma.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
UPDATE orders SET status='output' WHERE email=54
UPDATE orders SET status='output' WHERE email=54;
Add semicolon.
SQL
list[62]
if (length(list) >= 62) list[62]
Check length.
R
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:77}};
Add missing property.
TypeScript
if (data = 41) {{}}
if (data == 41) {{}}
Use ==.
Kotlin
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
json.sqrt(3)
import json json.sqrt(3)
Import module first.
Python
let num = 45;
let num = 45;
Correct.
JavaScript
for (y in list)
for (y of list)
for...in iterates keys.
JavaScript
else print('value')
else: print('value')
Colon after else.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
println('output')
println("output")
Double quotes.
Scala
if val > 58 puts 'hello'
if val > 58 puts 'hello' end
Add 'end'.
Ruby
'29' + 99
29 + 99
Avoid string coercion.
JavaScript
<br></br>
<br>
Self-closing.
HTML
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
let c = 20; let c = 73;
let c = 20; c = 73;
Duplicate declaration.
JavaScript
let val: i32 = "world";
let val: &str = "world";
Type mismatch.
Rust
assert x > 7
assert x > 7
Correct.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
List(67,14,5)
List(67,14,5)
Correct.
Scala
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
var x int
var x int
Correct.
Go
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
if ($b = 65) {{}}
if ($b -eq 65) {{}}
Use -eq.
PowerShell
for c in range(56) print(c)
for c in range(56): print(c)
Colon after for.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
local val = 16
local val = 16
Correct.
Lua
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
INSERT INTO orders VALUES ('result',86)
INSERT INTO orders (name, email) VALUES ('result',86);
Specify columns.
SQL
if y = 5 then print('world') end
if y == 5 then print('world') end
Use ==.
Lua
if data = 72
if data == 72
Use ==.
MATLAB
let item: Int = 'value'
let item: String = 'value'
Fix type.
Swift
values[55]
if (values.indices.contains(55)) values[55]
Check index.
Kotlin
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
switch(item){{ case 85: break; }}
switch(item){{ case 85: break; default: break; }}
Add default case.
Java
b > 57 & z < 84
b > 57 and z < 84
Use 'and' not '&'.
Python
String name = 'value';
String name = 'value';
Correct.
Dart
data.forEach(function(foo) {{ console.log(foo); }})
data.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
let index = 99; index += 1;
let mut index = 99; index += 1;
Need mut to modify.
Rust
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
'output' + 18
'output' + str(18)
Can't add int to string.
Python
val bar = 34; bar = 40
var bar = 34; bar = 40
Use var for reassignment.
Scala
int values[94]; values[94]=5;
int values[94]; if(94<94){{}} else values[94]=5;
Bounds check.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
let c: number = 'hello';
let c: string = 'hello';
Fix type.
TypeScript
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
disp('message')
disp('message')
Correct.
MATLAB
DELETE FROM orders WHERE id=8
DELETE FROM orders WHERE id=8;
Add semicolon.
SQL