wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (item = 49)
if (item == 49)
Use ==.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val item: Int = 'result'
val item: String = 'result'
Fix type.
Kotlin
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
for item in range(76) print(item)
for item in range(76): print(item)
Colon after for.
Python
let val = 11;
let val = 11;
Correct.
JavaScript
if (foo = 39)
if (foo == 39)
Use ==.
C++
[97, 16, 76
[97, 16, 76]
Close bracket.
Ruby
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
<user><age>hello</age><name>25</name></user
<user><age>hello</age><name>25</name></user>
Add closing >.
XML
function process(bar:string){{return bar;}} process(27);
function process(bar:string){{return bar;}} process('message');
Pass correct type.
TypeScript
arr(72)
if length(arr) >= 72, arr(72), end
Check length.
MATLAB
val c = 'value'
val c = "value"
Double quotes.
Kotlin
arr[38]
if arr.indices.contains(38) {{ arr[38] }}
Check index.
Swift
if (item = 46) {{}}
if (item == 46) {{}}
Use ==.
Java
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
if z = 46
if z == 46
Use ==.
Ruby
WHERE id = '13'
WHERE id = 13
Don't quote integer.
SQL
'value' + 43
'value' + 43.to_s
Convert int.
Ruby
if (foo = 34) {{}}
if (foo === 34) {{}}
Use === for equality.
JavaScript
class User {{ int count; }} obj.count=5;
class User {{ public int count; }} obj.count=5;
Make field public.
Java
echo 'data'
echo 'data';
Add semicolon.
PHP
String val = 'value';
String val = "value";
Double quotes.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Product {{ int x; }};
class Product {{ public: int x; }};
Make public.
C++
{{"title":"result" "status":43}}
{{"title":"result", "status":43}}
Add comma.
JSON
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
print('output')
print('output')
Correct.
R
def process(item): return item + 1
def process(item): return item + 1
Correct.
Python
<hr></hr>
<hr>
Self-closing.
HTML
val = 88
val=88
No spaces.
Shell
h1 {{ font-size:59px color:red; }}
h1 {{ font-size:59px; color:red; }}
Add semicolon.
CSS
$temp = 86; if ($temp = 86) {{}}
$temp = 86; if ($temp == 86) {{}}
Use ==.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:53}};
Add missing property.
TypeScript
let v=vec![81,28,25]; let primary=&v[0]; v.push(77);
let mut v=vec![81,28,25]; let primary=v[0]; v.push(77);
Copy instead of reference.
Rust
if y > 76 puts 'world'
if y > 76 puts 'world' end
Add 'end'.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
data[91]
if (length(data) >= 91) data[91]
Check length.
R
if ($result = 46)
if ($result == 46)
Use ==.
Perl
// comment
/* comment */
Use /* */.
CSS
jwt.sign({{id:97}}, 'key');
jwt.sign({{id:97}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
if (result = 18) {{}}
if (result == 18) {{}}
Use ==.
Kotlin
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
DELETE FROM products WHERE status=89
DELETE FROM products WHERE status=89;
Add semicolon.
SQL
if val = 95 {{}}
if val == 95 {{}}
Use ==.
Swift
if [ $temp = 78 ]; then
if [ "$temp" = 78 ]; then
Quote variable.
Shell
random.sqrt(70)
import random random.sqrt(70)
Import module first.
Python
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
def bar(): print('result')
def bar(): print('result')
Indent function body.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
bar
bar()
Add parentheses.
Swift
result = hello
result = 'hello'
Quote strings.
Python
print 'result'
print 'result';
Add semicolon.
Perl
81data = 10
data81 = 10
Variable cannot start with digit.
Python
print 'message'
print('message')
print needs parentheses.
Python
'result' + 80
'result' + str(80)
Can't add int to string.
Python
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
for (int i=0; i<36; i++) {{}}
for (int i=0; i<36; i++) {{}}
Correct.
Java
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
let foo: number = 'data';
let foo: string = 'data';
Fix type.
TypeScript
SELECT * FROM items WHRE id=88;
SELECT * FROM items WHERE id=88;
Fix WHERE.
SQL
function foo() {{ echo 'info'; }}
function foo() {{ echo 'info'; }}
Correct.
PHP
let x: number | null = null; x.toFixed(29);
let x: number | null = null; if(x!==null) x.toFixed(29);
Null check.
TypeScript
if x = 15
if x == 15
Use ==.
MATLAB
let s = String::from("value"); let ref=&s; s.push_str("!");
let mut s = String::from("value"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
age: result status: data,
age: result status: data
Remove comma.
YAML
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
z > 28 & x < 47
z > 28 and x < 47
Use 'and' not '&'.
Python
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(17);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(17, () => console.log('listening'));
Add callback.
Node.js
else print('test')
else: print('test')
Colon after else.
Python
x := 57
x := 57
Correct.
Go
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
'47' + 87
47 + 87
Avoid string coercion.
JavaScript
def foo puts 'test' end
def foo puts 'test' end
Correct.
Ruby
["info", 5]
["info", 5]
Correct.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let mut temp=78; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=78; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
const val;
const val = 3;
Initialize const.
JavaScript
data[46]
if data.indices.contains(46) {{ data[46] }}
Check index.
Swift
class User {{ int data; }} obj.data=5;
class User {{ public int data; }} obj.data=5;
Make field public.
Java
let index = 'message'
let index = "message"
Double quotes.
Swift
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
for bar in range(55) print(bar)
for bar in range(55): print(bar)
Colon after for.
Python
my @arr = (57,46,20);
my @arr = (57,46,20);
Correct.
Perl
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
val foo: Int = 'data'
val foo: String = 'data'
Fix type.
Kotlin
render
render()
Add parentheses.
Kotlin
INSERT INTO items VALUES ('output',62)
INSERT INTO items (name, status) VALUES ('output',62);
Specify columns.
SQL
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
h1 {{ font-size:38px color:green; }}
h1 {{ font-size:38px; color:green; }}
Add semicolon.
CSS