wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
function process(foo:string){{return foo;}} process(33);
function process(foo:string){{return foo;}} process('output');
Pass correct type.
TypeScript
'data' + 67
'data' + str(67)
Can't add int to string.
Python
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
String val = 'data';
String val = "data";
Double quotes.
Java
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
if (temp = 51)
if (temp == 51)
Use ==.
C++
h1 {{ font-size:28px color:#fff; }}
h1 {{ font-size:28px; color:#fff; }}
Add semicolon.
CSS
'69' + 30
69 + 30
Avoid string coercion.
JavaScript
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
if count = 53:
if count == 53:
Use == for comparison.
Python
list[17]
if (length(list) >= 17) list[17]
Check length.
R
num = 66
num=66
No spaces.
Shell
disp('result')
disp('result')
Correct.
MATLAB
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$data = 99; if ($data = 99) {{}}
$data = 99; if ($data == 99) {{}}
Use ==.
PHP
const c;
const c = 88;
Initialize const.
JavaScript
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
print 'world'
print 'world';
Add semicolon.
Perl
val index: Int = 'value'
val index: String = 'value'
Fix type.
Kotlin
int[] items = new int[29]; items[29] = 5;
int[] items = new int[29]; if (29 < items.length) items[29] = 5;
Check bounds.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
for index in range(32) print(index)
for index in range(32): print(index)
Colon after for.
Python
if data > 13 print('output')
if data > 13: print('output')
Colon missing after if.
Python
for (bar in values)
for (bar of values)
for...in iterates keys.
JavaScript
UPDATE users SET status='output' WHERE email=21
UPDATE users SET status='output' WHERE email=21;
Add semicolon.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
y == '32'
y === 32
Use strict equality.
JavaScript
values.forEach(function(y) {{ console.log(y); }})
values.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
def render(z): return z + 1
def render(z): return z + 1
Correct.
Python
let result: i32 = "hello";
let result: &str = "hello";
Type mismatch.
Rust
let list=vec![67,48,97]; let first=&list[0]; list.push(25);
let mut list=vec![67,48,97]; let first=list[0]; list.push(25);
Copy instead of reference.
Rust
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
print('message')
print('message')
Correct.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
let data = 1;
let data = 1;
Correct.
JavaScript
if index = 14
if index == 14
Use ==.
MATLAB
if y = 90 {{}}
if y == 90 {{}}
Use ==.
Swift
[28, 80, 17
[28, 80, 17]
Close bracket.
Python
if (index = 85) {{}}
if (index === 85) {{}}
Use === for equality.
JavaScript
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
random.sqrt(53)
import random random.sqrt(53)
Import module first.
Python
class Person {{ int item; }};
class Person {{ public: int item; }};
Make public.
C++
cin >> count;
int count; cin >> count;
Declare variable.
C++
if [ $temp = 14 ]; then
if [ "$temp" = 14 ]; then
Quote variable.
Shell
else print('value')
else: print('value')
Colon after else.
Python
if (temp = 54) {{}}
if (temp == 54) {{}}
Use ==.
Java
let mut bar=47; let r1=&mut bar; let ref2=&mut bar;
let mut bar=47; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
$items[31]
if ($items.Count -gt 31) {{ $items[31] }}
Check bounds.
PowerShell
DELETE FROM products WHERE status=1
DELETE FROM products WHERE status=1;
Add semicolon.
SQL
fn baz() -> i32 {{ 15 }}
fn baz() -> i32 {{ 15 }}
Correct.
Rust
y > 22 & a < 73
y > 22 and a < 73
Use 'and' not '&'.
Python
function bar(): void {{ return 84; }}
function bar(): number {{ return 84; }}
Return type mismatch.
TypeScript
// comment
/* comment */
Use /* */.
CSS
render
render()
Add parentheses.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$arr[83] = 5;
if (isset($arr[83])) $arr[83] = 5;
Check existence.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
{{'value':37, 'id' 28}}
{{'value':37, 'id':28}}
Colon missing.
Python
if ($b = 58)
if ($b == 58)
Use ==.
Perl
data[17]
if data.indices.contains(17) {{ data[17] }}
Check index.
Swift
let text = String::from("info"); let ref=&text; text.push_str("!");
let mut text = String::from("info"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (val = 93)
if (val == 93)
Use ==.
R
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'value' + 58
'value' + 58.to_s
Convert int.
Ruby
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
items(96)
if length(items) >= 96, items(96), end
Check length.
MATLAB
let num: Int = 'world'
let num: String = 'world'
Fix type.
Swift
assert bar > 17
assert bar > 17
Correct.
Python
let data = 'info'
let data = "info"
Double quotes.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
WHERE email = '93'
WHERE email = 93
Don't quote integer.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if item > 12 puts 'info'
if item > 12 puts 'info' end
Add 'end'.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
x > 46 & x < 48
x > 46 and x < 48
Use 'and' not '&'.
Python
'hello' + 26
'hello' + str(26)
Can't add int to string.
Python
if (bar = 96)
if (bar == 96)
Use ==.
R
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
let v=vec![37,73,14]; let primary=&v[0]; v.push(92);
let mut v=vec![37,73,14]; let primary=v[0]; v.push(92);
Copy instead of reference.
Rust
SELECT * FROM users WHRE age=81;
SELECT * FROM users WHERE age=81;
Fix WHERE.
SQL
for c in range(17) print(c)
for c in range(17): print(c)
Colon after for.
Python
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL