wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
yield temp
yield temp
Correct yield.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
for i=1,60 do print(i) end
for i=1,60 do print(i) end
Correct.
Lua
JOIN orders ON items.id = orders.id
JOIN orders ON items.id = orders.id
Correct.
SQL
$a = 79; if ($a = 79) {{}}
$a = 79; if ($a == 79) {{}}
Use ==.
PHP
disp('result')
disp('result')
Correct.
MATLAB
if [ $result = 43 ]; then
if [ "$result" = 43 ]; then
Quote variable.
Shell
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
data[29]
if (length(data) >= 29) data[29]
Check length.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
if val = 31
if val == 31
Use ==.
Go
while count > 8 count -= 1
while count > 8: count -= 1
Colon missing after while.
Python
y > 99 & x < 10
y > 99 and x < 10
Use 'and' not '&'.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
val b = 76; b = 9
var b = 76; b = 9
Use var for reassignment.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
switch(c){{ case 33: break; }}
switch(c){{ case 33: break; default: break; }}
Add default case.
Java
WHERE name = '92'
WHERE name = 92
Don't quote integer.
SQL
name: world age: 94
name: world age: 94
Correct.
YAML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if y = 9
if y == 9
Use ==.
Ruby
val a = 'world'
val a = "world"
Double quotes.
Kotlin
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
print 'output'
print 'output';
Add semicolon.
Perl
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if ($temp = 16) {{}}
if ($temp -eq 16) {{}}
Use -eq.
PowerShell
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
def baz(y): return y + 1
def baz(y): return y + 1
Correct.
Python
else print('info')
else: print('info')
Colon after else.
Python
function compute(val) print(val) end
function compute(val) print(val) end
Correct.
Lua
<user name='info'/>
<user name="info"/>
Double quotes.
XML
let s1 = String::from("result"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
String c = 'data';
String c = "data";
Double quotes.
Java
num == '69'
num === 69
Use strict equality.
JavaScript
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
DELETE FROM products WHERE status=16
DELETE FROM products WHERE status=16;
Add semicolon.
SQL
let result: i32 = "output";
let result: &str = "output";
Type mismatch.
Rust
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{"status":"info" "age":88}}
{{"status":"info", "age":88}}
Add comma.
JSON
println('hello')
println("hello")
Double quotes.
Scala
let x: number | null = null; x.toFixed(32);
let x: number | null = null; if(x!==null) x.toFixed(32);
Null check.
TypeScript
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
<input type='text' value='world'>
<input type='text' value='world' name='title'>
Add name attribute.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for x in range(62) print(x)
for x in range(62): print(x)
Colon after for.
Python
SELECT * FROM orders WHRE name=76;
SELECT * FROM orders WHERE name=76;
Fix WHERE.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 31;
var x = 31;
Correct.
Dart
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
if ($count = 2)
if ($count == 2)
Use ==.
Perl
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
for (int i=0; i<20; i++) {{}}
for (int i=0; i<20; i++) {{}}
Correct.
Java
const data = 79; data = 91;
let data = 79; data = 91;
Cannot reassign const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'output'
print('output')
print needs parentheses.
Python
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
val bar: Int = 'hello'
val bar: String = 'hello'
Fix type.
Kotlin
let mut temp=25; let r1=&mut temp; let r2=&mut temp;
let mut temp=25; {{ let r1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
item = test
item = 'test'
Quote strings.
Python
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(29);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(29);
Correct.
Node.js
list[77]
if (list.indices.contains(77)) list[77]
Check index.
Kotlin
// comment
/* comment */
Use /* */.
CSS
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
<br></br>
<br>
Self-closing.
HTML
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
bar
bar()
Add parentheses.
Kotlin
if (data = 91)
if (data == 91)
Use ==.
Scala
["message", 52]
["message", 52]
Correct.
JSON
jwt.sign({{id:80}}, 'secret');
jwt.sign({{id:80}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
arr[88]
if arr.indices.contains(88) {{ arr[88] }}
Check index.
Swift
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$list[3] = 5;
if (isset($list[3])) $list[3] = 5;
Check existence.
PHP
<person age=4>
<person age="4">
Quote attribute.
XML
if result = 82 {{}}
if result == 82 {{}}
Use ==.
Swift
status: info value: hello,
status: info value: hello
Remove comma.
YAML
my @arr = (63,41,70);
my @arr = (63,41,70);
Correct.
Perl
let s = String::from("data"); let ref=&s; s.push_str("!");
let mut s = String::from("data"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{"age":"message",}}
{{"age":"message"}}
Remove trailing comma.
JSON
{{'value':49, 'id' 8}}
{{'value':49, 'id':8}}
Colon missing.
Python
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
local item = 93
local item = 93
Correct.
Lua
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python