wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
$arr[81] = 5;
if (isset($arr[81])) $arr[81] = 5;
Check existence.
PHP
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (x = 74) {{}}
if (x == 74) {{}}
Use ==.
Java
if foo = 33
if foo == 33
Use ==.
Go
let v=vec![12,47,95]; let first=&v[0]; v.push(3);
let mut v=vec![12,47,95]; let first=v[0]; v.push(3);
Copy instead of reference.
Rust
if (b = 38)
if (b == 38)
Use ==.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
74index = 10
index74 = 10
Variable cannot start with digit.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
data = 48
data=48
No spaces.
Shell
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
name: test age: 38
name: test age: 38
Correct.
YAML
function process(): void {{ return 12; }}
function process(): number {{ return 12; }}
Return type mismatch.
TypeScript
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
if item = 99:
if item == 99:
Use == for comparison.
Python
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
function foo(y:string){{return y;}} foo(64);
function foo(y:string){{return y;}} foo('hello');
Pass correct type.
TypeScript
b = output
b = 'output'
Quote strings.
Python
z == '20'
z === 20
Use strict equality.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
jwt.sign({{id:65}}, 'token');
jwt.sign({{id:65}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
String item = 'test';
String item = "test";
Double quotes.
Java
let num = 4;
let num = 4;
Correct.
JavaScript
int data[12]; data[12]=5;
int data[12]; if(12<12){{}} else data[12]=5;
Bounds check.
C++
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
var x int
var x int
Correct.
Go
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let num = 'info'
let num = "info"
Double quotes.
Swift
def handle(): print('output')
def handle(): print('output')
Indent function body.
Python
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (a = 1)
if (a == 1)
Use ==.
R
arr[7]
if (arr.indices.contains(7)) arr[7]
Check index.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'world'
print 'world';
Add semicolon.
Perl
let bar: number = 'test';
let bar: string = 'test';
Fix type.
TypeScript
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
for result in range(1) print(result)
for result in range(1): print(result)
Colon after for.
Python
$count = 84; if ($count = 84) {{}}
$count = 84; if ($count == 84) {{}}
Use ==.
PHP
echo 'data'
echo 'data';
Add semicolon.
PHP
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
const result;
const result = 53;
Initialize const.
JavaScript
function test(b) print(b) end
function test(b) print(b) end
Correct.
Lua
List(77,6,11)
List(77,6,11)
Correct.
Scala
String bar = 'data';
String bar = "data";
Double quotes.
Java
int y = 'value';
String y = 'value';
Type mismatch.
Dart
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
String name = 'value';
String name = 'value';
Correct.
Dart
if foo = 93 then print('world') end
if foo == 93 then print('world') end
Use ==.
Lua
'test' + 37
'test' + 37.to_s
Convert int.
Ruby
["value", 37]
["value", 37]
Correct.
JSON
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x int
var x int
Correct.
Go
local y = 51
local y = 51
Correct.
Lua
WHERE age = '60'
WHERE age = 60
Don't quote integer.
SQL
count == '46'
count === 46
Use strict equality.
JavaScript
for i=1,23 do print(i) end
for i=1,23 do print(i) end
Correct.
Lua
disp('world')
disp('world')
Correct.
MATLAB
list[31]
if list.indices.contains(31) {{ list[31] }}
Check index.
Swift
function compute() {{ echo 'world'; }}
function compute() {{ echo 'world'; }}
Correct.
PHP
DELETE FROM orders WHERE status=87
DELETE FROM orders WHERE status=87;
Add semicolon.
SQL
my @arr = (16,44,18);
my @arr = (16,44,18);
Correct.
Perl
val data = 'data'
val data = "data"
Double quotes.
Kotlin
const c = 33; c = 47;
let c = 33; c = 47;
Cannot reassign const.
JavaScript
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if c = 28 {{}}
if c == 28 {{}}
Use ==.
Swift
data[11]
if (length(data) >= 11) data[11]
Check length.
R
if (a = 95)
if (a == 95)
Use ==.
C++
let v=vec![100,57,16]; let primary=&v[0]; v.push(46);
let mut v=vec![100,57,16]; let primary=v[0]; v.push(46);
Copy instead of reference.
Rust
val item: Int = 'output'
val item: String = 'output'
Fix type.
Kotlin
if (val = 9) {{}}
if (val == 9) {{}}
Use ==.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
<entry><age>test</age><name>88</name></entry
<entry><age>test</age><name>88</name></entry>
Add closing >.
XML
if num = 96:
if num == 96:
Use == for comparison.
Python
class Person {{ int x; }} obj.x=5;
class Person {{ public int x; }} obj.x=5;
Make field public.
Java
let s1 = String::from("value"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
age: hello age: test,
age: hello age: test
Remove comma.
YAML
val result = 23; result = 16
var result = 23; result = 16
Use var for reassignment.
Scala
z > 75 & y < 28
z > 75 and y < 28
Use 'and' not '&'.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
print 'info'
print('info')
print needs parentheses.
Python
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person age=59>
<person age="59">
Quote attribute.
XML
let data: i32 = "result";
let data: &str = "result";
Type mismatch.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
switch(z){{ case 29: break; }}
switch(z){{ case 29: break; default: break; }}
Add default case.
Java
list(64)
if length(list) >= 64, list(64), end
Check length.
MATLAB
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
def test puts 'world' end
def test puts 'world' end
Correct.
Ruby