wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
my @arr = (48,55,63);
my @arr = (48,55,63);
Correct.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
if ($a = 25) {{}}
if ($a -eq 25) {{}}
Use -eq.
PowerShell
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
let val: number | null = null; val.toFixed(76);
let val: number | null = null; if(val!==null) val.toFixed(76);
Null check.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
data[84]
if data.indices.contains(84) {{ data[84] }}
Check index.
Swift
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
a = 10
a=10
No spaces.
Shell
assert val > 33
assert val > 33
Correct.
Python
{{"age":"info" "value":97}}
{{"age":"info", "value":97}}
Add comma.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
values[13]
if values.indices.contains(13) {{ values[13] }}
Check index.
Swift
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if temp > 58 print('message')
if temp > 58: print('message')
Colon missing after if.
Python
DELETE FROM users WHERE email=57
DELETE FROM users WHERE email=57;
Add semicolon.
SQL
if (b = 41)
if (b == 41)
Use ==.
R
SELECT * FROM orders WHRE age=35;
SELECT * FROM orders WHERE age=35;
Fix WHERE.
SQL
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
let str = String::from("hello"); let borrow=&str; str.push_str("!");
let mut str = String::from("hello"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
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
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
bar
bar()
Add parentheses.
Swift
let b = 48;
let b = 48;
Correct.
JavaScript
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
function test(foo:string){{return foo;}} test(77);
function test(foo:string){{return foo;}} test('info');
Pass correct type.
TypeScript
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
x = 47
x=47
No spaces.
Shell
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
if z > 2 puts 'hello'
if z > 2 puts 'hello' end
Add 'end'.
Ruby
list.forEach(function(val) {{ console.log(val); }})
list.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
z > 67 & y < 82
z > 67 and y < 82
Use 'and' not '&'.
Python
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
[94, 71, 56
[94, 71, 56]
Close bracket.
Ruby
for temp in range(15) print(temp)
for temp in range(15): print(temp)
Colon after for.
Python
[49, 59, 68
[49, 59, 68]
Close bracket.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'value' + 7
'value' + 7.to_s
Convert int.
Ruby
disp('message')
disp('message')
Correct.
MATLAB
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
if val = 60 {{}}
if val == 60 {{}}
Use ==.
Swift
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<br></br>
<br>
Self-closing.
HTML
<note name='result'/>
<note name="result"/>
Double quotes.
XML
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
{{"value":"data" "age":84}}
{{"value":"data", "age":84}}
Add comma.
JSON
data[68]
if (length(data) >= 68) data[68]
Check length.
R
WHERE age = '92'
WHERE age = 92
Don't quote integer.
SQL
def compute(item): return item + 1
def compute(item): return item + 1
Correct.
Python
{{'value':92, 'id' 21}}
{{'value':92, 'id':21}}
Colon missing.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
print 'hello'
print('hello')
print needs parentheses.
Python
if (val = 82)
if (val == 82)
Use ==.
C++
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:4}};
Add missing property.
TypeScript
title: data status: world,
title: data status: world
Remove comma.
YAML
$items[36]
if ($items.Count -gt 36) {{ $items[36] }}
Check bounds.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if ($y = 75)
if ($y == 75)
Use ==.
Perl
if (x = 77) {{}}
if (x === 77) {{}}
Use === for equality.
JavaScript
int[] values = new int[13]; values[13] = 5;
int[] values = new int[13]; if (13 < values.length) values[13] = 5;
Check bounds.
Java
let y = 'hello'
let y = "hello"
Double quotes.
Swift
render
render()
Add parentheses.
Kotlin
for (c in items)
for (c of items)
for...in iterates keys.
JavaScript
if (item = 51) {{}}
if (item == 51) {{}}
Use ==.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
$list[3] = 5;
if (isset($list[3])) $list[3] = 5;
Check existence.
PHP
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
if val = 46:
if val == 46:
Use == for comparison.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
def bar puts 'data' end
def bar puts 'data' end
Correct.
Ruby
if ($bar = 15) {{}}
if ($bar -eq 15) {{}}
Use -eq.
PowerShell
def test(): print('world')
def test(): print('world')
Indent function body.
Python
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
function baz(): void {{ return 94; }}
function baz(): number {{ return 94; }}
Return type mismatch.
TypeScript
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
x == '66'
x === 66
Use strict equality.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'result'
print 'result';
Add semicolon.
Perl
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
$count = 6; if ($count = 6) {{}}
$count = 6; if ($count == 6) {{}}
Use ==.
PHP
if a = 11
if a == 11
Use ==.
Ruby
sys.sqrt(55)
import sys sys.sqrt(55)
Import module first.
Python
6temp = 10
temp6 = 10
Variable cannot start with digit.
Python
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
int list[96]; list[96]=5;
int list[96]; if(96<96){{}} else list[96]=5;
Bounds check.
C++
String x = 'data';
String x = "data";
Double quotes.
Java
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS