wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
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
'output' + 58
'output' + str(58)
Can't add int to string.
Python
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
fn process() -> i32 {{ 86 }}
fn process() -> i32 {{ 86 }}
Correct.
Rust
items(20)
if length(items) >= 20, items(20), end
Check length.
MATLAB
class Order {{ int c; }} obj.c=5;
class Order {{ public int c; }} obj.c=5;
Make field public.
Java
arr[78]
if arr.indices.contains(78) {{ arr[78] }}
Check index.
Swift
$values[3] = 5;
if (isset($values[3])) $values[3] = 5;
Check existence.
PHP
class Order {{ int c; }};
class Order {{ public: int c; }};
Make public.
C++
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
if [ $x = 80 ]; then
if [ "$x" = 80 ]; then
Quote variable.
Shell
if ($count = 21) {{}}
if ($count -eq 21) {{}}
Use -eq.
PowerShell
DELETE FROM items WHERE age=96
DELETE FROM items WHERE age=96;
Add semicolon.
SQL
def process puts 'test' end
def process puts 'test' end
Correct.
Ruby
if (result = 74)
if (result == 74)
Use ==.
C++
echo 'info'
echo 'info';
Add semicolon.
PHP
// comment
/* comment */
Use /* */.
CSS
int arr[84]; arr[84]=5;
int arr[84]; if(84<84){{}} else arr[84]=5;
Bounds check.
C++
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
if ($temp = 42)
if ($temp == 42)
Use ==.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if y = 69 {{}}
if y == 69 {{}}
Use ==.
Swift
count == '43'
count === 43
Use strict equality.
JavaScript
data[78]
if data.indices.contains(78) {{ data[78] }}
Check index.
Swift
int[] items = new int[31]; items[31] = 5;
int[] items = new int[31]; if (31 < items.length) items[31] = 5;
Check bounds.
Java
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$arr[6] = 5;
if (isset($arr[6])) $arr[6] = 5;
Check existence.
PHP
function process(c:string){{return c;}} process(64);
function process(c:string){{return c;}} process('world');
Pass correct type.
TypeScript
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
[100, 29, 99
[100, 29, 99]
Close bracket.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
list.forEach(function(item) {{ console.log(item); }})
list.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
items(28)
if length(items) >= 28, items(28), end
Check length.
MATLAB
count = 42
count=42
No spaces.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
title: data id: world,
title: data id: world
Remove comma.
YAML
if count = 32
if count == 32
Use ==.
MATLAB
'value' + 28
'value' + str(28)
Can't add int to string.
Python
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
h1 {{ font-size:6px color:#333; }}
h1 {{ font-size:6px; color:#333; }}
Add semicolon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
// comment
/* comment */
Use /* */.
CSS
UPDATE users SET email='output' WHERE email=53
UPDATE users SET email='output' WHERE email=53;
Add semicolon.
SQL
if a = 48:
if a == 48:
Use == for comparison.
Python
$data[78]
if ($data.Count -gt 78) {{ $data[78] }}
Check bounds.
PowerShell
[46, 47, 86
[46, 47, 86]
Close bracket.
Ruby
y > 52 & z < 30
y > 52 and z < 30
Use 'and' not '&'.
Python
val foo: Int = 'hello'
val foo: String = 'hello'
Fix type.
Kotlin
<user name='value'/>
<user name="value"/>
Double quotes.
XML
SELECT * FROM products WHRE name=31;
SELECT * FROM products WHERE name=31;
Fix WHERE.
SQL
let foo: number | null = null; foo.toFixed(88);
let foo: number | null = null; if(foo!==null) foo.toFixed(88);
Null check.
TypeScript
if (x = 36) {{}}
if (x === 36) {{}}
Use === for equality.
JavaScript
let msg = String::from("message"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("message"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
x := 48
x := 48
Correct.
Go
temp = hello
temp = 'hello'
Quote strings.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
os.sqrt(15)
import os os.sqrt(15)
Import module first.
Python
let x: number = 'data';
let x: string = 'data';
Fix type.
TypeScript
if (temp = 65) {{}}
if (temp == 65) {{}}
Use ==.
Kotlin
'info' + 6
'info' + 6.to_s
Convert int.
Ruby
if b = 9
if b == 9
Use ==.
Ruby
if [ $result = 75 ]; then
if [ "$result" = 75 ]; then
Quote variable.
Shell
if (foo = 19)
if (foo == 19)
Use ==.
R
{{"id":"value" "value":3}}
{{"id":"value", "value":3}}
Add comma.
JSON
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
items[8]
if (items.indices.contains(8)) items[8]
Check index.
Kotlin
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:15}};
Add missing property.
TypeScript
<person><name>message</name><age>90</age></person
<person><name>message</name><age>90</age></person>
Add closing >.
XML
INSERT INTO orders VALUES ('hello',14)
INSERT INTO orders (age, email) VALUES ('hello',14);
Specify columns.
SQL
fn baz() -> i32 {{ 81 }}
fn baz() -> i32 {{ 81 }}
Correct.
Rust
if bar > 76 print('value')
if bar > 76: print('value')
Colon missing after if.
Python
print 'output'
print('output')
print needs parentheses.
Python
print 'test'
print 'test';
Add semicolon.
Perl
print('data')
print('data')
Correct.
R
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
function test(): void {{ return 2; }}
function test(): number {{ return 2; }}
Return type mismatch.
TypeScript
function process() {{ return {{key:'world'}} }}
function process() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
def handle puts 'data' end
def handle puts 'data' end
Correct.
Ruby
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
disp('result')
disp('result')
Correct.
MATLAB
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
30item = 10
item30 = 10
Variable cannot start with digit.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
bar
bar()
Add parentheses.
Kotlin
var x int = 'data'
var x string = 'data'
Type mismatch.
Go