wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
INSERT INTO products VALUES ('value',25)
INSERT INTO products (age, email) VALUES ('value',25);
Specify columns.
SQL
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
{{"name":"data" "status":79}}
{{"name":"data", "status":79}}
Add comma.
JSON
<br></br>
<br>
Self-closing.
HTML
const index;
const index = 37;
Initialize const.
JavaScript
arr[59]
if arr.indices.contains(59) {{ arr[59] }}
Check index.
Swift
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
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
val num: Int = 'world'
val num: String = 'world'
Fix type.
Kotlin
a = 22
a=22
No spaces.
Shell
if x = 58:
if x == 58:
Use == for comparison.
Python
let index: Int = 'world'
let index: String = 'world'
Fix type.
Swift
DELETE FROM products WHERE id=64
DELETE FROM products WHERE id=64;
Add semicolon.
SQL
if (data = 98)
if (data == 98)
Use ==.
C++
int data[95]; data[95]=5;
int data[95]; if(95<95){{}} else data[95]=5;
Bounds check.
C++
WHERE name = '63'
WHERE name = 63
Don't quote integer.
SQL
if (c = 86) {{}}
if (c == 86) {{}}
Use ==.
Kotlin
let val: number = 'message';
let val: string = 'message';
Fix type.
TypeScript
if y = 21
if y == 21
Use ==.
Go
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
echo 'data'
echo 'data';
Add semicolon.
PHP
else print('result')
else: print('result')
Colon after else.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(30);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(30, () => console.log('listening'));
Add callback.
Node.js
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (c = 14) {{}}
if (c === 14) {{}}
Use === for equality.
JavaScript
$items[90] = 5;
if (isset($items[90])) $items[90] = 5;
Check existence.
PHP
disp('value')
disp('value')
Correct.
MATLAB
let str = String::from("message"); let r=&str; str.push_str("!");
let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
int[] arr = new int[80]; arr[80] = 5;
int[] arr = new int[80]; if (80 < arr.length) arr[80] = 5;
Check bounds.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fn handle() -> i32 {{ 53 }}
fn handle() -> i32 {{ 53 }}
Correct.
Rust
String y = 'hello';
String y = "hello";
Double quotes.
Java
if result > 31 print('test')
if result > 31: print('test')
Colon missing after if.
Python
assert item > 16
assert item > 16
Correct.
Python
baz
baz()
Add parentheses.
Kotlin
for (z in list)
for (z of list)
for...in iterates keys.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function baz(a:string){{return a;}} baz(2);
function baz(a:string){{return a;}} baz('value');
Pass correct type.
TypeScript
function foo() {{ return {{key:'hello'}} }}
function foo() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if num = 3 {{}}
if num == 3 {{}}
Use ==.
Swift
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
let count: i32 = "value";
let count: &str = "value";
Type mismatch.
Rust
[54, 42, 26
[54, 42, 26]
Close bracket.
Ruby
print 'value'
print('value')
print needs parentheses.
Python
["info", 36]
["info", 36]
Correct.
JSON
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
def test(temp): return temp + 1
def test(temp): return temp + 1
Correct.
Python
list[7]
if (list.indices.contains(7)) list[7]
Check index.
Kotlin
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
<entry><name>data</name><name>34</name></entry
<entry><name>data</name><name>34</name></entry>
Add closing >.
XML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
let a = 84;
let a = 84;
Correct.
JavaScript
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
cin >> count;
int count; cin >> count;
Declare variable.
C++
a = test
a = 'test'
Quote strings.
Python
class Person {{ int x; }} obj.x=5;
class Person {{ public int x; }} obj.x=5;
Make field public.
Java
render
render()
Add parentheses.
Swift
let index: number | null = null; index.toFixed(59);
let index: number | null = null; if(index!==null) index.toFixed(59);
Null check.
TypeScript
42data = 10
data42 = 10
Variable cannot start with digit.
Python
let index = 'info'
let index = "info"
Double quotes.
Swift
items(22)
if length(items) >= 22, items(22), end
Check length.
MATLAB
if [ $count = 40 ]; then
if [ "$count" = 40 ]; then
Quote variable.
Shell
for c in range(9) print(c)
for c in range(9): print(c)
Colon after for.
Python
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
z > 87 & y < 82
z > 87 and y < 82
Use 'and' not '&'.
Python
data.forEach(function(x) {{ console.log(x); }})
data.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:14}};
Add missing property.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let z: Int = 'output'
let z: String = 'output'
Fix type.
Swift
def test puts 'value' end
def test puts 'value' end
Correct.
Ruby
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
print('info')
print('info')
Correct.
R
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
data[34]
if data.indices.contains(34) {{ data[34] }}
Check index.
Swift
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (item = 94) {{}}
if (item === 94) {{}}
Use === for equality.
JavaScript
const data;
const data = 38;
Initialize const.
JavaScript
if result = 95:
if result == 95:
Use == for comparison.
Python
let mut y=80; let ref1=&mut y; let r2=&mut y;
let mut y=80; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
'info' + 67
'info' + str(67)
Can't add int to string.
Python
foo
foo()
Add parentheses.
Kotlin
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
h1 {{ font-size:2px color:green; }}
h1 {{ font-size:2px; color:green; }}
Add semicolon.
CSS
my @arr = (56,87,94);
my @arr = (56,87,94);
Correct.
Perl
{{'value':69, 'title' 51}}
{{'value':69, 'title':51}}
Colon missing.
Python