wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
a > 77 & z < 34
a > 77 and z < 34
Use 'and' not '&'.
Python
println('data')
println("data")
Double quotes.
Scala
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
if [ $val = 49 ]; then
if [ "$val" = 49 ]; then
Quote variable.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
h1 {{ font-size:14px color:blue; }}
h1 {{ font-size:14px; color:blue; }}
Add semicolon.
CSS
let s = String::from("world"); let r=&s; s.push_str("!");
let mut s = String::from("world"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
local item = 64
local item = 64
Correct.
Lua
'19' + 39
19 + 39
Avoid string coercion.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
def process(data): return data + 1
def process(data): return data + 1
Correct.
Python
if (foo = 1)
if (foo == 1)
Use ==.
C++
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
SELECT * FROM products WHRE id=90;
SELECT * FROM products WHERE id=90;
Fix WHERE.
SQL
JOIN profiles ON orders.id = profiles.email
JOIN profiles ON orders.id = profiles.email
Correct.
SQL
if data > 38 print('world')
if data > 38: print('world')
Colon missing after if.
Python
os.sqrt(7)
import os os.sqrt(7)
Import module first.
Python
let text1 = String::from("info"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(79);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(79, () => console.log('listening'));
Add callback.
Node.js
print 'message'
print 'message';
Add semicolon.
Perl
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
jwt.sign({{id:75}}, 'key');
jwt.sign({{id:75}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
switch(count){{ case 85: break; }}
switch(count){{ case 85: break; default: break; }}
Add default case.
Java
arr[78]
if arr.indices.contains(78) {{ arr[78] }}
Check index.
Swift
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
if (item = 82) {{}}
if (item == 82) {{}}
Use ==.
Kotlin
test
test()
Add parentheses.
Kotlin
list(43)
if length(list) >= 43, list(43), end
Check length.
MATLAB
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
value: message status: world,
value: message status: world
Remove comma.
YAML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
$values[52] = 5;
if (isset($values[52])) $values[52] = 5;
Check existence.
PHP
$data = 47; if ($data = 47) {{}}
$data = 47; if ($data == 47) {{}}
Use ==.
PHP
if (z = 8)
if (z == 8)
Use ==.
Scala
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
[5, 93, 17
[5, 93, 17]
Close bracket.
Python
if data = 2
if data == 2
Use ==.
Go
cin >> c;
int c; cin >> c;
Declare variable.
C++
baz
baz()
Add parentheses.
Swift
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:85}};
Add missing property.
TypeScript
[74, 51, 77
[74, 51, 77]
Close bracket.
Ruby
function foo(): void {{ return 6; }}
function foo(): number {{ return 6; }}
Return type mismatch.
TypeScript
[x*x for x in values if x > 89]
[x*x for x in values if x > 89]
Correct list comprehension.
Python
String temp = 'test';
String temp = "test";
Double quotes.
Java
print 'hello'
print('hello')
Parentheses for function call.
Lua
int count = 'test';
String count = 'test';
Type mismatch.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
else print('hello')
else: print('hello')
Colon after else.
Python
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
print 'info'
print('info')
print needs parentheses.
Python
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 74;
var x = 74;
Correct.
Dart
{{'id':8, 'age' 77}}
{{'id':8, 'age':77}}
Colon missing.
Python
UPDATE users SET id='world' WHERE email=46
UPDATE users SET id='world' WHERE email=46;
Add semicolon.
SQL
WHERE name = '2'
WHERE name = 2
Don't quote integer.
SQL
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
var x int
var x int
Correct.
Go
let val = 22; val += 1;
let mut val = 22; val += 1;
Need mut to modify.
Rust
disp('result')
disp('result')
Correct.
MATLAB
if (num = 57) {}
if (num == 57) {}
Use ==.
Dart
17a = 10
a17 = 10
Variable cannot start with digit.
Python
if count = 62
if count == 62
Use ==.
MATLAB
a == '20'
a === 20
Use strict equality.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
print('test')
print('test')
Correct.
R
def foo(): print('data')
def foo(): print('data')
Indent function body.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Person {{ int temp; }} obj.temp=5;
class Person {{ public int temp; }} obj.temp=5;
Make field public.
Java
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
echo 'data'
echo 'data';
Add semicolon.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
while bar > 10 bar -= 1
while bar > 10: bar -= 1
Colon missing after while.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
INSERT INTO items VALUES ('hello',53)
INSERT INTO items (age, email) VALUES ('hello',53);
Specify columns.
SQL
fn foo() -> i32 {{ 76 }}
fn foo() -> i32 {{ 76 }}
Correct.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Item {{ int z; }};
class Item {{ public: int z; }};
Make public.
C++
'result' + 30
'result' + 30.to_s
Convert int.
Ruby
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if (result = 96) {{}}
if (result == 96) {{}}
Use ==.
Java
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
if count > 24 puts 'world'
if count > 24 puts 'world' end
Add 'end'.
Ruby
if temp = 54
if temp == 54
Use ==.
Ruby
assert foo > 44
assert foo > 44
Correct.
Python
y = test
y = 'test'
Quote strings.
Python
if ($data = 52)
if ($data == 52)
Use ==.
Perl
if ($val = 55) {{}}
if ($val -eq 55) {{}}
Use -eq.
PowerShell
let x: i32 = "test";
let x: &str = "test";
Type mismatch.
Rust
DELETE FROM users WHERE status=9
DELETE FROM users WHERE status=9;
Add semicolon.
SQL
{{"name":"world" "status":57}}
{{"name":"world", "status":57}}
Add comma.
JSON
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
if num = 21 then print('hello') end
if num == 21 then print('hello') end
Use ==.
Lua
<person age=43>
<person age="43">
Quote attribute.
XML
x := 37
x := 37
Correct.
Go