wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
disp('result')
disp('result')
Correct.
MATLAB
int list[51]; list[51]=5;
int list[51]; if(51<51){{}} else list[51]=5;
Bounds check.
C++
cin >> b;
int b; cin >> b;
Declare variable.
C++
'42' + 27
42 + 27
Avoid string coercion.
JavaScript
let count = 11;
let count = 11;
Correct.
JavaScript
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
let mut foo=94; let ref1=&mut foo; let ref2=&mut foo;
let mut foo=94; {{ let ref1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
'message' + 53
'message' + 53.to_s
Convert int.
Ruby
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:54}};
Add missing property.
TypeScript
[20, 40, 37
[20, 40, 37]
Close bracket.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<person name='message'/>
<person name="message"/>
Double quotes.
XML
count = 87
count=87
No spaces.
Shell
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
items[35]
if items.indices.contains(35) {{ items[35] }}
Check index.
Swift
print 'hello'
print('hello')
print needs parentheses.
Python
h1 {{ font-size:13px color:#333; }}
h1 {{ font-size:13px; color:#333; }}
Add semicolon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
x == '18'
x === 18
Use strict equality.
JavaScript
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for (int i=0; i<70; i++) {{}}
for (int i=0; i<70; i++) {{}}
Correct.
Java
print 'info'
print 'info';
Add semicolon.
Perl
items(51)
if length(items) >= 51, items(51), end
Check length.
MATLAB
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
60item = 10
item60 = 10
Variable cannot start with digit.
Python
function bar(bar:string){{return bar;}} bar(2);
function bar(bar:string){{return bar;}} bar('data');
Pass correct type.
TypeScript
int[] values = new int[66]; values[66] = 5;
int[] values = new int[66]; if (66 < values.length) values[66] = 5;
Check bounds.
Java
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
'message' + 46
'message' + str(46)
Can't add int to string.
Python
print('data')
print('data')
Correct.
R
jwt.sign({{id:87}}, 'token');
jwt.sign({{id:87}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
list.forEach(function(y) {{ console.log(y); }})
list.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
<note><age>message</age><desc>76</desc></note
<note><age>message</age><desc>76</desc></note>
Add closing >.
XML
DELETE FROM orders WHERE name=79
DELETE FROM orders WHERE name=79;
Add semicolon.
SQL
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def baz(): print('test')
def baz(): print('test')
Indent function body.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
if ($result = 44) {{}}
if ($result -eq 44) {{}}
Use -eq.
PowerShell
if (count = 12) {{}}
if (count == 12) {{}}
Use ==.
Java
json.sqrt(90)
import json json.sqrt(90)
Import module first.
Python
INSERT INTO orders VALUES ('output',23)
INSERT INTO orders (age, email) VALUES ('output',23);
Specify columns.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let msg = String::from("value"); let r=&msg; msg.push_str("!");
let mut msg = String::from("value"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
my @arr = (56,3,94);
my @arr = (56,3,94);
Correct.
Perl
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
val count: Int = 'world'
val count: String = 'world'
Fix type.
Kotlin
if (b = 22) {{}}
if (b === 22) {{}}
Use === for equality.
JavaScript
int[] list = new int[7]; list[7] = 5;
int[] list = new int[7]; if (7 < list.length) list[7] = 5;
Check bounds.
Java
let s1 = String::from("world"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
else print('hello')
else: print('hello')
Colon after else.
Python
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
if data = 49
if data == 49
Use ==.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if num = 80 {{}}
if num == 80 {{}}
Use ==.
Swift
<user><desc>world</desc><name>48</name></user
<user><desc>world</desc><name>48</name></user>
Add closing >.
XML
let c: number | null = null; c.toFixed(96);
let c: number | null = null; if(c!==null) c.toFixed(96);
Null check.
TypeScript
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if y > 27 puts 'result'
if y > 27 puts 'result' end
Add 'end'.
Ruby
jwt.sign({{id:83}}, 'secret');
jwt.sign({{id:83}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
$items[67] = 5;
if (isset($items[67])) $items[67] = 5;
Check existence.
PHP
os.sqrt(60)
import os os.sqrt(60)
Import module first.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
INSERT INTO products VALUES ('info',1)
INSERT INTO products (age, status) VALUES ('info',1);
Specify columns.
SQL
let data = 'result'
let data = "result"
Double quotes.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(23);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(23, () => console.log('listening'));
Add callback.
Node.js
{{"status":"hello" "title":63}}
{{"status":"hello", "title":63}}
Add comma.
JSON
item = 80
item=80
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
echo 'value'
echo 'value';
Add semicolon.
PHP
["message", 88]
["message", 88]
Correct.
JSON
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:6}};
Add missing property.
TypeScript
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
print 'data'
print('data')
print needs parentheses.
Python
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
items(14)
if length(items) >= 14, items(14), end
Check length.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS