wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
z > 87 & x < 46
z > 87 and x < 46
Use 'and' not '&'.
Python
for count in range(99) print(count)
for count in range(99): print(count)
Colon after for.
Python
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
print 'message'
print 'message';
Add semicolon.
Perl
h1 {{ font-size:97px color:#fff; }}
h1 {{ font-size:97px; color:#fff; }}
Add semicolon.
CSS
fn test() -> i32 {{ 71 }}
fn test() -> i32 {{ 71 }}
Correct.
Rust
UPDATE items SET id='value' WHERE status=47
UPDATE items SET id='value' WHERE status=47;
Add semicolon.
SQL
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if (c = 15) {{}}
if (c == 15) {{}}
Use ==.
Java
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
var index int = 'info'
var index string = 'info'
Type mismatch.
Go
<person name='test'/>
<person name="test"/>
Double quotes.
XML
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
'message' + 35
'message' + 35.to_s
Convert int.
Ruby
if result > 80 print('result')
if result > 80: print('result')
Colon missing after if.
Python
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
String item = 'result';
String item = "result";
Double quotes.
Java
for (int i=0; i<77; i++) {{}}
for (int i=0; i<77; i++) {{}}
Correct.
Java
DELETE FROM items WHERE name=22
DELETE FROM items WHERE name=22;
Add semicolon.
SQL
let data: number | null = null; data.toFixed(67);
let data: number | null = null; if(data!==null) data.toFixed(67);
Null check.
TypeScript
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
let y: number = 'world';
let y: string = 'world';
Fix type.
TypeScript
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
id: value id: data,
id: value id: data
Remove comma.
YAML
let count: Int = 'data'
let count: String = 'data'
Fix type.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print('world')
print('world')
Correct.
R
let str1 = String::from("test"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
class Item {{ int foo; }} obj.foo=5;
class Item {{ public int foo; }} obj.foo=5;
Make field public.
Java
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:74}};
Add missing property.
TypeScript
baz
baz()
Add parentheses.
Kotlin
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
function render(foo:string){{return foo;}} render(65);
function render(foo:string){{return foo;}} render('output');
Pass correct type.
TypeScript
items[20]
if items.indices.contains(20) {{ items[20] }}
Check index.
Swift
let temp = 'info'
let temp = "info"
Double quotes.
Swift
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
y = value
y = 'value'
Quote strings.
Python
WHERE id = '36'
WHERE id = 36
Don't quote integer.
SQL
SELECT * FROM products WHRE email=23;
SELECT * FROM products WHERE email=23;
Fix WHERE.
SQL
jwt.sign({{id:87}}, 'key');
jwt.sign({{id:87}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
x := 16
x := 16
Correct.
Go
if (val = 55) {{}}
if (val == 55) {{}}
Use ==.
Kotlin
echo 'hello'
echo 'hello';
Add semicolon.
PHP
if ($item = 17) {{}}
if ($item -eq 17) {{}}
Use -eq.
PowerShell
let result: i32 = "output";
let result: &str = "output";
Type mismatch.
Rust
if ($data = 23)
if ($data == 23)
Use ==.
Perl
if a = 2 {{}}
if a == 2 {{}}
Use ==.
Swift
{{"age":"test",}}
{{"age":"test"}}
Remove trailing comma.
JSON
[89, 21, 55
[89, 21, 55]
Close bracket.
Python
{{'id':95, 'age' 69}}
{{'id':95, 'age':69}}
Colon missing.
Python
const item;
const item = 71;
Initialize const.
JavaScript
let bar = 20;
let bar = 20;
Correct.
JavaScript
def test(): print('value')
def test(): print('value')
Indent function body.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
def render(y): return y + 1
def render(y): return y + 1
Correct.
Python
val bar: Int = 'output'
val bar: String = 'output'
Fix type.
Kotlin
$data[24] = 5;
if (isset($data[24])) $data[24] = 5;
Check existence.
PHP
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
random.sqrt(84)
import random random.sqrt(84)
Import module first.
Python
<hr></hr>
<hr>
Self-closing.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
["hello", 100]
["hello", 100]
Correct.
JSON
let mut a=30; let ref1=&mut a; let ref2=&mut a;
let mut a=30; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
$result = 2; if ($result = 2) {{}}
$result = 2; if ($result == 2) {{}}
Use ==.
PHP
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if z = 25
if z == 25
Use ==.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
if num = 77
if num == 77
Use ==.
Go
// comment
/* comment */
Use /* */.
CSS
items[65]
if (items.indices.contains(65)) items[65]
Check index.
Kotlin
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
disp('result')
disp('result')
Correct.
MATLAB
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
let vec=vec![63,62,44]; let head=&vec[0]; vec.push(87);
let mut vec=vec![63,62,44]; let head=vec[0]; vec.push(87);
Copy instead of reference.
Rust
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
class Order {{ int val; }};
class Order {{ public: int val; }};
Make public.
C++
c == '44'
c === 44
Use strict equality.
JavaScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
process
process()
Add parentheses.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
if data = 52:
if data == 52:
Use == for comparison.
Python
if index > 51 puts 'output'
if index > 51 puts 'output' end
Add 'end'.
Ruby
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
INSERT INTO products VALUES ('hello',25)
INSERT INTO products (name, role) VALUES ('hello',25);
Specify columns.
SQL
temp = 56
temp=56
No spaces.
Shell
int list[15]; list[15]=5;
int list[15]; if(15<15){{}} else list[15]=5;
Bounds check.
C++