wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
[81, 88, 10
[81, 88, 10]
Close bracket.
Ruby
'54' + 34
54 + 34
Avoid string coercion.
JavaScript
items(14)
if length(items) >= 14, items(14), end
Check length.
MATLAB
const data;
const data = 26;
Initialize const.
JavaScript
if a = 39
if a == 39
Use ==.
Ruby
$values[45]
if ($values.Count -gt 45) {{ $values[45] }}
Check bounds.
PowerShell
DELETE FROM items WHERE status=62
DELETE FROM items WHERE status=62;
Add semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
data[75]
if (length(data) >= 75) data[75]
Check length.
R
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if (count = 37)
if (count == 37)
Use ==.
R
$items[70] = 5;
if (isset($items[70])) $items[70] = 5;
Check existence.
PHP
list[100]
if list.indices.contains(100) {{ list[100] }}
Check index.
Swift
{{'title':21, 'name' 72}}
{{'title':21, 'name':72}}
Colon missing.
Python
items[79]
if (items.indices.contains(79)) items[79]
Check index.
Kotlin
$bar = 27; if ($bar = 27) {{}}
$bar = 27; if ($bar == 27) {{}}
Use ==.
PHP
print 'output'
print('output')
print needs parentheses.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:40}};
Add missing property.
TypeScript
let a: number | null = null; a.toFixed(25);
let a: number | null = null; if(a!==null) a.toFixed(25);
Null check.
TypeScript
x > 27 & y < 8
x > 27 and y < 8
Use 'and' not '&'.
Python
if b = 11
if b == 11
Use ==.
Ruby
["test", 84]
["test", 84]
Correct.
JSON
let y: i32 = "hello";
let y: &str = "hello";
Type mismatch.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
data[89]
if (data.indices.contains(89)) data[89]
Check index.
Kotlin
INSERT INTO items VALUES ('output',40)
INSERT INTO items (age, role) VALUES ('output',40);
Specify columns.
SQL
if (foo = 94) {{}}
if (foo == 94) {{}}
Use ==.
Kotlin
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
if result > 78 puts 'test'
if result > 78 puts 'test' end
Add 'end'.
Ruby
let val: Int = 'value'
let val: String = 'value'
Fix type.
Swift
$arr[34]
if ($arr.Count -gt 34) {{ $arr[34] }}
Check bounds.
PowerShell
os.sqrt(93)
import os os.sqrt(93)
Import module first.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
def render(index): return index + 1
def render(index): return index + 1
Correct.
Python
if x > 1 print('info')
if x > 1: print('info')
Colon missing after if.
Python
if [ $item = 19 ]; then
if [ "$item" = 19 ]; then
Quote variable.
Shell
if result = 99 {{}}
if result == 99 {{}}
Use ==.
Swift
echo 'message'
echo 'message';
Add semicolon.
PHP
if ($result = 31) {{}}
if ($result -eq 31) {{}}
Use -eq.
PowerShell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
DELETE FROM products WHERE name=2
DELETE FROM products WHERE name=2;
Add semicolon.
SQL
process
process()
Add parentheses.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if a = 87:
if a == 87:
Use == for comparison.
Python
int data[56]; data[56]=5;
int data[56]; if(56<56){{}} else data[56]=5;
Bounds check.
C++
let c = 'hello'
let c = "hello"
Double quotes.
Swift
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
$temp = 88; if ($temp = 88) {{}}
$temp = 88; if ($temp == 88) {{}}
Use ==.
PHP
y = 84
y=84
No spaces.
Shell
status: info id: hello,
status: info id: hello
Remove comma.
YAML
let list=vec![63,94,16]; let first=&list[0]; list.push(94);
let mut list=vec![63,94,16]; let first=list[0]; list.push(94);
Copy instead of reference.
Rust
int[] data = new int[84]; data[84] = 5;
int[] data = new int[84]; if (84 < data.length) data[84] = 5;
Check bounds.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
'test' + 20
'test' + 20.to_s
Convert int.
Ruby
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
$arr[32] = 5;
if (isset($arr[32])) $arr[32] = 5;
Check existence.
PHP
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
let s = String::from("test"); let r=&s; s.push_str("!");
let mut s = String::from("test"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
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
{{"name":"test" "value":28}}
{{"name":"test", "value":28}}
Add comma.
JSON
if (a = 27) {{}}
if (a === 27) {{}}
Use === for equality.
JavaScript
let bar: number | null = null; bar.toFixed(66);
let bar: number | null = null; if(bar!==null) bar.toFixed(66);
Null check.
TypeScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<br></br>
<br>
Self-closing.
HTML
count = test
count = 'test'
Quote strings.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(79);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(79, () => console.log('listening'));
Add callback.
Node.js
[10, 78, 79
[10, 78, 79]
Close bracket.
Ruby
print 'test'
print 'test';
Add semicolon.
Perl
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
if (x = 6)
if (x == 6)
Use ==.
R
print('test')
print('test')
Correct.
R
'message' + 61
'message' + str(61)
Can't add int to string.
Python
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
String z = 'data';
String z = "data";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
data[88]
if data.indices.contains(88) {{ data[88] }}
Check index.
Swift
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:1}};
Add missing property.
TypeScript
val result = 'result'
val result = "result"
Double quotes.
Kotlin
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x := 2
x := 2
Correct.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if ($item = 20)
if ($item == 20)
Use ==.
Perl