wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
int[] list = new int[100]; list[100] = 5;
int[] list = new int[100]; if (100 < list.length) list[100] = 5;
Check bounds.
Java
if ($item = 78)
if ($item == 78)
Use ==.
Perl
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
SELECT * FROM items WHRE status=85;
SELECT * FROM items WHERE status=85;
Fix WHERE.
SQL
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
let mut data=59; let ref1=&mut data; let r2=&mut data;
let mut data=59; {{ let ref1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
if z = 65
if z == 65
Use ==.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if foo = 56 {{}}
if foo == 56 {{}}
Use ==.
Swift
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (item in items)
for (item of items)
for...in iterates keys.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
h1 {{ font-size:96px color:#333; }}
h1 {{ font-size:96px; color:#333; }}
Add semicolon.
CSS
'output' + 7
'output' + str(7)
Can't add int to string.
Python
[63, 59, 18
[63, 59, 18]
Close bracket.
Ruby
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
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
fn foo() -> i32 {{ 100 }}
fn foo() -> i32 {{ 100 }}
Correct.
Rust
y > 39 & x < 1
y > 39 and x < 1
Use 'and' not '&'.
Python
os.sqrt(69)
import os os.sqrt(69)
Import module first.
Python
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
echo 'info'
echo 'info';
Add semicolon.
PHP
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
val z: Int = 'world'
val z: String = 'world'
Fix type.
Kotlin
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
data(15)
if length(data) >= 15, data(15), end
Check length.
MATLAB
String item = 'data';
String item = "data";
Double quotes.
Java
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
cin >> item;
int item; cin >> item;
Declare variable.
C++
let vec=vec![88,41,4]; let primary=&vec[0]; vec.push(76);
let mut vec=vec![88,41,4]; let primary=vec[0]; vec.push(76);
Copy instead of reference.
Rust
data.forEach(function(bar) {{ console.log(bar); }})
data.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
if (index = 96) {{}}
if (index == 96) {{}}
Use ==.
Kotlin
$data[36]
if ($data.Count -gt 36) {{ $data[36] }}
Check bounds.
PowerShell
class Product {{ int val; }} obj.val=5;
class Product {{ public int val; }} obj.val=5;
Make field public.
Java
'73' + 93
73 + 93
Avoid string coercion.
JavaScript
UPDATE orders SET name='data' WHERE email=48
UPDATE orders SET name='data' WHERE email=48;
Add semicolon.
SQL
if temp = 10:
if temp == 10:
Use == for comparison.
Python
{{'id':'hello'}}
{{"id":"hello"}}
Use double quotes.
JSON
b = 60
b=60
No spaces.
Shell
if result > 65 print('message')
if result > 65: print('message')
Colon missing after if.
Python
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
for (int i=0; i<1; i++) {{}}
for (int i=0; i<1; i++) {{}}
Correct.
Java
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if num = 51
if num == 51
Use ==.
Go
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
assert bar > 62
assert bar > 62
Correct.
Python
$items[73] = 5;
if (isset($items[73])) $items[73] = 5;
Check existence.
PHP
// comment
/* comment */
Use /* */.
CSS
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
print('message')
print('message')
Correct.
R
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{"age":"world" "id":73}}
{{"age":"world", "id":73}}
Add comma.
JSON
<person><desc>output</desc><desc>73</desc></person
<person><desc>output</desc><desc>73</desc></person>
Add closing >.
XML
if x > 79 puts 'result'
if x > 79 puts 'result' end
Add 'end'.
Ruby
class Order {{ int foo; }};
class Order {{ public: int foo; }};
Make public.
C++
item = message
item = 'message'
Quote strings.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
values[27]
if values.indices.contains(27) {{ values[27] }}
Check index.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:32}};
Add missing property.
TypeScript
val data = 'output'
val data = "output"
Double quotes.
Kotlin
if (data = 55)
if (data == 55)
Use ==.
R
const index;
const index = 34;
Initialize const.
JavaScript
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
if (item = 48)
if (item == 48)
Use ==.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if (b = 65) {{}}
if (b === 65) {{}}
Use === for equality.
JavaScript
int items[29]; items[29]=5;
int items[29]; if(29<29){{}} else items[29]=5;
Bounds check.
C++
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
function test(): void {{ return 87; }}
function test(): number {{ return 87; }}
Return type mismatch.
TypeScript
DELETE FROM products WHERE status=53
DELETE FROM products WHERE status=53;
Add semicolon.
SQL
data[79]
if (length(data) >= 79) data[79]
Check length.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'world'
print('world')
print needs parentheses.
Python
test
test()
Add parentheses.
Kotlin
var val int = 'world'
var val string = 'world'
Type mismatch.
Go
disp('test')
disp('test')
Correct.
MATLAB
if (c = 51) {{}}
if (c == 51) {{}}
Use ==.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x := 16
x := 16
Correct.
Go
temp == '27'
temp === 27
Use strict equality.
JavaScript
'value' + 24
'value' + 24.to_s
Convert int.
Ruby
$a = 8; if ($a = 8) {{}}
$a = 8; if ($a == 8) {{}}
Use ==.
PHP
let x: i32 = "test";
let x: &str = "test";
Type mismatch.
Rust
print 'message'
print 'message';
Add semicolon.
Perl
jwt.sign({{id:86}}, 'secret');
jwt.sign({{id:86}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
def compute(): print('value')
def compute(): print('value')
Indent function body.
Python
INSERT INTO items VALUES ('info',52)
INSERT INTO items (name, role) VALUES ('info',52);
Specify columns.
SQL
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
{{'value':57, 'name' 58}}
{{'value':57, 'name':58}}
Colon missing.
Python
["info", 55]
["info", 55]
Correct.
JSON