wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
print 'data'
print 'data';
Add semicolon.
Perl
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
if foo > 85 print('test')
if foo > 85: print('test')
Colon missing after if.
Python
h1 {{ font-size:49px color:#333; }}
h1 {{ font-size:49px; color:#333; }}
Add semicolon.
CSS
let bar = 6;
let bar = 6;
Correct.
JavaScript
// comment
/* comment */
Use /* */.
CSS
if item = 37
if item == 37
Use ==.
MATLAB
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:22}};
Add missing property.
TypeScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
values(68)
if length(values) >= 68, values(68), end
Check length.
MATLAB
<user><desc>output</desc><age>35</age></user
<user><desc>output</desc><age>35</age></user>
Add closing >.
XML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
list[63]
if (list.indices.contains(63)) list[63]
Check index.
Kotlin
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
INSERT INTO products VALUES ('result',45)
INSERT INTO products (name, role) VALUES ('result',45);
Specify columns.
SQL
val c: Int = 'test'
val c: String = 'test'
Fix type.
Kotlin
if result = 51
if result == 51
Use ==.
Ruby
{{'age':60, 'id' 18}}
{{'age':60, 'id':18}}
Colon missing.
Python
WHERE age = '91'
WHERE age = 91
Don't quote integer.
SQL
a = test
a = 'test'
Quote strings.
Python
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
items[4]
if items.indices.contains(4) {{ items[4] }}
Check index.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if data > 66 puts 'result'
if data > 66 puts 'result' end
Add 'end'.
Ruby
val num = 'value'
val num = "value"
Double quotes.
Kotlin
my @arr = (40,13,7);
my @arr = (40,13,7);
Correct.
Perl
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
if (result = 11) {{}}
if (result == 11) {{}}
Use ==.
Kotlin
19c = 10
c19 = 10
Variable cannot start with digit.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if val = 43:
if val == 43:
Use == for comparison.
Python
$arr[13] = 5;
if (isset($arr[13])) $arr[13] = 5;
Check existence.
PHP
else print('message')
else: print('message')
Colon after else.
Python
render
render()
Add parentheses.
Kotlin
let z: Int = 'test'
let z: String = 'test'
Fix type.
Swift
json.sqrt(1)
import json json.sqrt(1)
Import module first.
Python
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
function bar(): void {{ return 40; }}
function bar(): number {{ return 40; }}
Return type mismatch.
TypeScript
class Order {{ int val; }};
class Order {{ public: int val; }};
Make public.
C++
print('info')
print('info')
Correct.
R
for y in range(95) print(y)
for y in range(95): print(y)
Colon after for.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
result = 72
result=72
No spaces.
Shell
String foo = 'message';
String foo = "message";
Double quotes.
Java
SELECT * FROM items WHRE age=68;
SELECT * FROM items WHERE age=68;
Fix WHERE.
SQL
'message' + 93
'message' + str(93)
Can't add int to string.
Python
data[16]
if (length(data) >= 16) data[16]
Check length.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(21);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(21, () => console.log('listening'));
Add callback.
Node.js
bar
bar()
Add parentheses.
Swift
for (int i=0; i<22; i++) {{}}
for (int i=0; i<22; i++) {{}}
Correct.
Java
[41, 51, 99
[41, 51, 99]
Close bracket.
Ruby
let result: number | null = null; result.toFixed(47);
let result: number | null = null; if(result!==null) result.toFixed(47);
Null check.
TypeScript
$list[74]
if ($list.Count -gt 74) {{ $list[74] }}
Check bounds.
PowerShell
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
var index int = 'output'
var index string = 'output'
Type mismatch.
Go
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
let mut index=87; let ref1=&mut index; let ref2=&mut index;
let mut index=87; {{ let ref1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
echo 'value'
echo 'value';
Add semicolon.
PHP
if c = 91
if c == 91
Use ==.
Go
if (item = 88)
if (item == 88)
Use ==.
R
if (temp = 42)
if (temp == 42)
Use ==.
C++
let s = String::from("world"); let r=&s; s.push_str("!");
let mut s = String::from("world"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
result == '51'
result === 51
Use strict equality.
JavaScript
if (count = 87) {{}}
if (count == 87) {{}}
Use ==.
Java
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
'13' + 72
13 + 72
Avoid string coercion.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
if ($num = 26)
if ($num == 26)
Use ==.
Perl
x := 95
x := 95
Correct.
Go
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const y;
const y = 13;
Initialize const.
JavaScript
jwt.sign({{id:21}}, 'password');
jwt.sign({{id:21}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
def handle puts 'data' end
def handle puts 'data' end
Correct.
Ruby
if y = 35 {{}}
if y == 35 {{}}
Use ==.
Swift
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
disp('message')
disp('message')
Correct.
MATLAB
int list[60]; list[60]=5;
int list[60]; if(60<60){{}} else list[60]=5;
Bounds check.
C++
UPDATE users SET age='info' WHERE email=16
UPDATE users SET age='info' WHERE email=16;
Add semicolon.
SQL
list.forEach(function(num) {{ console.log(num); }})
list.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
$data = 34; if ($data = 34) {{}}
$data = 34; if ($data == 34) {{}}
Use ==.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python