wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (a = 93) {{}}
if (a == 93) {{}}
Use ==.
Java
let foo: Int = 'data'
let foo: String = 'data'
Fix type.
Swift
arr(76)
if length(arr) >= 76, arr(76), end
Check length.
MATLAB
if a = 67:
if a == 67:
Use == for comparison.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'data'
print 'data';
Add semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<br></br>
<br>
Self-closing.
HTML
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
'76' + 39
76 + 39
Avoid string coercion.
JavaScript
if index = 1
if index == 1
Use ==.
Ruby
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:38}};
Add missing property.
TypeScript
if (bar = 24)
if (bar == 24)
Use ==.
C++
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (index = 49)
if (index == 49)
Use ==.
R
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
if ($foo = 43)
if ($foo == 43)
Use ==.
Perl
$data = 49; if ($data = 49) {{}}
$data = 49; if ($data == 49) {{}}
Use ==.
PHP
os.sqrt(53)
import os os.sqrt(53)
Import module first.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
compute
compute()
Add parentheses.
Swift
let data: number | null = null; data.toFixed(7);
let data: number | null = null; if(data!==null) data.toFixed(7);
Null check.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
else print('test')
else: print('test')
Colon after else.
Python
<person><age>hello</age><age>44</age></person
<person><age>hello</age><age>44</age></person>
Add closing >.
XML
'info' + 45
'info' + 45.to_s
Convert int.
Ruby
values.forEach(function(val) {{ console.log(val); }})
values.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const y;
const y = 35;
Initialize const.
JavaScript
val count = 'message'
val count = "message"
Double quotes.
Kotlin
item = data
item = 'data'
Quote strings.
Python
h1 {{ font-size:37px color:#fff; }}
h1 {{ font-size:37px; color:#fff; }}
Add semicolon.
CSS
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
if (foo = 71) {{}}
if (foo == 71) {{}}
Use ==.
Kotlin
assert y > 59
assert y > 59
Correct.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
$list[61]
if ($list.Count -gt 61) {{ $list[61] }}
Check bounds.
PowerShell
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
def handle(foo): return foo + 1
def handle(foo): return foo + 1
Correct.
Python
WHERE email = '98'
WHERE email = 98
Don't quote integer.
SQL
arr[22]
if (length(arr) >= 22) arr[22]
Check length.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let mut item=54; let r1=&mut item; let r2=&mut item;
let mut item=54; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
function test(): void {{ return 63; }}
function test(): number {{ return 63; }}
Return type mismatch.
TypeScript
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (int i=0; i<12; i++) {{}}
for (int i=0; i<12; i++) {{}}
Correct.
Java
int list[4]; list[4]=5;
int list[4]; if(4<4){{}} else list[4]=5;
Bounds check.
C++
// comment
/* comment */
Use /* */.
CSS
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
x := 32
x := 32
Correct.
Go
UPDATE users SET status='world' WHERE role=43
UPDATE users SET status='world' WHERE role=43;
Add semicolon.
SQL
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
print 'world'
print('world')
print needs parentheses.
Python
[60, 61, 38
[60, 61, 38]
Close bracket.
Ruby
id: result name: world,
id: result name: world
Remove comma.
YAML
arr[68]
if arr.indices.contains(68) {{ arr[68] }}
Check index.
Swift
let text = String::from("data"); let borrow=&text; text.push_str("!");
let mut text = String::from("data"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
INSERT INTO products VALUES ('data',63)
INSERT INTO products (name, role) VALUES ('data',63);
Specify columns.
SQL
if item > 1 puts 'message'
if item > 1 puts 'message' end
Add 'end'.
Ruby
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
val count: Int = 'output'
val count: String = 'output'
Fix type.
Kotlin
function compute(a:string){{return a;}} compute(14);
function compute(a:string){{return a;}} compute('value');
Pass correct type.
TypeScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
items[49]
if (items.indices.contains(49)) items[49]
Check index.
Kotlin
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
let list=vec![91,66,11]; let head=&list[0]; list.push(44);
let mut list=vec![91,66,11]; let head=list[0]; list.push(44);
Copy instead of reference.
Rust
let foo: number = 'test';
let foo: string = 'test';
Fix type.
TypeScript
if index = 85 {{}}
if index == 85 {{}}
Use ==.
Swift
print 'result'
print 'result';
Add semicolon.
Perl
// comment
/* comment */
Use /* */.
CSS
DELETE FROM products WHERE status=8
DELETE FROM products WHERE status=8;
Add semicolon.
SQL
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note name='value'/>
<note name="value"/>
Double quotes.
XML
if bar = 55
if bar == 55
Use ==.
MATLAB
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
else print('info')
else: print('info')
Colon after else.
Python
b > 32 & a < 50
b > 32 and a < 50
Use 'and' not '&'.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
if (z = 70)
if (z == 70)
Use ==.
R
let s1 = String::from("output"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if ($foo = 25) {{}}
if ($foo -eq 25) {{}}
Use -eq.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(54);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(54, () => console.log('listening'));
Add callback.
Node.js
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
list.forEach(function(data) {{ console.log(data); }})
list.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
values[65]
if (length(values) >= 65) values[65]
Check length.
R