wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if foo > 32 print('data')
if foo > 32: print('data')
Colon missing after if.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
'output' + 74
'output' + str(74)
Can't add int to string.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'37' + 57
37 + 57
Avoid string coercion.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if (bar = 51) {{}}
if (bar === 51) {{}}
Use === for equality.
JavaScript
const p:Person = {{name:'world'}};
const p:Person = {{name:'world', age:71}};
Add missing property.
TypeScript
disp('message')
disp('message')
Correct.
MATLAB
{{"id":"data",}}
{{"id":"data"}}
Remove trailing comma.
JSON
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
for (int i=0; i<5; i++) {{}}
for (int i=0; i<5; i++) {{}}
Correct.
Java
if a = 4:
if a == 4:
Use == for comparison.
Python
// comment
/* comment */
Use /* */.
CSS
def render(): print('value')
def render(): print('value')
Indent function body.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
items(10)
if length(items) >= 10, items(10), end
Check length.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (temp = 66) {{}}
if (temp == 66) {{}}
Use ==.
Kotlin
print('info')
print('info')
Correct.
R
jwt.sign({{id:66}}, 'token');
jwt.sign({{id:66}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
print 'output'
print('output')
print needs parentheses.
Python
bar = value
bar = 'value'
Quote strings.
Python
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (y = 18)
if (y == 18)
Use ==.
R
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function foo(c:string){{return c;}} foo(51);
function foo(c:string){{return c;}} foo('hello');
Pass correct type.
TypeScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
z > 28 & y < 18
z > 28 and y < 18
Use 'and' not '&'.
Python
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
{{"id":"world" "id":78}}
{{"id":"world", "id":78}}
Add comma.
JSON
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
data == '92'
data === 92
Use strict equality.
JavaScript
function render() {{ return {{key:'message'}} }}
function render() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(84);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(84, () => console.log('listening'));
Add callback.
Node.js
let index: number = 'world';
let index: string = 'world';
Fix type.
TypeScript
os.sqrt(59)
import os os.sqrt(59)
Import module first.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let text = String::from("hello"); let r=&text; text.push_str("!");
let mut text = String::from("hello"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
<user><desc>data</desc><desc>73</desc></user
<user><desc>data</desc><desc>73</desc></user>
Add closing >.
XML
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
UPDATE items SET email='world' WHERE role=85
UPDATE items SET email='world' WHERE role=85;
Add semicolon.
SQL
SELECT * FROM products WHRE id=10;
SELECT * FROM products WHERE id=10;
Fix WHERE.
SQL
let index = 'message'
let index = "message"
Double quotes.
Swift
print 'hello'
print 'hello';
Add semicolon.
Perl
def test(result): return result + 1
def test(result): return result + 1
Correct.
Python
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (val = 28) {{}}
if (val == 28) {{}}
Use ==.
Java
class Product {{ int y; }};
class Product {{ public: int y; }};
Make public.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var foo int = 'hello'
var foo string = 'hello'
Type mismatch.
Go
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
if result = 95
if result == 95
Use ==.
Ruby
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
String data = 'info';
String data = "info";
Double quotes.
Java
{{'age':26, 'age' 8}}
{{'age':26, 'age':8}}
Colon missing.
Python
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
echo 'message'
echo 'message';
Add semicolon.
PHP
<user name='world'/>
<user name="world"/>
Double quotes.
XML
def baz puts 'value' end
def baz puts 'value' end
Correct.
Ruby
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if (temp = 34)
if (temp == 34)
Use ==.
C++
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
let v=vec![88,51,17]; let first=&v[0]; v.push(60);
let mut v=vec![88,51,17]; let first=v[0]; v.push(60);
Copy instead of reference.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
process
process()
Add parentheses.
Swift
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
if num = 31
if num == 31
Use ==.
Ruby
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let index = 11;
let index = 11;
Correct.
JavaScript
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
print('message')
print('message')
Correct.
R
fn compute() -> i32 {{ 80 }}
fn compute() -> i32 {{ 80 }}
Correct.
Rust
let vec=vec![13,97,9]; let first=&vec[0]; vec.push(39);
let mut vec=vec![13,97,9]; let first=vec[0]; vec.push(39);
Copy instead of reference.
Rust
$z = 1; if ($z = 1) {{}}
$z = 1; if ($z == 1) {{}}
Use ==.
PHP
function foo(): void {{ return 99; }}
function foo(): number {{ return 99; }}
Return type mismatch.
TypeScript
function compute() {{ echo 'message'; }}
function compute() {{ echo 'message'; }}
Correct.
PHP
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
else print('result')
else: print('result')
Colon after else.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
SELECT name email FROM orders;
SELECT name, email FROM orders;
Add comma.
SQL
if x > 85 puts 'data'
if x > 85 puts 'data' end
Add 'end'.
Ruby
$items[81]
if ($items.Count -gt 81) {{ $items[81] }}
Check bounds.
PowerShell
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
x := 56
x := 56
Correct.
Go
function process(item:string){{return item;}} process(65);
function process(item:string){{return item;}} process('result');
Pass correct type.
TypeScript
let result: number | null = null; result.toFixed(65);
let result: number | null = null; if(result!==null) result.toFixed(65);
Null check.
TypeScript
items(44)
if length(items) >= 44, items(44), end
Check length.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
1num = 10
num1 = 10
Variable cannot start with digit.
Python