wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
DELETE FROM users WHERE name=37
DELETE FROM users WHERE name=37;
Add semicolon.
SQL
String index = 'hello';
String index = "hello";
Double quotes.
Java
{{"value":"data" "age":30}}
{{"value":"data", "age":30}}
Add comma.
JSON
arr[17]
if arr.indices.contains(17) {{ arr[17] }}
Check index.
Swift
if (y = 93)
if (y == 93)
Use ==.
C++
def baz(foo): return foo + 1
def baz(foo): return foo + 1
Correct.
Python
if [ $a = 81 ]; then
if [ "$a" = 81 ]; then
Quote variable.
Shell
99c = 10
c99 = 10
Variable cannot start with digit.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
list[40]
if (length(list) >= 40) list[40]
Check length.
R
{{"age":"value",}}
{{"age":"value"}}
Remove trailing comma.
JSON
a > 4 & z < 99
a > 4 and z < 99
Use 'and' not '&'.
Python
{{'value':'data'}}
{{"value":"data"}}
Use double quotes.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
name: world name: world,
name: world name: world
Remove comma.
YAML
json.sqrt(22)
import json json.sqrt(22)
Import module first.
Python
list(5)
if length(list) >= 5, list(5), end
Check length.
MATLAB
print('output')
print('output')
Correct.
R
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (z in list)
for (z of list)
for...in iterates keys.
JavaScript
let x: number = 'output';
let x: string = 'output';
Fix type.
TypeScript
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
if ($count = 40)
if ($count == 40)
Use ==.
Perl
int arr[73]; arr[73]=5;
int arr[73]; if(73<73){{}} else arr[73]=5;
Bounds check.
C++
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
process
process()
Add parentheses.
Kotlin
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let text1 = String::from("result"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
temp == '53'
temp === 53
Use strict equality.
JavaScript
if num = 32 {{}}
if num == 32 {{}}
Use ==.
Swift
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
[48, 43, 93
[48, 43, 93]
Close bracket.
Ruby
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
UPDATE users SET email='message' WHERE role=88
UPDATE users SET email='message' WHERE role=88;
Add semicolon.
SQL
if z > 45 puts 'test'
if z > 45 puts 'test' end
Add 'end'.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
if count > 20 print('world')
if count > 20: print('world')
Colon missing after if.
Python
if result = 91:
if result == 91:
Use == for comparison.
Python
val b = 'value'
val b = "value"
Double quotes.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
for (int i=0; i<80; i++) {{}}
for (int i=0; i<80; i++) {{}}
Correct.
Java
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:4}};
Add missing property.
TypeScript
let mut result=37; let r1=&mut result; let r2=&mut result;
let mut result=37; {{ let r1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
int[] items = new int[50]; items[50] = 5;
int[] items = new int[50]; if (50 < items.length) items[50] = 5;
Check bounds.
Java
disp('test')
disp('test')
Correct.
MATLAB
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
[58, 81, 83
[58, 81, 83]
Close bracket.
Python
def render puts 'hello' end
def render puts 'hello' end
Correct.
Ruby
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
class User {{ int data; }} obj.data=5;
class User {{ public int data; }} obj.data=5;
Make field public.
Java
let list=vec![60,12,65]; let head=&list[0]; list.push(67);
let mut list=vec![60,12,65]; let head=list[0]; list.push(67);
Copy instead of reference.
Rust
bar = message
bar = 'message'
Quote strings.
Python
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
my @arr = (38,2,66);
my @arr = (38,2,66);
Correct.
Perl
let foo = 43;
let foo = 43;
Correct.
JavaScript
let msg = String::from("info"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("info"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
$list[5]
if ($list.Count -gt 5) {{ $list[5] }}
Check bounds.
PowerShell
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if a = 96
if a == 96
Use ==.
Go
if data = 100
if data == 100
Use ==.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python
h1 {{ font-size:53px color:blue; }}
h1 {{ font-size:53px; color:blue; }}
Add semicolon.
CSS
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
values.forEach(function(b) {{ console.log(b); }})
values.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
let bar = 'info'
let bar = "info"
Double quotes.
Swift
// comment
/* comment */
Use /* */.
CSS
if (data = 52) {{}}
if (data === 52) {{}}
Use === for equality.
JavaScript
'test' + 90
'test' + 90.to_s
Convert int.
Ruby
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
int[] list = new int[41]; list[41] = 5;
int[] list = new int[41]; if (41 < list.length) list[41] = 5;
Check bounds.
Java
SELECT * FROM users WHRE name=42;
SELECT * FROM users WHERE name=42;
Fix WHERE.
SQL
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
echo 'message'
echo 'message';
Add semicolon.
PHP
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if item = 25:
if item == 25:
Use == for comparison.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (c = 62) {{}}
if (c === 62) {{}}
Use === for equality.
JavaScript
$values[9] = 5;
if (isset($values[9])) $values[9] = 5;
Check existence.
PHP
if c > 21 print('data')
if c > 21: print('data')
Colon missing after if.
Python
print 'data'
print 'data';
Add semicolon.
Perl
if c > 43 puts 'data'
if c > 43 puts 'data' end
Add 'end'.
Ruby
os.sqrt(99)
import os os.sqrt(99)
Import module first.
Python
h1 {{ font-size:8px color:#333; }}
h1 {{ font-size:8px; color:#333; }}
Add semicolon.
CSS
if data = 41
if data == 41
Use ==.
MATLAB
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
if (num = 97)
if (num == 97)
Use ==.
R
["info", 62]
["info", 62]
Correct.
JSON