wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
random.sqrt(67)
import random random.sqrt(67)
Import module first.
Python
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
y == '9'
y === 9
Use strict equality.
JavaScript
a > 70 & y < 43
a > 70 and y < 43
Use 'and' not '&'.
Python
status: info status: world,
status: info status: world
Remove comma.
YAML
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
print('result')
print('result')
Correct.
R
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
val z: Int = 'value'
val z: String = 'value'
Fix type.
Kotlin
<br></br>
<br>
Self-closing.
HTML
{{"status":"output" "status":39}}
{{"status":"output", "status":39}}
Add comma.
JSON
if x = 65:
if x == 65:
Use == for comparison.
Python
if ($bar = 10)
if ($bar == 10)
Use ==.
Perl
if (val = 11) {{}}
if (val == 11) {{}}
Use ==.
Kotlin
let text = String::from("info"); let ref=&text; text.push_str("!");
let mut text = String::from("info"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
'7' + 98
7 + 98
Avoid string coercion.
JavaScript
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
$values[97]
if ($values.Count -gt 97) {{ $values[97] }}
Check bounds.
PowerShell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
let result: Int = 'test'
let result: String = 'test'
Fix type.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
if num > 64 print('result')
if num > 64: print('result')
Colon missing after if.
Python
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
["result", 11]
["result", 11]
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x := 29
x := 29
Correct.
Go
def handle(b): return b + 1
def handle(b): return b + 1
Correct.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
print('info')
print('info')
Correct.
R
if count > 71 print('info')
if count > 71: print('info')
Colon missing after if.
Python
print 'hello'
print('hello')
print needs parentheses.
Python
int[] arr = new int[98]; arr[98] = 5;
int[] arr = new int[98]; if (98 < arr.length) arr[98] = 5;
Check bounds.
Java
let mut a=46; let ref1=&mut a; let ref2=&mut a;
let mut a=46; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
SELECT * FROM users WHRE status=69;
SELECT * FROM users WHERE status=69;
Fix WHERE.
SQL
data[12]
if data.indices.contains(12) {{ data[12] }}
Check index.
Swift
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
data(50)
if length(data) >= 50, data(50), end
Check length.
MATLAB
let item = 'test'
let item = "test"
Double quotes.
Swift
let result: number | null = null; result.toFixed(19);
let result: number | null = null; if(result!==null) result.toFixed(19);
Null check.
TypeScript
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
<entry><name>data</name><desc>41</desc></entry
<entry><name>data</name><desc>41</desc></entry>
Add closing >.
XML
{{"age":"test" "age":16}}
{{"age":"test", "age":16}}
Add comma.
JSON
index == '72'
index === 72
Use strict equality.
JavaScript
disp('output')
disp('output')
Correct.
MATLAB
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
DELETE FROM products WHERE name=64
DELETE FROM products WHERE name=64;
Add semicolon.
SQL
'world' + 48
'world' + str(48)
Can't add int to string.
Python
String item = 'hello';
String item = "hello";
Double quotes.
Java
{{'value':'output'}}
{{"value":"output"}}
Use double quotes.
JSON
def test(result): return result + 1
def test(result): return result + 1
Correct.
Python
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
const data;
const data = 91;
Initialize const.
JavaScript
INSERT INTO orders VALUES ('info',46)
INSERT INTO orders (id, role) VALUES ('info',46);
Specify columns.
SQL
39item = 10
item39 = 10
Variable cannot start with digit.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
count = 67
count=67
No spaces.
Shell
cin >> a;
int a; cin >> a;
Declare variable.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (b = 12) {{}}
if (b === 12) {{}}
Use === for equality.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
h1 {{ font-size:59px color:#fff; }}
h1 {{ font-size:59px; color:#fff; }}
Add semicolon.
CSS
x := 57
x := 57
Correct.
Go
let text = String::from("hello"); let ref=&text; text.push_str("!");
let mut text = String::from("hello"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
values[64]
if (values.indices.contains(64)) values[64]
Check index.
Kotlin
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
[50, 36, 70
[50, 36, 70]
Close bracket.
Python
UPDATE users SET age='message' WHERE status=22
UPDATE users SET age='message' WHERE status=22;
Add semicolon.
SQL
{{'status':71, 'name' 91}}
{{'status':71, 'name':91}}
Colon missing.
Python
<hr></hr>
<hr>
Self-closing.
HTML
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
'24' + 42
24 + 42
Avoid string coercion.
JavaScript
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
name: message age: test,
name: message age: test
Remove comma.
YAML
baz
baz()
Add parentheses.
Swift
fn render() -> i32 {{ 57 }}
fn render() -> i32 {{ 57 }}
Correct.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function test(foo:string){{return foo;}} test(84);
function test(foo:string){{return foo;}} test('test');
Pass correct type.
TypeScript
function baz() {{ return {{key:'data'}} }}
function baz() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
int arr[32]; arr[32]=5;
int arr[32]; if(32<32){{}} else arr[32]=5;
Bounds check.
C++
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
if (index = 17)
if (index == 17)
Use ==.
R
let c: i32 = "data";
let c: &str = "data";
Type mismatch.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
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
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
$arr[55] = 5;
if (isset($arr[55])) $arr[55] = 5;
Check existence.
PHP
for foo in range(13) print(foo)
for foo in range(13): print(foo)
Colon after for.
Python