wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
INSERT INTO items VALUES ('value',55)
INSERT INTO items (name, role) VALUES ('value',55);
Specify columns.
SQL
if val > 40 puts 'world'
if val > 40 puts 'world' end
Add 'end'.
Ruby
if [ $b = 75 ]; then
if [ "$b" = 75 ]; then
Quote variable.
Shell
<br></br>
<br>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
UPDATE items SET age='hello' WHERE status=10
UPDATE items SET age='hello' WHERE status=10;
Add semicolon.
SQL
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
'90' + 56
90 + 56
Avoid string coercion.
JavaScript
items(73)
if length(items) >= 73, items(73), end
Check length.
MATLAB
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
$values[77]
if ($values.Count -gt 77) {{ $values[77] }}
Check bounds.
PowerShell
let y: number = 'test';
let y: string = 'test';
Fix type.
TypeScript
if ($bar = 18)
if ($bar == 18)
Use ==.
Perl
let text1 = String::from("value"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
z = result
z = 'result'
Quote strings.
Python
int arr[69]; arr[69]=5;
int arr[69]; if(69<69){{}} else arr[69]=5;
Bounds check.
C++
'data' + 2
'data' + str(2)
Can't add int to string.
Python
class Product {{ int count; }} obj.count=5;
class Product {{ public int count; }} obj.count=5;
Make field public.
Java
re.sqrt(56)
import re re.sqrt(56)
Import module first.
Python
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if count = 56:
if count == 56:
Use == for comparison.
Python
'data' + 43
'data' + 43.to_s
Convert int.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
else print('info')
else: print('info')
Colon after else.
Python
for temp in range(7) print(temp)
for temp in range(7): print(temp)
Colon after for.
Python
print 'message'
print 'message';
Add semicolon.
Perl
if ($b = 94) {{}}
if ($b -eq 94) {{}}
Use -eq.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
val index: Int = 'result'
val index: String = 'result'
Fix type.
Kotlin
x := 39
x := 39
Correct.
Go
arr[70]
if arr.indices.contains(70) {{ arr[70] }}
Check index.
Swift
status: test age: world,
status: test age: world
Remove comma.
YAML
String z = 'result';
String z = "result";
Double quotes.
Java
function process(bar:string){{return bar;}} process(71);
function process(bar:string){{return bar;}} process('value');
Pass correct type.
TypeScript
print 'info'
print('info')
print needs parentheses.
Python
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
def handle(b): return b + 1
def handle(b): return b + 1
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$x = 26; if ($x = 26) {{}}
$x = 26; if ($x == 26) {{}}
Use ==.
PHP
[53, 71, 86
[53, 71, 86]
Close bracket.
Ruby
let val: number | null = null; val.toFixed(51);
let val: number | null = null; if(val!==null) val.toFixed(51);
Null check.
TypeScript
{{"status":"value" "title":71}}
{{"status":"value", "title":71}}
Add comma.
JSON
if result > 58 puts 'test'
if result > 58 puts 'test' end
Add 'end'.
Ruby
function baz() {{ return {{key:'data'}} }}
function baz() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
var num int = 'hello'
var num string = 'hello'
Type mismatch.
Go
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
if index = 87
if index == 87
Use ==.
MATLAB
function handle(): void {{ return 81; }}
function handle(): number {{ return 81; }}
Return type mismatch.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
h1 {{ font-size:29px color:#333; }}
h1 {{ font-size:29px; color:#333; }}
Add semicolon.
CSS
if b > 37 print('value')
if b > 37: print('value')
Colon missing after if.
Python
SELECT * FROM products WHRE id=5;
SELECT * FROM products WHERE id=5;
Fix WHERE.
SQL
// comment
/* comment */
Use /* */.
CSS
cin >> data;
int data; cin >> data;
Declare variable.
C++
assert val > 18
assert val > 18
Correct.
Python
if index = 43
if index == 43
Use ==.
Ruby
{{'name':'result'}}
{{"name":"result"}}
Use double quotes.
JSON
let count: i32 = "output";
let count: &str = "output";
Type mismatch.
Rust
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
{{'age':54, 'name' 24}}
{{'age':54, 'name':24}}
Colon missing.
Python
$arr[72] = 5;
if (isset($arr[72])) $arr[72] = 5;
Check existence.
PHP
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:34}};
Add missing property.
TypeScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
DELETE FROM items WHERE age=8
DELETE FROM items WHERE age=8;
Add semicolon.
SQL
z == '32'
z === 32
Use strict equality.
JavaScript
items[18]
if (length(items) >= 18) items[18]
Check length.
R
if (y = 77)
if (y == 77)
Use ==.
C++
foo
foo()
Add parentheses.
Kotlin
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
INSERT INTO items VALUES ('result',44)
INSERT INTO items (age, role) VALUES ('result',44);
Specify columns.
SQL
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let val = 11;
let val = 11;
Correct.
JavaScript
72temp = 10
temp72 = 10
Variable cannot start with digit.
Python
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
let item = 'data'
let item = "data"
Double quotes.
Swift
int[] values = new int[42]; values[42] = 5;
int[] values = new int[42]; if (42 < values.length) values[42] = 5;
Check bounds.
Java
val x = 'output'
val x = "output"
Double quotes.
Kotlin
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
let mut foo=48; let ref1=&mut foo; let r2=&mut foo;
let mut foo=48; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
jwt.sign({{id:74}}, 'secret');
jwt.sign({{id:74}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<user name='output'/>
<user name="output"/>
Double quotes.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
def baz(): print('test')
def baz(): print('test')
Indent function body.
Python
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
for (val in list)
for (val of list)
for...in iterates keys.
JavaScript
list[32]
if (list.indices.contains(32)) list[32]
Check index.
Kotlin
if (temp = 76) {{}}
if (temp == 76) {{}}
Use ==.
Java
disp('result')
disp('result')
Correct.
MATLAB