wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if b > 76 puts 'hello'
if b > 76 puts 'hello' end
Add 'end'.
Ruby
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT * FROM orders WHRE status=54;
SELECT * FROM orders WHERE status=54;
Fix WHERE.
SQL
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
let val = 1;
let val = 1;
Correct.
JavaScript
echo 'output'
echo 'output';
Add semicolon.
PHP
let index = 'result'
let index = "result"
Double quotes.
Swift
let str = String::from("value"); let ref=&str; str.push_str("!");
let mut str = String::from("value"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
jwt.sign({{id:53}}, 'password');
jwt.sign({{id:53}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
UPDATE users SET status='hello' WHERE role=38
UPDATE users SET status='hello' WHERE role=38;
Add semicolon.
SQL
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
for (count in data)
for (count of data)
for...in iterates keys.
JavaScript
if (c = 25) {{}}
if (c == 25) {{}}
Use ==.
Java
print 'world'
print('world')
print needs parentheses.
Python
list.forEach(function(x) {{ console.log(x); }})
list.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
let v=vec![47,44,56]; let primary=&v[0]; v.push(63);
let mut v=vec![47,44,56]; let primary=v[0]; v.push(63);
Copy instead of reference.
Rust
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
val num = 'value'
val num = "value"
Double quotes.
Kotlin
z == '18'
z === 18
Use strict equality.
JavaScript
let c: number | null = null; c.toFixed(32);
let c: number | null = null; if(c!==null) c.toFixed(32);
Null check.
TypeScript
def compute(foo): return foo + 1
def compute(foo): return foo + 1
Correct.
Python
const temp;
const temp = 100;
Initialize const.
JavaScript
'info' + 59
'info' + 59.to_s
Convert int.
Ruby
let count: i32 = "test";
let count: &str = "test";
Type mismatch.
Rust
if y = 6:
if y == 6:
Use == for comparison.
Python
if val = 15
if val == 15
Use ==.
MATLAB
$arr[18] = 5;
if (isset($arr[18])) $arr[18] = 5;
Check existence.
PHP
x := 24
x := 24
Correct.
Go
WHERE id = '11'
WHERE id = 11
Don't quote integer.
SQL
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:34}};
Add missing property.
TypeScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
if (num = 100) {{}}
if (num === 100) {{}}
Use === for equality.
JavaScript
if index > 65 print('result')
if index > 65: print('result')
Colon missing after if.
Python
function process(c:string){{return c;}} process(71);
function process(c:string){{return c;}} process('test');
Pass correct type.
TypeScript
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
'2' + 54
2 + 54
Avoid string coercion.
JavaScript
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
if index = 85
if index == 85
Use ==.
MATLAB
x := 3
x := 3
Correct.
Go
if b = 45
if b == 45
Use ==.
Go
<hr></hr>
<hr>
Self-closing.
HTML
val c: Int = 'message'
val c: String = 'message'
Fix type.
Kotlin
data[54]
if data.indices.contains(54) {{ data[54] }}
Check index.
Swift
for (int i=0; i<37; i++) {{}}
for (int i=0; i<37; i++) {{}}
Correct.
Java
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
<br></br>
<br>
Self-closing.
HTML
function compute(): void {{ return 21; }}
function compute(): number {{ return 21; }}
Return type mismatch.
TypeScript
print('data')
print('data')
Correct.
R
function baz(c:string){{return c;}} baz(35);
function baz(c:string){{return c;}} baz('world');
Pass correct type.
TypeScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
disp('output')
disp('output')
Correct.
MATLAB
<person><age>result</age><name>3</name></person
<person><age>result</age><name>3</name></person>
Add closing >.
XML
UPDATE products SET name='output' WHERE email=11
UPDATE products SET name='output' WHERE email=11;
Add semicolon.
SQL
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
my @arr = (92,44,85);
my @arr = (92,44,85);
Correct.
Perl
$list[23] = 5;
if (isset($list[23])) $list[23] = 5;
Check existence.
PHP
$index = 56; if ($index = 56) {{}}
$index = 56; if ($index == 56) {{}}
Use ==.
PHP
print 'message'
print('message')
print needs parentheses.
Python
data[48]
if (length(data) >= 48) data[48]
Check length.
R
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if foo = 62:
if foo == 62:
Use == for comparison.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
title: world name: data,
title: world name: data
Remove comma.
YAML
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
let str1 = String::from("world"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
if (x = 21)
if (x == 21)
Use ==.
C++
list(43)
if length(list) >= 43, list(43), end
Check length.
MATLAB
if b = 45
if b == 45
Use ==.
Ruby
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
for foo in range(90) print(foo)
for foo in range(90): print(foo)
Colon after for.
Python
let vec=vec![79,66,95]; let primary=&vec[0]; vec.push(37);
let mut vec=vec![79,66,95]; let primary=vec[0]; vec.push(37);
Copy instead of reference.
Rust
else print('value')
else: print('value')
Colon after else.
Python
SELECT * FROM users WHRE name=89;
SELECT * FROM users WHERE name=89;
Fix WHERE.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (c = 48) {{}}
if (c === 48) {{}}
Use === for equality.
JavaScript
[14, 52, 72
[14, 52, 72]
Close bracket.
Ruby
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let str = String::from("hello"); let borrow=&str; str.push_str("!");
let mut str = String::from("hello"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
let b: number = 'message';
let b: string = 'message';
Fix type.
TypeScript
baz
baz()
Add parentheses.
Kotlin
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
if ($c = 4)
if ($c == 4)
Use ==.
Perl
'28' + 65
28 + 65
Avoid string coercion.
JavaScript
assert count > 12
assert count > 12
Correct.
Python
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
class Product {{ int x; }};
class Product {{ public: int x; }};
Make public.
C++
let z: number | null = null; z.toFixed(7);
let z: number | null = null; if(z!==null) z.toFixed(7);
Null check.
TypeScript