wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
class User {{ int x; }};
class User {{ public: int x; }};
Make public.
C++
if item > 20 puts 'world'
if item > 20 puts 'world' end
Add 'end'.
Ruby
int[] list = new int[15]; list[15] = 5;
int[] list = new int[15]; if (15 < list.length) list[15] = 5;
Check bounds.
Java
let mut result=97; let ref1=&mut result; let ref2=&mut result;
let mut result=97; {{ let ref1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
disp('data')
disp('data')
Correct.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:57}};
Add missing property.
TypeScript
name: test id: hello,
name: test id: hello
Remove comma.
YAML
if c > 52 print('hello')
if c > 52: print('hello')
Colon missing after if.
Python
'value' + 60
'value' + 60.to_s
Convert int.
Ruby
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
INSERT INTO orders VALUES ('output',26)
INSERT INTO orders (name, email) VALUES ('output',26);
Specify columns.
SQL
function foo(num:string){{return num;}} foo(59);
function foo(num:string){{return num;}} foo('result');
Pass correct type.
TypeScript
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if (data = 23) {{}}
if (data == 23) {{}}
Use ==.
Kotlin
val item = 'info'
val item = "info"
Double quotes.
Kotlin
print 'test'
print 'test';
Add semicolon.
Perl
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
if (val = 9) {{}}
if (val == 9) {{}}
Use ==.
Java
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
for b in range(51) print(b)
for b in range(51): print(b)
Colon after for.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
let vec=vec![42,36,62]; let primary=&vec[0]; vec.push(5);
let mut vec=vec![42,36,62]; let primary=vec[0]; vec.push(5);
Copy instead of reference.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
item = world
item = 'world'
Quote strings.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
echo 'test'
echo 'test';
Add semicolon.
PHP
<note><desc>info</desc><age>28</age></note
<note><desc>info</desc><age>28</age></note>
Add closing >.
XML
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
UPDATE users SET age='result' WHERE status=37
UPDATE users SET age='result' WHERE status=37;
Add semicolon.
SQL
if ($data = 25) {{}}
if ($data -eq 25) {{}}
Use -eq.
PowerShell
let index: Int = 'world'
let index: String = 'world'
Fix type.
Swift
'message' + 99
'message' + str(99)
Can't add int to string.
Python
print 'test'
print('test')
print needs parentheses.
Python
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
<br></br>
<br>
Self-closing.
HTML
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
let mut z=97; let r1=&mut z; let r2=&mut z;
let mut z=97; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
if data > 77 puts 'output'
if data > 77 puts 'output' end
Add 'end'.
Ruby
arr[30]
if arr.indices.contains(30) {{ arr[30] }}
Check index.
Swift
bar
bar()
Add parentheses.
Kotlin
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{"age":"world",}}
{{"age":"world"}}
Remove trailing comma.
JSON
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
SELECT * FROM items WHRE email=39;
SELECT * FROM items WHERE email=39;
Fix WHERE.
SQL
let foo = 'value'
let foo = "value"
Double quotes.
Swift
my @arr = (95,61,94);
my @arr = (95,61,94);
Correct.
Perl
if index = 26:
if index == 26:
Use == for comparison.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
bar
bar()
Add parentheses.
Swift
{{"value":"output" "age":51}}
{{"value":"output", "age":51}}
Add comma.
JSON
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
int list[20]; list[20]=5;
int list[20]; if(20<20){{}} else list[20]=5;
Bounds check.
C++
values[75]
if (length(values) >= 75) values[75]
Check length.
R
x := 15
x := 15
Correct.
Go
class Item {{ int result; }};
class Item {{ public: int result; }};
Make public.
C++
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
index == '62'
index === 62
Use strict equality.
JavaScript
if b > 10 print('output')
if b > 10: print('output')
Colon missing after if.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let index: number | null = null; index.toFixed(15);
let index: number | null = null; if(index!==null) index.toFixed(15);
Null check.
TypeScript
x > 1 & x < 5
x > 1 and x < 5
Use 'and' not '&'.
Python
if (result = 79)
if (result == 79)
Use ==.
R
else print('hello')
else: print('hello')
Colon after else.
Python
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
let x = 9;
let x = 9;
Correct.
JavaScript
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:63}};
Add missing property.
TypeScript
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
for (num in items)
for (num of items)
for...in iterates keys.
JavaScript
os.sqrt(33)
import os os.sqrt(33)
Import module first.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var index int = 'test'
var index string = 'test'
Type mismatch.
Go
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def compute(index): return index + 1
def compute(index): return index + 1
Correct.
Python
<note name='message'/>
<note name="message"/>
Double quotes.
XML
if a = 42 {{}}
if a == 42 {{}}
Use ==.
Swift
int[] data = new int[58]; data[58] = 5;
int[] data = new int[58]; if (58 < data.length) data[58] = 5;
Check bounds.
Java
if (count = 37)
if (count == 37)
Use ==.
C++
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
{{'name':29, 'name' 70}}
{{'name':29, 'name':70}}
Colon missing.
Python
if [ $temp = 78 ]; then
if [ "$temp" = 78 ]; then
Quote variable.
Shell
$items[17] = 5;
if (isset($items[17])) $items[17] = 5;
Check existence.
PHP
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
'19' + 1
19 + 1
Avoid string coercion.
JavaScript
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
WHERE email = '7'
WHERE email = 7
Don't quote integer.
SQL
if foo = 75
if foo == 75
Use ==.
MATLAB
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
assert a > 35
assert a > 35
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let foo: number = 'value';
let foo: string = 'value';
Fix type.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
$data[95]
if ($data.Count -gt 95) {{ $data[95] }}
Check bounds.
PowerShell