wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (c = 37)
if (c == 37)
Use ==.
C++
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
["data", 87]
["data", 87]
Correct.
JSON
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
math.sqrt(30)
import math math.sqrt(30)
Import module first.
Python
my @arr = (52,63,95);
my @arr = (52,63,95);
Correct.
Perl
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[95, 12, 58
[95, 12, 58]
Close bracket.
Python
data = hello
data = 'hello'
Quote strings.
Python
{{'name':36, 'age' 41}}
{{'name':36, 'age':41}}
Colon missing.
Python
jwt.sign({{id:76}}, 'token');
jwt.sign({{id:76}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
def process(): print('value')
def process(): print('value')
Indent function body.
Python
if (a = 77)
if (a == 77)
Use ==.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
// comment
/* comment */
Use /* */.
CSS
$data[24] = 5;
if (isset($data[24])) $data[24] = 5;
Check existence.
PHP
if z > 76 print('result')
if z > 76: print('result')
Colon missing after if.
Python
const y;
const y = 89;
Initialize const.
JavaScript
<person><desc>output</desc><name>91</name></person
<person><desc>output</desc><name>91</name></person>
Add closing >.
XML
foo == '42'
foo === 42
Use strict equality.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print 'info'
print 'info';
Add semicolon.
Perl
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
<br></br>
<br>
Self-closing.
HTML
let v=vec![85,30,66]; let head=&v[0]; v.push(94);
let mut v=vec![85,30,66]; let head=v[0]; v.push(94);
Copy instead of reference.
Rust
DELETE FROM orders WHERE id=49
DELETE FROM orders WHERE id=49;
Add semicolon.
SQL
let z = 79;
let z = 79;
Correct.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
values[33]
if (length(values) >= 33) values[33]
Check length.
R
x := 45
x := 45
Correct.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function handle(x:string){{return x;}} handle(73);
function handle(x:string){{return x;}} handle('test');
Pass correct type.
TypeScript
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
'info' + 37
'info' + 37.to_s
Convert int.
Ruby
if val = 71
if val == 71
Use ==.
Go
UPDATE products SET email='world' WHERE email=5
UPDATE products SET email='world' WHERE email=5;
Add semicolon.
SQL
if a = 9 {{}}
if a == 9 {{}}
Use ==.
Swift
function bar(): void {{ return 46; }}
function bar(): number {{ return 46; }}
Return type mismatch.
TypeScript
val x = 'value'
val x = "value"
Double quotes.
Kotlin
if a > 1 puts 'message'
if a > 1 puts 'message' end
Add 'end'.
Ruby
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
let mut val=64; let ref1=&mut val; let r2=&mut val;
let mut val=64; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
if index = 16:
if index == 16:
Use == for comparison.
Python
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
String a = 'hello';
String a = "hello";
Double quotes.
Java
fn process() -> i32 {{ 16 }}
fn process() -> i32 {{ 16 }}
Correct.
Rust
function foo() {{ return {{key:'hello'}} }}
function foo() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
else print('output')
else: print('output')
Colon after else.
Python
if (result = 34) {{}}
if (result == 34) {{}}
Use ==.
Java
items(86)
if length(items) >= 86, items(86), end
Check length.
MATLAB
if ($bar = 100)
if ($bar == 100)
Use ==.
Perl
int[] items = new int[48]; items[48] = 5;
int[] items = new int[48]; if (48 < items.length) items[48] = 5;
Check bounds.
Java
let str1 = String::from("data"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
print('output')
print('output')
Correct.
R
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
let count: Int = 'data'
let count: String = 'data'
Fix type.
Swift
val temp: Int = 'world'
val temp: String = 'world'
Fix type.
Kotlin
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if foo = 83
if foo == 83
Use ==.
MATLAB
print 'test'
print('test')
print needs parentheses.
Python
43y = 10
y43 = 10
Variable cannot start with digit.
Python
echo 'result'
echo 'result';
Add semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
INSERT INTO orders VALUES ('value',89)
INSERT INTO orders (id, status) VALUES ('value',89);
Specify columns.
SQL
let a: number | null = null; a.toFixed(73);
let a: number | null = null; if(a!==null) a.toFixed(73);
Null check.
TypeScript
if [ $index = 54 ]; then
if [ "$index" = 54 ]; then
Quote variable.
Shell
disp('value')
disp('value')
Correct.
MATLAB
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:1}};
Add missing property.
TypeScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
'78' + 24
78 + 24
Avoid string coercion.
JavaScript
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
WHERE id = '64'
WHERE id = 64
Don't quote integer.
SQL
let c: number = 'hello';
let c: string = 'hello';
Fix type.
TypeScript
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
{{"age":"data" "value":78}}
{{"age":"data", "value":78}}
Add comma.
JSON
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
print 'message'
print('message')
print needs parentheses.
Python
[8, 43, 42
[8, 43, 42]
Close bracket.
Python
if (bar = 90) {{}}
if (bar === 90) {{}}
Use === for equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
let bar = 'world'
let bar = "world"
Double quotes.
Swift
["result", 8]
["result", 8]
Correct.
JSON
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
let text1 = String::from("info"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
x > 23 & y < 90
x > 23 and y < 90
Use 'and' not '&'.
Python
if [ $data = 61 ]; then
if [ "$data" = 61 ]; then
Quote variable.
Shell
title: value name: data,
title: value name: data
Remove comma.
YAML
'message' + 10
'message' + 10.to_s
Convert int.
Ruby
DELETE FROM users WHERE name=63
DELETE FROM users WHERE name=63;
Add semicolon.
SQL