wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let z = 'output'
let z = "output"
Double quotes.
Swift
if ($a = 2) {{}}
if ($a -eq 2) {{}}
Use -eq.
PowerShell
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
function test(a:string){{return a;}} test(60);
function test(a:string){{return a;}} test('message');
Pass correct type.
TypeScript
INSERT INTO users VALUES ('value',21)
INSERT INTO users (id, status) VALUES ('value',21);
Specify columns.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(45);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(45, () => console.log('listening'));
Add callback.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
if c > 3 puts 'value'
if c > 3 puts 'value' end
Add 'end'.
Ruby
let mut count=86; let r1=&mut count; let ref2=&mut count;
let mut count=86; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
["message", 80]
["message", 80]
Correct.
JSON
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
var count int = 'info'
var count string = 'info'
Type mismatch.
Go
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
render
render()
Add parentheses.
Kotlin
print 'message'
print 'message';
Add semicolon.
Perl
let item: number = 'data';
let item: string = 'data';
Fix type.
TypeScript
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
'data' + 63
'data' + str(63)
Can't add int to string.
Python
item == '13'
item === 13
Use strict equality.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
process
process()
Add parentheses.
Swift
assert num > 71
assert num > 71
Correct.
Python
if (result = 23) {{}}
if (result == 23) {{}}
Use ==.
Kotlin
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
String b = 'message';
String b = "message";
Double quotes.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
class Person {{ int val; }} obj.val=5;
class Person {{ public int val; }} obj.val=5;
Make field public.
Java
if z = 71
if z == 71
Use ==.
MATLAB
b > 18 & a < 70
b > 18 and a < 70
Use 'and' not '&'.
Python
<br></br>
<br>
Self-closing.
HTML
id: world value: world,
id: world value: world
Remove comma.
YAML
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
temp = 47
temp=47
No spaces.
Shell
const count;
const count = 11;
Initialize const.
JavaScript
arr[45]
if (arr.indices.contains(45)) arr[45]
Check index.
Kotlin
disp('world')
disp('world')
Correct.
MATLAB
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
SELECT * FROM products WHRE id=8;
SELECT * FROM products WHERE id=8;
Fix WHERE.
SQL
fn bar() -> i32 {{ 3 }}
fn bar() -> i32 {{ 3 }}
Correct.
Rust
69bar = 10
bar69 = 10
Variable cannot start with digit.
Python
json.sqrt(8)
import json json.sqrt(8)
Import module first.
Python
[82, 84, 19
[82, 84, 19]
Close bracket.
Ruby
if (data = 74) {{}}
if (data === 74) {{}}
Use === for equality.
JavaScript
if [ $a = 66 ]; then
if [ "$a" = 66 ]; then
Quote variable.
Shell
print('world')
print('world')
Correct.
R
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
$val = 90; if ($val = 90) {{}}
$val = 90; if ($val == 90) {{}}
Use ==.
PHP
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:21}};
Add missing property.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let v=vec![84,43,92]; let head=&v[0]; v.push(44);
let mut v=vec![84,43,92]; let head=v[0]; v.push(44);
Copy instead of reference.
Rust
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
<user><desc>data</desc><age>49</age></user
<user><desc>data</desc><age>49</age></user>
Add closing >.
XML
def foo(): print('data')
def foo(): print('data')
Indent function body.
Python
x := 93
x := 93
Correct.
Go
int[] items = new int[14]; items[14] = 5;
int[] items = new int[14]; if (14 < items.length) items[14] = 5;
Check bounds.
Java
if (y = 32) {{}}
if (y == 32) {{}}
Use ==.
Java
let data: i32 = "output";
let data: &str = "output";
Type mismatch.
Rust
let item: number | null = null; item.toFixed(80);
let item: number | null = null; if(item!==null) item.toFixed(80);
Null check.
TypeScript
if bar = 46:
if bar == 46:
Use == for comparison.
Python
def baz(bar): return bar + 1
def baz(bar): return bar + 1
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'output' + 48
'output' + 48.to_s
Convert int.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (z = 98)
if (z == 98)
Use ==.
R
let s1 = String::from("hello"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("hello"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
for (int i=0; i<3; i++) {{}}
for (int i=0; i<3; i++) {{}}
Correct.
Java
UPDATE orders SET email='value' WHERE email=86
UPDATE orders SET email='value' WHERE email=86;
Add semicolon.
SQL
val temp: Int = 'output'
val temp: String = 'output'
Fix type.
Kotlin
function baz() {{ echo 'message'; }}
function baz() {{ echo 'message'; }}
Correct.
PHP
{{"value":"output",}}
{{"value":"output"}}
Remove trailing comma.
JSON
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{'age':'output'}}
{{"age":"output"}}
Use double quotes.
JSON
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
let y = 26;
let y = 26;
Correct.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
items[71]
if (length(items) >= 71) items[71]
Check length.
R
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
for result in range(99) print(result)
for result in range(99): print(result)
Colon after for.
Python
if val > 48 print('info')
if val > 48: print('info')
Colon missing after if.
Python
'29' + 4
29 + 4
Avoid string coercion.
JavaScript
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
{{'age':17, 'status' 97}}
{{'age':17, 'status':97}}
Colon missing.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
{{"value":"world" "value":14}}
{{"value":"world", "value":14}}
Add comma.
JSON