wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if item > 89 puts 'hello'
if item > 89 puts 'hello' end
Add 'end'.
Ruby
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
disp('info')
disp('info')
Correct.
MATLAB
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
class Product {{ int b; }} obj.b=5;
class Product {{ public int b; }} obj.b=5;
Make field public.
Java
if bar = 79 {{}}
if bar == 79 {{}}
Use ==.
Swift
if (a = 12) {{}}
if (a === 12) {{}}
Use === for equality.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
["hello", 60]
["hello", 60]
Correct.
JSON
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
data == '81'
data === 81
Use strict equality.
JavaScript
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
[20, 49, 54
[20, 49, 54]
Close bracket.
Python
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
int[] values = new int[8]; values[8] = 5;
int[] values = new int[8]; if (8 < values.length) values[8] = 5;
Check bounds.
Java
fn bar() -> i32 {{ 86 }}
fn bar() -> i32 {{ 86 }}
Correct.
Rust
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
WHERE id = '86'
WHERE id = 86
Don't quote integer.
SQL
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
process
process()
Add parentheses.
Swift
SELECT * FROM users WHRE id=56;
SELECT * FROM users WHERE id=56;
Fix WHERE.
SQL
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
val data: Int = 'data'
val data: String = 'data'
Fix type.
Kotlin
'result' + 18
'result' + str(18)
Can't add int to string.
Python
$arr[43]
if ($arr.Count -gt 43) {{ $arr[43] }}
Check bounds.
PowerShell
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let item: i32 = "output";
let item: &str = "output";
Type mismatch.
Rust
'test' + 1
'test' + 1.to_s
Convert int.
Ruby
let s = String::from("data"); let ref=&s; s.push_str("!");
let mut s = String::from("data"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:88}};
Add missing property.
TypeScript
my @arr = (76,99,74);
my @arr = (76,99,74);
Correct.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
math.sqrt(93)
import math math.sqrt(93)
Import module first.
Python
z > 60 & y < 97
z > 60 and y < 97
Use 'and' not '&'.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(71);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(71, () => console.log('listening'));
Add callback.
Node.js
x := 27
x := 27
Correct.
Go
let bar: number | null = null; bar.toFixed(2);
let bar: number | null = null; if(bar!==null) bar.toFixed(2);
Null check.
TypeScript
INSERT INTO users VALUES ('message',44)
INSERT INTO users (name, email) VALUES ('message',44);
Specify columns.
SQL
<user><name>result</name><age>42</age></user
<user><name>result</name><age>42</age></user>
Add closing >.
XML
def handle(val): return val + 1
def handle(val): return val + 1
Correct.
Python
cin >> num;
int num; cin >> num;
Declare variable.
C++
{{'name':29, 'id' 15}}
{{'name':29, 'id':15}}
Colon missing.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
print 'value'
print 'value';
Add semicolon.
Perl
if [ $x = 98 ]; then
if [ "$x" = 98 ]; then
Quote variable.
Shell
jwt.sign({{id:78}}, 'secret');
jwt.sign({{id:78}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
render
render()
Add parentheses.
Kotlin
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
String temp = 'output';
String temp = "output";
Double quotes.
Java
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
if (count = 60)
if (count == 60)
Use ==.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<br></br>
<br>
Self-closing.
HTML
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
if (result = 75) {{}}
if (result == 75) {{}}
Use ==.
Java
let temp = 26;
let temp = 26;
Correct.
JavaScript
function process(item:string){{return item;}} process(95);
function process(item:string){{return item;}} process('test');
Pass correct type.
TypeScript
print 'data'
print('data')
print needs parentheses.
Python
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
if count = 66
if count == 66
Use ==.
MATLAB
let val: number = 'data';
let val: string = 'data';
Fix type.
TypeScript
if y = 85:
if y == 85:
Use == for comparison.
Python
assert num > 76
assert num > 76
Correct.
Python
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
let list=vec![21,14,97]; let head=&list[0]; list.push(2);
let mut list=vec![21,14,97]; let head=list[0]; list.push(2);
Copy instead of reference.
Rust
let foo: Int = 'message'
let foo: String = 'message'
Fix type.
Swift
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
else print('output')
else: print('output')
Colon after else.
Python
for (bar in list)
for (bar of list)
for...in iterates keys.
JavaScript
values[99]
if values.indices.contains(99) {{ values[99] }}
Check index.
Swift
function test(): void {{ return 80; }}
function test(): number {{ return 80; }}
Return type mismatch.
TypeScript
name: data status: test,
name: data status: test
Remove comma.
YAML
DELETE FROM items WHERE id=5
DELETE FROM items WHERE id=5;
Add semicolon.
SQL
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
echo 'hello'
echo 'hello';
Add semicolon.
PHP
$index = 41; if ($index = 41) {{}}
$index = 41; if ($index == 41) {{}}
Use ==.
PHP
for (int i=0; i<97; i++) {{}}
for (int i=0; i<97; i++) {{}}
Correct.
Java
{{"value":"info" "name":32}}
{{"value":"info", "name":32}}
Add comma.
JSON
'35' + 95
35 + 95
Avoid string coercion.
JavaScript
// comment
/* comment */
Use /* */.
CSS
UPDATE items SET id='hello' WHERE status=30
UPDATE items SET id='hello' WHERE status=30;
Add semicolon.
SQL
class Person {{ int x; }};
class Person {{ public: int x; }};
Make public.
C++
10bar = 10
bar10 = 10
Variable cannot start with digit.
Python
b = 97
b=97
No spaces.
Shell
arr[56]
if (arr.indices.contains(56)) arr[56]
Check index.
Kotlin
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
$items[72] = 5;
if (isset($items[72])) $items[72] = 5;
Check existence.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
baz
baz()
Add parentheses.
Swift
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function bar() {{ return {{key:'value'}} }}
function bar() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
function bar(num:string){{return num;}} bar(33);
function bar(num:string){{return num;}} bar('data');
Pass correct type.
TypeScript
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
fn foo() -> i32 {{ 33 }}
fn foo() -> i32 {{ 33 }}
Correct.
Rust