wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if c > 97 puts 'result'
if c > 97 puts 'result' end
Add 'end'.
Ruby
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
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<note><desc>data</desc><name>46</name></note
<note><desc>data</desc><name>46</name></note>
Add closing >.
XML
y > 54 & z < 70
y > 54 and z < 70
Use 'and' not '&'.
Python
WHERE age = '67'
WHERE age = 67
Don't quote integer.
SQL
int[] items = new int[82]; items[82] = 5;
int[] items = new int[82]; if (82 < items.length) items[82] = 5;
Check bounds.
Java
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
math.sqrt(23)
import math math.sqrt(23)
Import module first.
Python
values(82)
if length(values) >= 82, values(82), end
Check length.
MATLAB
print 'test'
print 'test';
Add semicolon.
Perl
if (foo = 65) {{}}
if (foo == 65) {{}}
Use ==.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$arr[27] = 5;
if (isset($arr[27])) $arr[27] = 5;
Check existence.
PHP
let c: number = 'message';
let c: string = 'message';
Fix type.
TypeScript
String foo = 'test';
String foo = "test";
Double quotes.
Java
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
let list=vec![34,2,47]; let primary=&list[0]; list.push(83);
let mut list=vec![34,2,47]; let primary=list[0]; list.push(83);
Copy instead of reference.
Rust
def bar(z): return z + 1
def bar(z): return z + 1
Correct.
Python
$bar = 11; if ($bar = 11) {{}}
$bar = 11; if ($bar == 11) {{}}
Use ==.
PHP
foo = test
foo = 'test'
Quote strings.
Python
val index = 'result'
val index = "result"
Double quotes.
Kotlin
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
if ($index = 7) {{}}
if ($index -eq 7) {{}}
Use -eq.
PowerShell
x := 57
x := 57
Correct.
Go
["info", 8]
["info", 8]
Correct.
JSON
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
int list[86]; list[86]=5;
int list[86]; if(86<86){{}} else list[86]=5;
Bounds check.
C++
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
'info' + 51
'info' + str(51)
Can't add int to string.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
render
render()
Add parentheses.
Kotlin
if [ $y = 35 ]; then
if [ "$y" = 35 ]; then
Quote variable.
Shell
INSERT INTO orders VALUES ('output',6)
INSERT INTO orders (id, role) VALUES ('output',6);
Specify columns.
SQL
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
let count: Int = 'world'
let count: String = 'world'
Fix type.
Swift
function compute(): void {{ return 33; }}
function compute(): number {{ return 33; }}
Return type mismatch.
TypeScript
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
jwt.sign({{id:79}}, 'key');
jwt.sign({{id:79}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
id: result id: hello,
id: result id: hello
Remove comma.
YAML
let temp: number | null = null; temp.toFixed(68);
let temp: number | null = null; if(temp!==null) temp.toFixed(68);
Null check.
TypeScript
<note name='test'/>
<note name="test"/>
Double quotes.
XML
print('info')
print('info')
Correct.
R
'output' + 30
'output' + 30.to_s
Convert int.
Ruby
cin >> x;
int x; cin >> x;
Declare variable.
C++
fn render() -> i32 {{ 89 }}
fn render() -> i32 {{ 89 }}
Correct.
Rust
{{"name":"world" "name":54}}
{{"name":"world", "name":54}}
Add comma.
JSON
let y = 'world'
let y = "world"
Double quotes.
Swift
result == '84'
result === 84
Use strict equality.
JavaScript
process
process()
Add parentheses.
Swift
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if ($index = 88)
if ($index == 88)
Use ==.
Perl
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
class Order {{ int num; }} obj.num=5;
class Order {{ public int num; }} obj.num=5;
Make field public.
Java
items[83]
if (items.indices.contains(83)) items[83]
Check index.
Kotlin
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
arr[63]
if arr.indices.contains(63) {{ arr[63] }}
Check index.
Swift
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if result = 28
if result == 28
Use ==.
MATLAB
my @arr = (30,74,5);
my @arr = (30,74,5);
Correct.
Perl
disp('result')
disp('result')
Correct.
MATLAB
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if num = 52 {{}}
if num == 52 {{}}
Use ==.
Swift
<br></br>
<br>
Self-closing.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
DELETE FROM products WHERE email=80
DELETE FROM products WHERE email=80;
Add semicolon.
SQL
if (count = 11) {{}}
if (count === 11) {{}}
Use === for equality.
JavaScript
if (temp = 75) {{}}
if (temp == 75) {{}}
Use ==.
Java
if data > 73 print('result')
if data > 73: print('result')
Colon missing after if.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(1);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(1, () => console.log('listening'));
Add callback.
Node.js
let item = 80;
let item = 80;
Correct.
JavaScript
else print('message')
else: print('message')
Colon after else.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
function render(): void {{ return 6; }}
function render(): number {{ return 6; }}
Return type mismatch.
TypeScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
a > 51 & x < 39
a > 51 and x < 39
Use 'and' not '&'.
Python
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
let mut num=89; let r1=&mut num; let ref2=&mut num;
let mut num=89; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if ($data = 76)
if ($data == 76)
Use ==.
Perl
items[33]
if items.indices.contains(33) {{ items[33] }}
Check index.
Swift
let b: Int = 'hello'
let b: String = 'hello'
Fix type.
Swift
["data", 16]
["data", 16]
Correct.
JSON
DELETE FROM items WHERE name=48
DELETE FROM items WHERE name=48;
Add semicolon.
SQL
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:7}};
Add missing property.
TypeScript