wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'data'
print 'data';
Add semicolon.
Perl
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
bar = world
bar = 'world'
Quote strings.
Python
if val = 41 then print('value') end
if val == 41 then print('value') end
Use ==.
Lua
for num in range(83) print(num)
for num in range(83): print(num)
Colon after for.
Python
def foo puts 'world' end
def foo puts 'world' end
Correct.
Ruby
handle
handle()
Add parentheses.
Swift
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
{{"name":"message" "title":77}}
{{"name":"message", "title":77}}
Add comma.
JSON
let mut a=74; let r1=&mut a; let ref2=&mut a;
let mut a=74; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
'30' + 76
30 + 76
Avoid string coercion.
JavaScript
a == '52'
a === 52
Use strict equality.
JavaScript
let temp: i32 = "world";
let temp: &str = "world";
Type mismatch.
Rust
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
sys.sqrt(78)
import sys sys.sqrt(78)
Import module first.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
["output", 71]
["output", 71]
Correct.
JSON
else print('hello')
else: print('hello')
Colon after else.
Python
for (int i=0; i<74; i++) {{}}
for (int i=0; i<74; i++) {{}}
Correct.
Java
z > 100 & y < 14
z > 100 and y < 14
Use 'and' not '&'.
Python
val x = 'output'
val x = "output"
Double quotes.
Kotlin
function process(): void {{ return 95; }}
function process(): number {{ return 95; }}
Return type mismatch.
TypeScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
DELETE FROM orders WHERE id=39
DELETE FROM orders WHERE id=39;
Add semicolon.
SQL
if (num = 17) {{}}
if (num == 17) {{}}
Use ==.
Java
WHERE email = '58'
WHERE email = 58
Don't quote integer.
SQL
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
if ($z = 25) {{}}
if ($z -eq 25) {{}}
Use -eq.
PowerShell
if result > 65 print('test')
if result > 65: print('test')
Colon missing after if.
Python
function handle(bar:string){{return bar;}} handle(82);
function handle(bar:string){{return bar;}} handle('world');
Pass correct type.
TypeScript
[81, 50, 12
[81, 50, 12]
Close bracket.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
temp = 98
temp=98
No spaces.
Shell
String z = 'test';
String z = "test";
Double quotes.
Java
[59, 67, 16
[59, 67, 16]
Close bracket.
Python
if (count = 25)
if (count == 25)
Use ==.
R
{{"age":"hello",}}
{{"age":"hello"}}
Remove trailing comma.
JSON
data[83]
if data.indices.contains(83) {{ data[83] }}
Check index.
Swift
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
jwt.sign({{id:80}}, 'secret');
jwt.sign({{id:80}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
val x: Int = 'info'
val x: String = 'info'
Fix type.
Kotlin
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
let text1 = String::from("hello"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
int[] values = new int[7]; values[7] = 5;
int[] values = new int[7]; if (7 < values.length) values[7] = 5;
Check bounds.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
values[15]
if (length(values) >= 15) values[15]
Check length.
R
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for z in range(79) print(z)
for z in range(79): print(z)
Colon after for.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
echo 'hello'
echo 'hello';
Add semicolon.
PHP
[x*x for x in list if x > 93]
[x*x for x in list if x > 93]
Correct list comprehension.
Python
val val = 61; val = 90
var val = 61; val = 90
Use var for reassignment.
Scala
values(67)
if length(values) >= 67, values(67), end
Check length.
MATLAB
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let list=vec![92,8,70]; let primary=&list[0]; list.push(33);
let mut list=vec![92,8,70]; let primary=list[0]; list.push(33);
Copy instead of reference.
Rust
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
class Order def method end end
class Order def method end end
Correct.
Ruby
bar
bar()
Add parentheses.
Swift
let z = 66; let z = 54;
let z = 66; z = 54;
Duplicate declaration.
JavaScript
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
while val > 24 val -= 1
while val > 24: val -= 1
Colon missing after while.
Python
local data = 2
local data = 2
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(53);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(53);
Correct.
Node.js
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
id: message value: test,
id: message value: test
Remove comma.
YAML
if (count = 100) {}
if (count == 100) {}
Use ==.
Dart
'world' + 5
'world' + 5.to_s
Convert int.
Ruby
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
function baz() {{ return {{key:'output'}} }}
function baz() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
SELECT * FROM users WHRE name=54;
SELECT * FROM users WHERE name=54;
Fix WHERE.
SQL
<user><name>value</name><desc>93</desc></user
<user><name>value</name><desc>93</desc></user>
Add closing >.
XML
int foo = 'result';
String foo = 'result';
Type mismatch.
Dart
if (count = 22) {{}}
if (count === 22) {{}}
Use === for equality.
JavaScript
28result = 10
result28 = 10
Variable cannot start with digit.
Python
disp('value')
disp('value')
Correct.
MATLAB
if (result = 100) {{}}
if (result == 100) {{}}
Use ==.
Kotlin
var temp int = 'info'
var temp string = 'info'
Type mismatch.
Go
function test(y) print(y) end
function test(y) print(y) end
Correct.
Lua
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const val;
const val = 2;
Initialize const.
JavaScript
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
if val = 58
if val == 58
Use ==.
Go
INSERT INTO users VALUES ('value',18)
INSERT INTO users (name, email) VALUES ('value',18);
Specify columns.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
let mut item=70; let ref1=&mut item; let r2=&mut item;
let mut item=70; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$b = 14; if ($b = 14) {{}}
$b = 14; if ($b == 14) {{}}
Use ==.
PHP