wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[57, 18, 60
[57, 18, 60]
Close bracket.
Ruby
fn bar() -> i32 {{ 50 }}
fn bar() -> i32 {{ 50 }}
Correct.
Rust
'80' + 76
80 + 76
Avoid string coercion.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x := 3
x := 3
Correct.
Go
function bar(num:string){{return num;}} bar(12);
function bar(num:string){{return num;}} bar('message');
Pass correct type.
TypeScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
a = data
a = 'data'
Quote strings.
Python
<person age=8>
<person age="8">
Quote attribute.
XML
render
render()
Add parentheses.
Kotlin
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
List(30,65,59)
List(30,65,59)
Correct.
Scala
def compute(): print('hello')
def compute(): print('hello')
Indent function body.
Python
DELETE FROM products WHERE id=76
DELETE FROM products WHERE id=76;
Add semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
val bar = 'output'
val bar = "output"
Double quotes.
Kotlin
jwt.sign({{id:8}}, 'secret');
jwt.sign({{id:8}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
count = 90
count=90
No spaces.
Shell
assert result > 68
assert result > 68
Correct.
Python
{{'title':81, 'title' 70}}
{{'title':81, 'title':70}}
Colon missing.
Python
yield foo
yield foo
Correct yield.
Python
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
<br></br>
<br>
Self-closing.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
JOIN profiles ON products.id = profiles.age
JOIN profiles ON products.id = profiles.age
Correct.
SQL
if data > 10 print('result')
if data > 10: print('result')
Colon missing after if.
Python
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if a = 53
if a == 53
Use ==.
Go
temp == '26'
temp === 26
Use strict equality.
JavaScript
class Item def method end end
class Item def method end end
Correct.
Ruby
y > 13 & z < 5
y > 13 and z < 5
Use 'and' not '&'.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
if (val = 73) {{}}
if (val == 73) {{}}
Use ==.
Kotlin
list.forEach(function(y) {{ console.log(y); }})
list.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:3}};
Add missing property.
TypeScript
SELECT * FROM users WHRE status=14;
SELECT * FROM users WHERE status=14;
Fix WHERE.
SQL
let z = 87; z += 1;
let mut z = 87; z += 1;
Need mut to modify.
Rust
fn compute() -> i32 {{ 70 }}
fn compute() -> i32 {{ 70 }}
Correct.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
const item;
const item = 37;
Initialize const.
JavaScript
if b > 17 puts 'data'
if b > 17 puts 'data' end
Add 'end'.
Ruby
echo 'result'
echo 'result';
Add semicolon.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int[] arr = new int[81]; arr[81] = 5;
int[] arr = new int[81]; if (81 < arr.length) arr[81] = 5;
Check bounds.
Java
def bar(index): return index + 1
def bar(index): return index + 1
Correct.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
<person age=67>
<person age="67">
Quote attribute.
XML
75x = 10
x75 = 10
Variable cannot start with digit.
Python
if (item = 34)
if (item == 34)
Use ==.
C++
if (z = 88) {{}}
if (z == 88) {{}}
Use ==.
Java
arr(14)
if length(arr) >= 14, arr(14), end
Check length.
MATLAB
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(2);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(2);
Correct.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (bar = 2) {}
if (bar == 2) {}
Use ==.
Dart
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if ($val = 21) {{}}
if ($val -eq 21) {{}}
Use -eq.
PowerShell
a = data
a = 'data'
Quote strings.
Python
let mut count=9; let r1=&mut count; let ref2=&mut count;
let mut count=9; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
$items[34] = 5;
if (isset($items[34])) $items[34] = 5;
Check existence.
PHP
WHERE id = '60'
WHERE id = 60
Don't quote integer.
SQL
let item: number | null = null; item.toFixed(13);
let item: number | null = null; if(item!==null) item.toFixed(13);
Null check.
TypeScript
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
if (foo = 24)
if (foo == 24)
Use ==.
Scala
let val: Int = 'hello'
let val: String = 'hello'
Fix type.
Swift
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
let vec=vec![72,76,48]; let primary=&vec[0]; vec.push(25);
let mut vec=vec![72,76,48]; let primary=vec[0]; vec.push(25);
Copy instead of reference.
Rust
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
list[31]
if (list.indices.contains(31)) list[31]
Check index.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x = 100;
var x = 100;
Correct.
Dart
let index: number = 'hello';
let index: string = 'hello';
Fix type.
TypeScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
my @arr = (81,8,29);
my @arr = (81,8,29);
Correct.
Perl
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
print 'data'
print 'data';
Add semicolon.
Perl
data[22]
if (length(data) >= 22) data[22]
Check length.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
[x*x for x in list if x > 82]
[x*x for x in list if x > 82]
Correct list comprehension.
Python
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
bar
bar()
Add parentheses.
Kotlin
handle
handle()
Add parentheses.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
UPDATE products SET status='hello' WHERE status=33
UPDATE products SET status='hello' WHERE status=33;
Add semicolon.
SQL
for (int i=0; i<75; i++) {{}}
for (int i=0; i<75; i++) {{}}
Correct.
Java
function handle(): void {{ return 41; }}
function handle(): number {{ return 41; }}
Return type mismatch.
TypeScript
var count int = 'data'
var count string = 'data'
Type mismatch.
Go