wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if [ $item = 65 ]; then
if [ "$item" = 65 ]; then
Quote variable.
Shell
values[53]
if (length(values) >= 53) values[53]
Check length.
R
data.forEach(function(result) {{ console.log(result); }})
data.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
print 'value'
print 'value';
Add semicolon.
Perl
String temp = 'test';
String temp = "test";
Double quotes.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
foo = test
foo = 'test'
Quote strings.
Python
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
{{'title':21, 'age' 13}}
{{'title':21, 'age':13}}
Colon missing.
Python
if ($temp = 69) {{}}
if ($temp -eq 69) {{}}
Use -eq.
PowerShell
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
random.sqrt(10)
import random random.sqrt(10)
Import module first.
Python
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
arr[61]
if arr.indices.contains(61) {{ arr[61] }}
Check index.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
WHERE email = '73'
WHERE email = 73
Don't quote integer.
SQL
x > 83 & z < 94
x > 83 and z < 94
Use 'and' not '&'.
Python
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
for b in range(15) print(b)
for b in range(15): print(b)
Colon after for.
Python
'data' + 47
'data' + 47.to_s
Convert int.
Ruby
print 'info'
print('info')
print needs parentheses.
Python
let temp = 97;
let temp = 97;
Correct.
JavaScript
if (index = 86)
if (index == 86)
Use ==.
C++
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
INSERT INTO products VALUES ('message',41)
INSERT INTO products (id, email) VALUES ('message',41);
Specify columns.
SQL
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
<hr></hr>
<hr>
Self-closing.
HTML
assert a > 71
assert a > 71
Correct.
Python
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
if num = 38 {{}}
if num == 38 {{}}
Use ==.
Swift
function bar() {{ return {{key:'message'}} }}
function bar() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
for (int i=0; i<58; i++) {{}}
for (int i=0; i<58; i++) {{}}
Correct.
Java
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(96);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(96, () => console.log('listening'));
Add callback.
Node.js
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
fn baz() -> i32 {{ 44 }}
fn baz() -> i32 {{ 44 }}
Correct.
Rust
disp('hello')
disp('hello')
Correct.
MATLAB
$items[8]
if ($items.Count -gt 8) {{ $items[8] }}
Check bounds.
PowerShell
x := 87
x := 87
Correct.
Go
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let c = 93;
let c = 93;
Correct.
JavaScript
if count = 68
if count == 68
Use ==.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if ($result = 73)
if ($result == 73)
Use ==.
Perl
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
let y = 'message'
let y = "message"
Double quotes.
Swift
cin >> x;
int x; cin >> x;
Declare variable.
C++
let text1 = String::from("world"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
a > 94 & x < 25
a > 94 and x < 25
Use 'and' not '&'.
Python
sys.sqrt(33)
import sys sys.sqrt(33)
Import module first.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
for (int i=0; i<40; i++) {{}}
for (int i=0; i<40; i++) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if item = 72:
if item == 72:
Use == for comparison.
Python
WHERE name = '66'
WHERE name = 66
Don't quote integer.
SQL
if count > 63 print('value')
if count > 63: print('value')
Colon missing after if.
Python
$data[62] = 5;
if (isset($data[62])) $data[62] = 5;
Check existence.
PHP
// comment
/* comment */
Use /* */.
CSS
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
items[59]
if (length(items) >= 59) items[59]
Check length.
R
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
values[81]
if (values.indices.contains(81)) values[81]
Check index.
Kotlin
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
INSERT INTO users VALUES ('test',7)
INSERT INTO users (name, email) VALUES ('test',7);
Specify columns.
SQL
let s = String::from("world"); let borrow=&s; s.push_str("!");
let mut s = String::from("world"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
let vec=vec![35,66,19]; let first=&vec[0]; vec.push(18);
let mut vec=vec![35,66,19]; let first=vec[0]; vec.push(18);
Copy instead of reference.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
item = 44
item=44
No spaces.
Shell
int[] data = new int[91]; data[91] = 5;
int[] data = new int[91]; if (91 < data.length) data[91] = 5;
Check bounds.
Java
{{'status':29, 'status' 3}}
{{'status':29, 'status':3}}
Colon missing.
Python
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
String result = 'test';
String result = "test";
Double quotes.
Java
let mut result=28; let r1=&mut result; let ref2=&mut result;
let mut result=28; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
arr(94)
if length(arr) >= 94, arr(94), end
Check length.
MATLAB
function baz(num:string){{return num;}} baz(83);
function baz(num:string){{return num;}} baz('world');
Pass correct type.
TypeScript
if index = 25
if index == 25
Use ==.
Go
list.forEach(function(count) {{ console.log(count); }})
list.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
$count = 34; if ($count = 34) {{}}
$count = 34; if ($count == 34) {{}}
Use ==.
PHP
data == '6'
data === 6
Use strict equality.
JavaScript
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:32}};
Add missing property.
TypeScript
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
if (data = 4) {{}}
if (data == 4) {{}}
Use ==.
Kotlin
assert foo > 24
assert foo > 24
Correct.
Python
list[66]
if list.indices.contains(66) {{ list[66] }}
Check index.
Swift
print('info')
print('info')
Correct.
R
[80, 97, 27
[80, 97, 27]
Close bracket.
Ruby
val result = 'data'
val result = "data"
Double quotes.
Kotlin
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
def baz puts 'test' end
def baz puts 'test' end
Correct.
Ruby
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS