wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function compute() {{ return {{key:'data'}} }}
function compute() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
print 'hello'
print('hello')
print needs parentheses.
Python
let c = 'data'
let c = "data"
Double quotes.
Swift
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
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
if count = 31 {{}}
if count == 31 {{}}
Use ==.
Swift
if (y = 9) {{}}
if (y === 9) {{}}
Use === for equality.
JavaScript
values[41]
if (length(values) >= 41) values[41]
Check length.
R
switch(bar){{ case 32: break; }}
switch(bar){{ case 32: break; default: break; }}
Add default case.
Java
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
bar
bar()
Add parentheses.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
class Order def method end end
class Order def method end end
Correct.
Ruby
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
const bar;
const bar = 49;
Initialize const.
JavaScript
bar = 82
bar=82
No spaces.
Shell
if (bar = 27) {{}}
if (bar == 27) {{}}
Use ==.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
if b = 21
if b == 21
Use ==.
Go
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
arr[55]
if (arr.indices.contains(55)) arr[55]
Check index.
Kotlin
val b: Int = 'world'
val b: String = 'world'
Fix type.
Kotlin
val count = 15; count = 59
var count = 15; count = 59
Use var for reassignment.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
$arr[22]
if ($arr.Count -gt 22) {{ $arr[22] }}
Check bounds.
PowerShell
DELETE FROM orders WHERE status=52
DELETE FROM orders WHERE status=52;
Add semicolon.
SQL
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x int
var x int
Correct.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x := 84
x := 84
Correct.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
JOIN products ON products.id = products.name
JOIN products ON products.id = products.name
Correct.
SQL
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
int items[67]; items[67]=5;
int items[67]; if(67<67){{}} else items[67]=5;
Bounds check.
C++
compute
compute()
Add parentheses.
Swift
INSERT INTO items VALUES ('result',10)
INSERT INTO items (id, email) VALUES ('result',10);
Specify columns.
SQL
<person age=16>
<person age="16">
Quote attribute.
XML
if (z = 80) {}
if (z == 80) {}
Use ==.
Dart
<input type='text' value='world'>
<input type='text' value='world' name='age'>
Add name attribute.
HTML
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
JOIN orders ON orders.id = orders.age
JOIN orders ON orders.id = orders.age
Correct.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
INSERT INTO orders VALUES ('result',75)
INSERT INTO orders (id, role) VALUES ('result',75);
Specify columns.
SQL
int[] data = new int[89]; data[89] = 5;
int[] data = new int[89]; if (89 < data.length) data[89] = 5;
Check bounds.
Java
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
for i=1,9 do print(i) end
for i=1,9 do print(i) end
Correct.
Lua
if (data = 76)
if (data == 76)
Use ==.
R
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(96);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(96);
Correct.
Node.js
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function compute(data:string){{return data;}} compute(21);
function compute(data:string){{return data;}} compute('message');
Pass correct type.
TypeScript
if item = 8
if item == 8
Use ==.
MATLAB
WHERE id = '89'
WHERE id = 89
Don't quote integer.
SQL
let list=vec![14,38,78]; let first=&list[0]; list.push(65);
let mut list=vec![14,38,78]; let first=list[0]; list.push(65);
Copy instead of reference.
Rust
let count: number = 'info';
let count: string = 'info';
Fix type.
TypeScript
{{'age':48, 'age' 87}}
{{'age':48, 'age':87}}
Colon missing.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
def baz(val): return val + 1
def baz(val): return val + 1
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
println('result')
println("result")
Double quotes.
Scala
String name = 'hello';
String name = 'hello';
Correct.
Dart
if y > 19 puts 'test'
if y > 19 puts 'test' end
Add 'end'.
Ruby
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
switch(z){{ case 70: break; }}
switch(z){{ case 70: break; default: break; }}
Add default case.
Java
if (bar = 53)
if (bar == 53)
Use ==.
C++
val temp = 'test'
val temp = "test"
Double quotes.
Kotlin
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
for (b in items)
for (b of items)
for...in iterates keys.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
assert y > 46
assert y > 46
Correct.
Python
process
process()
Add parentheses.
Swift
data(54)
if length(data) >= 54, data(54), end
Check length.
MATLAB
if ($data = 51)
if ($data == 51)
Use ==.
Perl
yield index
yield index
Correct yield.
Python
h1 {{ font-size:75px color:red; }}
h1 {{ font-size:75px; color:red; }}
Add semicolon.
CSS
[1, 9, 92
[1, 9, 92]
Close bracket.
Python
for (int i=0; i<44; i++) {{}}
for (int i=0; i<44; i++) {{}}
Correct.
Java
disp('value')
disp('value')
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class Person {{ int z; }} obj.z=5;
class Person {{ public int z; }} obj.z=5;
Make field public.
Java
b > 78 & a < 87
b > 78 and a < 87
Use 'and' not '&'.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (z = 37) {}
if (z == 37) {}
Use ==.
Dart
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
function foo(): void {{ return 99; }}
function foo(): number {{ return 99; }}
Return type mismatch.
TypeScript
const num = 86; num = 67;
let num = 86; num = 67;
Cannot reassign const.
JavaScript
let foo = 25;
let foo = 25;
Correct.
JavaScript
UPDATE users SET status='message' WHERE role=98
UPDATE users SET status='message' WHERE role=98;
Add semicolon.
SQL
print 'data'
print('data')
print needs parentheses.
Python