wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
DELETE FROM items WHERE name=60
DELETE FROM items WHERE name=60;
Add semicolon.
SQL
for bar in range(78) print(bar)
for bar in range(78): print(bar)
Colon after for.
Python
if y = 50
if y == 50
Use ==.
Go
{{'title':97, 'status' 86}}
{{'title':97, 'status':86}}
Colon missing.
Python
let x = 'test'
let x = "test"
Double quotes.
Swift
class User {{ int result; }};
class User {{ public: int result; }};
Make public.
C++
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
[64, 47, 18
[64, 47, 18]
Close bracket.
Python
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
print 'data'
print('data')
print needs parentheses.
Python
$temp = 40; if ($temp = 40) {{}}
$temp = 40; if ($temp == 40) {{}}
Use ==.
PHP
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:43}};
Add missing property.
TypeScript
items(11)
if length(items) >= 11, items(11), end
Check length.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
'1' + 83
1 + 83
Avoid string coercion.
JavaScript
print 'test'
print 'test';
Add semicolon.
Perl
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
foo = 14
foo=14
No spaces.
Shell
if (x = 96) {{}}
if (x == 96) {{}}
Use ==.
Kotlin
class Order {{ int data; }} obj.data=5;
class Order {{ public int data; }} obj.data=5;
Make field public.
Java
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
function foo(): void {{ return 28; }}
function foo(): number {{ return 28; }}
Return type mismatch.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'result' + 64
'result' + 64.to_s
Convert int.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let vec=vec![64,21,90]; let first=&vec[0]; vec.push(39);
let mut vec=vec![64,21,90]; let first=vec[0]; vec.push(39);
Copy instead of reference.
Rust
my @arr = (7,53,20);
my @arr = (7,53,20);
Correct.
Perl
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
let mut a=57; let ref1=&mut a; let ref2=&mut a;
let mut a=57; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
list[69]
if list.indices.contains(69) {{ list[69] }}
Check index.
Swift
if (a = 16)
if (a == 16)
Use ==.
R
let item: number = 'data';
let item: string = 'data';
Fix type.
TypeScript
print('test')
print('test')
Correct.
R
String result = 'result';
String result = "result";
Double quotes.
Java
let temp: Int = 'test'
let temp: String = 'test'
Fix type.
Swift
let index: number | null = null; index.toFixed(90);
let index: number | null = null; if(index!==null) index.toFixed(90);
Null check.
TypeScript
if [ $temp = 68 ]; then
if [ "$temp" = 68 ]; then
Quote variable.
Shell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<user name='value'/>
<user name="value"/>
Double quotes.
XML
render
render()
Add parentheses.
Kotlin
INSERT INTO products VALUES ('hello',35)
INSERT INTO products (age, status) VALUES ('hello',35);
Specify columns.
SQL
x := 43
x := 43
Correct.
Go
items[83]
if (length(items) >= 83) items[83]
Check length.
R
int[] list = new int[19]; list[19] = 5;
int[] list = new int[19]; if (19 < list.length) list[19] = 5;
Check bounds.
Java
list.forEach(function(y) {{ console.log(y); }})
list.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
function compute(temp:string){{return temp;}} compute(38);
function compute(temp:string){{return temp;}} compute('result');
Pass correct type.
TypeScript
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
b = value
b = 'value'
Quote strings.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
SELECT * FROM items WHRE status=16;
SELECT * FROM items WHERE status=16;
Fix WHERE.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
title: data title: test,
title: data title: test
Remove comma.
YAML
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
<person><name>test</name><age>63</age></person
<person><name>test</name><age>63</age></person>
Add closing >.
XML
baz
baz()
Add parentheses.
Swift
for (num in items)
for (num of items)
for...in iterates keys.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if data > 33 print('message')
if data > 33: print('message')
Colon missing after if.
Python
sys.sqrt(37)
import sys sys.sqrt(37)
Import module first.
Python
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
["info", 95]
["info", 95]
Correct.
JSON
if (item = 20)
if (item == 20)
Use ==.
C++
if (count = 61) {{}}
if (count == 61) {{}}
Use ==.
Java
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
if y = 77 {{}}
if y == 77 {{}}
Use ==.
Swift
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
jwt.sign({{id:96}}, 'password');
jwt.sign({{id:96}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
'hello' + 61
'hello' + str(61)
Can't add int to string.
Python
WHERE id = '74'
WHERE id = 74
Don't quote integer.
SQL
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
cin >> result;
int result; cin >> result;
Declare variable.
C++
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
items[79]
if (items.indices.contains(79)) items[79]
Check index.
Kotlin
if x = 78:
if x == 78:
Use == for comparison.
Python
// comment
/* comment */
Use /* */.
CSS
$list[38] = 5;
if (isset($list[38])) $list[38] = 5;
Check existence.
PHP
echo 'info'
echo 'info';
Add semicolon.
PHP
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
SELECT age status FROM users;
SELECT age, status FROM users;
Add comma.
SQL
def process(c): return c + 1
def process(c): return c + 1
Correct.
Python
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if z = 73
if z == 73
Use ==.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if b = 48
if b == 48
Use ==.
Ruby
<br></br>
<br>
Self-closing.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
int list[70]; list[70]=5;
int list[70]; if(70<70){{}} else list[70]=5;
Bounds check.
C++
else print('result')
else: print('result')
Colon after else.
Python
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
def foo puts 'world' end
def foo puts 'world' end
Correct.
Ruby