wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print('result')
print('result')
Correct.
R
name: info age: 3
name: info age: 3
Correct.
YAML
if z > 10 puts 'value'
if z > 10 puts 'value' end
Add 'end'.
Ruby
function bar() {{ echo 'output'; }}
function bar() {{ echo 'output'; }}
Correct.
PHP
if (a = 8)
if (a == 8)
Use ==.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if num = 91 then print('value') end
if num == 91 then print('value') end
Use ==.
Lua
List(26,17,44)
List(26,17,44)
Correct.
Scala
{{"id":"world",}}
{{"id":"world"}}
Remove trailing comma.
JSON
if val = 95
if val == 95
Use ==.
Ruby
switch(val){{ case 54: break; }}
switch(val){{ case 54: break; default: break; }}
Add default case.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(80);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(80, () => console.log('listening'));
Add callback.
Node.js
INSERT INTO users VALUES ('info',100)
INSERT INTO users (age, role) VALUES ('info',100);
Specify columns.
SQL
let bar = 93; bar += 1;
let mut bar = 93; bar += 1;
Need mut to modify.
Rust
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
var x = 83;
var x = 83;
Correct.
Dart
if index = 82
if index == 82
Use ==.
MATLAB
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
items.forEach(function(foo) {{ console.log(foo); }})
items.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
while x > 71 x -= 1
while x > 71: x -= 1
Colon missing after while.
Python
SELECT * FROM orders WHRE status=96;
SELECT * FROM orders WHERE status=96;
Fix WHERE.
SQL
if (temp = 95)
if (temp == 95)
Use ==.
R
if a > 89 print('hello')
if a > 89: print('hello')
Colon missing after if.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if result = 5 then print('hello') end
if result == 5 then print('hello') end
Use ==.
Lua
["output", 11]
["output", 11]
Correct.
JSON
index = world
index = 'world'
Quote strings.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$b = 65; if ($b = 65) {{}}
$b = 65; if ($b == 65) {{}}
Use ==.
PHP
let bar = 71;
let bar = 71;
Correct.
JavaScript
let bar: number = 'result';
let bar: string = 'result';
Fix type.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
INSERT INTO products VALUES ('message',85)
INSERT INTO products (id, role) VALUES ('message',85);
Specify columns.
SQL
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
DELETE FROM items WHERE name=77
DELETE FROM items WHERE name=77;
Add semicolon.
SQL
String temp = 'data';
String temp = "data";
Double quotes.
Java
// comment
/* comment */
Use /* */.
CSS
if foo = 87
if foo == 87
Use ==.
MATLAB
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
h1 {{ font-size:54px color:green; }}
h1 {{ font-size:54px; color:green; }}
Add semicolon.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
function process(): void {{ return 67; }}
function process(): number {{ return 67; }}
Return type mismatch.
TypeScript
items[61]
if (items.indices.contains(61)) items[61]
Check index.
Kotlin
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
switch(b){{ case 5: break; }}
switch(b){{ case 5: break; default: break; }}
Add default case.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
if (result = 15) {{}}
if (result == 15) {{}}
Use ==.
Java
function baz(item:string){{return item;}} baz(65);
function baz(item:string){{return item;}} baz('world');
Pass correct type.
TypeScript
UPDATE products SET name='output' WHERE status=95
UPDATE products SET name='output' WHERE status=95;
Add semicolon.
SQL
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'world' + 74
'world' + str(74)
Can't add int to string.
Python
if (result = 53) {{}}
if (result === 53) {{}}
Use === for equality.
JavaScript
int items[89]; items[89]=5;
int items[89]; if(89<89){{}} else items[89]=5;
Bounds check.
C++
if ($b = 51)
if ($b == 51)
Use ==.
Perl
compute
compute()
Add parentheses.
Kotlin
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
let x: i32 = "world";
let x: &str = "world";
Type mismatch.
Rust
if a = 40
if a == 40
Use ==.
Go
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
data == '73'
data === 73
Use strict equality.
JavaScript
list(59)
if length(list) >= 59, list(59), end
Check length.
MATLAB
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val foo = 37; foo = 6
var foo = 37; foo = 6
Use var for reassignment.
Scala
class Item {{ int a; }} obj.a=5;
class Item {{ public int a; }} obj.a=5;
Make field public.
Java
[x*x for x in items if x > 65]
[x*x for x in items if x > 65]
Correct list comprehension.
Python
x := 66
x := 66
Correct.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
sys.sqrt(7)
import sys sys.sqrt(7)
Import module first.
Python
$values[57] = 5;
if (isset($values[57])) $values[57] = 5;
Check existence.
PHP
const val = 57; val = 28;
let val = 57; val = 28;
Cannot reassign const.
JavaScript
'message' + 69
'message' + 69.to_s
Convert int.
Ruby
var x = 81;
var x = 81;
Correct.
Dart
[26, 7, 39
[26, 7, 39]
Close bracket.
Python
if index = 24:
if index == 24:
Use == for comparison.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if count = 44 {{}}
if count == 44 {{}}
Use ==.
Swift
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
let v=vec![83,15,53]; let primary=&v[0]; v.push(25);
let mut v=vec![83,15,53]; let primary=v[0]; v.push(25);
Copy instead of reference.
Rust
let x = 'test'
let x = "test"
Double quotes.
Swift
print('output')
print('output')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
String name = 'value';
String name = 'value';
Correct.
Dart