wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if foo = 37
if foo == 37
Use ==.
Go
print 'info'
print('info')
print needs parentheses.
Python
for data in range(74) print(data)
for data in range(74): print(data)
Colon after for.
Python
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
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["output", 33]
["output", 33]
Correct.
JSON
class Order {{ int b; }} obj.b=5;
class Order {{ public int b; }} obj.b=5;
Make field public.
Java
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
for (int i=0; i<16; i++) {{}}
for (int i=0; i<16; i++) {{}}
Correct.
Java
let x = 52; let x = 45;
let x = 52; x = 45;
Duplicate declaration.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if b > 95 print('data')
if b > 95: print('data')
Colon missing after if.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<person age=40>
<person age="40">
Quote attribute.
XML
name: hello age: 51
name: hello age: 51
Correct.
YAML
33a = 10
a33 = 10
Variable cannot start with digit.
Python
<br></br>
<br>
Self-closing.
HTML
[x*x for x in values if x > 84]
[x*x for x in values if x > 84]
Correct list comprehension.
Python
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
if c > 22 puts 'info'
if c > 22 puts 'info' end
Add 'end'.
Ruby
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
List(99,1,19)
List(99,1,19)
Correct.
Scala
items[55]
if items.indices.contains(55) {{ items[55] }}
Check index.
Swift
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
test
test()
Add parentheses.
Swift
my @arr = (35,30,37);
my @arr = (35,30,37);
Correct.
Perl
if val = 17
if val == 17
Use ==.
Ruby
let list=vec![36,46,77]; let primary=&list[0]; list.push(98);
let mut list=vec![36,46,77]; let primary=list[0]; list.push(98);
Copy instead of reference.
Rust
[66, 30, 90
[66, 30, 90]
Close bracket.
Ruby
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<note name='output'/>
<note name="output"/>
Double quotes.
XML
if ($index = 10) {{}}
if ($index -eq 10) {{}}
Use -eq.
PowerShell
if ($temp = 63)
if ($temp == 63)
Use ==.
Perl
if (foo = 8) {{}}
if (foo == 8) {{}}
Use ==.
Kotlin
while item > 43 item -= 1
while item > 43: item -= 1
Colon missing after while.
Python
SELECT * FROM items WHRE id=56;
SELECT * FROM items WHERE id=56;
Fix WHERE.
SQL
println('output')
println("output")
Double quotes.
Scala
z > 2 & b < 9
z > 2 and b < 9
Use 'and' not '&'.
Python
let foo = 'info'
let foo = "info"
Double quotes.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$list[13]
if ($list.Count -gt 13) {{ $list[13] }}
Check bounds.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
class Item def method end end
class Item def method end end
Correct.
Ruby
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:47}};
Add missing property.
TypeScript
int b = 'data';
String b = 'data';
Type mismatch.
Dart
var x = 41;
var x = 41;
Correct.
Dart
if (data = 84)
if (data == 84)
Use ==.
C++
function baz() {{ return {{key:'world'}} }}
function baz() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
fn render() -> i32 {{ 69 }}
fn render() -> i32 {{ 69 }}
Correct.
Rust
var val int = 'test'
var val string = 'test'
Type mismatch.
Go
else print('hello')
else: print('hello')
Colon after else.
Python
list[7]
if (list.indices.contains(7)) list[7]
Check index.
Kotlin
def bar(y): return y + 1
def bar(y): return y + 1
Correct.
Python
while y > 37 y -= 1
while y > 37: y -= 1
Colon missing after while.
Python
let num = 'test'
let num = "test"
Double quotes.
Swift
let val: Int = 'output'
let val: String = 'output'
Fix type.
Swift
val z = 'result'
val z = "result"
Double quotes.
Kotlin
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
["data", 50]
["data", 50]
Correct.
JSON
WHERE email = '16'
WHERE email = 16
Don't quote integer.
SQL
fn foo() -> i32 {{ 1 }}
fn foo() -> i32 {{ 1 }}
Correct.
Rust
if result = 88
if result == 88
Use ==.
Ruby
println('info')
println("info")
Double quotes.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var x = 6;
var x = 6;
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let z = 48; let z = 77;
let z = 48; z = 77;
Duplicate declaration.
JavaScript
{{'age':32, 'value' 100}}
{{'age':32, 'value':100}}
Colon missing.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
arr[21]
if (length(arr) >= 21) arr[21]
Check length.
R
list(24)
if length(list) >= 24, list(24), end
Check length.
MATLAB
if (temp = 67) {{}}
if (temp === 67) {{}}
Use === for equality.
JavaScript
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
math.sqrt(74)
import math math.sqrt(74)
Import module first.
Python
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
var x int
var x int
Correct.
Go
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
def foo(): print('result')
def foo(): print('result')
Indent function body.
Python
def foo puts 'result' end
def foo puts 'result' end
Correct.
Ruby
if a = 28
if a == 28
Use ==.
MATLAB
for i=1,96 do print(i) end
for i=1,96 do print(i) end
Correct.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (x = 26) {{}}
if (x == 26) {{}}
Use ==.
Kotlin
my @arr = (25,64,78);
my @arr = (25,64,78);
Correct.
Perl
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
x := 99
x := 99
Correct.
Go