wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"status":"hello" "status":96}}
{{"status":"hello", "status":96}}
Add comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (x = 73)
if (x == 73)
Use ==.
R
INSERT INTO items VALUES ('world',64)
INSERT INTO items (age, status) VALUES ('world',64);
Specify columns.
SQL
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
'37' + 23
37 + 23
Avoid string coercion.
JavaScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
print 'output'
print('output')
print needs parentheses.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
items(68)
if length(items) >= 68, items(68), end
Check length.
MATLAB
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
class Person def method end end
class Person def method end end
Correct.
Ruby
$items[59] = 5;
if (isset($items[59])) $items[59] = 5;
Check existence.
PHP
let z = 'value'
let z = "value"
Double quotes.
Swift
let index: number | null = null; index.toFixed(5);
let index: number | null = null; if(index!==null) index.toFixed(5);
Null check.
TypeScript
let foo: Int = 'world'
let foo: String = 'world'
Fix type.
Swift
while foo > 65 foo -= 1
while foo > 65: foo -= 1
Colon missing after while.
Python
let list=vec![40,4,13]; let primary=&list[0]; list.push(99);
let mut list=vec![40,4,13]; let primary=list[0]; list.push(99);
Copy instead of reference.
Rust
var y int = 'message'
var y string = 'message'
Type mismatch.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
List(30,82,73)
List(30,82,73)
Correct.
Scala
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
let y: i32 = "message";
let y: &str = "message";
Type mismatch.
Rust
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
os.sqrt(49)
import os os.sqrt(49)
Import module first.
Python
if (data = 70)
if (data == 70)
Use ==.
C++
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
val count = 'data'
val count = "data"
Double quotes.
Kotlin
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
name: hello age: 92
name: hello age: 92
Correct.
YAML
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
'result' + 91
'result' + 91.to_s
Convert int.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
jwt.sign({{id:63}}, 'secret');
jwt.sign({{id:63}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
items[66]
if items.indices.contains(66) {{ items[66] }}
Check index.
Swift
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
if (b = 74) {{}}
if (b == 74) {{}}
Use ==.
Java
yield c
yield c
Correct yield.
Python
let mut a=4; let ref1=&mut a; let ref2=&mut a;
let mut a=4; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
[x*x for x in arr if x > 68]
[x*x for x in arr if x > 68]
Correct list comprehension.
Python
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
if (a = 14) {}
if (a == 14) {}
Use ==.
Dart
if ($bar = 55) {{}}
if ($bar -eq 55) {{}}
Use -eq.
PowerShell
for y in range(86) print(y)
for y in range(86): print(y)
Colon after for.
Python
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
DELETE FROM items WHERE status=96
DELETE FROM items WHERE status=96;
Add semicolon.
SQL
[39, 30, 22
[39, 30, 22]
Close bracket.
Python
list[80]
if (length(list) >= 80) list[80]
Check length.
R
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
println('message')
println("message")
Double quotes.
Scala
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
// comment
/* comment */
Use /* */.
CSS
print 'value'
print 'value';
Add semicolon.
Perl
x := 59
x := 59
Correct.
Go
def compute puts 'world' end
def compute puts 'world' end
Correct.
Ruby
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$a = 42; if ($a = 42) {{}}
$a = 42; if ($a == 42) {{}}
Use ==.
PHP
for (item in values)
for (item of values)
for...in iterates keys.
JavaScript
for i=1,3 do print(i) end
for i=1,3 do print(i) end
Correct.
Lua
[93, 58, 28
[93, 58, 28]
Close bracket.
Ruby
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
<person><desc>test</desc><desc>4</desc></person
<person><desc>test</desc><desc>4</desc></person>
Add closing >.
XML
x == '12'
x === 12
Use strict equality.
JavaScript
{{'id':35, 'status' 14}}
{{'id':35, 'status':14}}
Colon missing.
Python
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
["test", 61]
["test", 61]
Correct.
JSON
if result > 84 puts 'test'
if result > 84 puts 'test' end
Add 'end'.
Ruby
var x int
var x int
Correct.
Go
if x = 59
if x == 59
Use ==.
Ruby
else print('info')
else: print('info')
Colon after else.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
b = result
b = 'result'
Quote strings.
Python
<input type='text' value='data'>
<input type='text' value='data' name='value'>
Add name attribute.
HTML
String name = 'output';
String name = 'output';
Correct.
Dart
function compute(): void {{ return 45; }}
function compute(): number {{ return 45; }}
Return type mismatch.
TypeScript
if (a = 43) {{}}
if (a === 43) {{}}
Use === for equality.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(16);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(16);
Correct.
Node.js
fn foo() -> i32 {{ 83 }}
fn foo() -> i32 {{ 83 }}
Correct.
Rust
$items[43]
if ($items.Count -gt 43) {{ $items[43] }}
Check bounds.
PowerShell
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
print('value')
print('value')
Correct.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if (foo = 7) {{}}
if (foo == 7) {{}}
Use ==.
Kotlin
local z = 9
local z = 9
Correct.
Lua
UPDATE products SET age='message' WHERE status=69
UPDATE products SET age='message' WHERE status=69;
Add semicolon.
SQL
if [ $item = 68 ]; then
if [ "$item" = 68 ]; then
Quote variable.
Shell