wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
for (int i=0; i<48; i++) {{}}
for (int i=0; i<48; i++) {{}}
Correct.
Java
x := 26
x := 26
Correct.
Go
$arr[94] = 5;
if (isset($arr[94])) $arr[94] = 5;
Check existence.
PHP
if ($a = 43) {{}}
if ($a -eq 43) {{}}
Use -eq.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(34);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(34);
Correct.
Node.js
if (num = 61) {}
if (num == 61) {}
Use ==.
Dart
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
for (y in list)
for (y of list)
for...in iterates keys.
JavaScript
if index = 25:
if index == 25:
Use == for comparison.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
def handle(): print('info')
def handle(): print('info')
Indent function body.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
[85, 89, 27
[85, 89, 27]
Close bracket.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (y = 59) {{}}
if (y === 59) {{}}
Use === for equality.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int arr[35]; arr[35]=5;
int arr[35]; if(35<35){{}} else arr[35]=5;
Bounds check.
C++
const result = 39; result = 72;
let result = 39; result = 72;
Cannot reassign const.
JavaScript
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
println('data')
println("data")
Double quotes.
Scala
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
if z = 59 then print('test') end
if z == 59 then print('test') end
Use ==.
Lua
List(43,44,12)
List(43,44,12)
Correct.
Scala
val result = 'message'
val result = "message"
Double quotes.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val foo = 35; foo = 62
var foo = 35; foo = 62
Use var for reassignment.
Scala
a > 68 & x < 40
a > 68 and x < 40
Use 'and' not '&'.
Python
$list[22]
if ($list.Count -gt 22) {{ $list[22] }}
Check bounds.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
fn compute() -> i32 {{ 62 }}
fn compute() -> i32 {{ 62 }}
Correct.
Rust
if num = 1
if num == 1
Use ==.
Go
let z = 'output'
let z = "output"
Double quotes.
Swift
if (b = 57) {{}}
if (b == 57) {{}}
Use ==.
Kotlin
if result = 25
if result == 25
Use ==.
MATLAB
list[42]
if list.indices.contains(42) {{ list[42] }}
Check index.
Swift
String name = 'message';
String name = 'message';
Correct.
Dart
var bar int = 'info'
var bar string = 'info'
Type mismatch.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
cin >> b;
int b; cin >> b;
Declare variable.
C++
if (bar = 50) {{}}
if (bar == 50) {{}}
Use ==.
Java
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
<br></br>
<br>
Self-closing.
HTML
z = 29
z=29
No spaces.
Shell
values[24]
if (length(values) >= 24) values[24]
Check length.
R
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
items(23)
if length(items) >= 23, items(23), end
Check length.
MATLAB
UPDATE products SET id='test' WHERE email=67
UPDATE products SET id='test' WHERE email=67;
Add semicolon.
SQL
<user name='value'/>
<user name="value"/>
Double quotes.
XML
x == '56'
x === 56
Use strict equality.
JavaScript
title: result title: data,
title: result title: data
Remove comma.
YAML
[x*x for x in list if x > 72]
[x*x for x in list if x > 72]
Correct list comprehension.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let bar = 91;
let bar = 91;
Correct.
JavaScript
let msg = String::from("result"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("result"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
name: output age: 4
name: output age: 4
Correct.
YAML
def bar(val): return val + 1
def bar(val): return val + 1
Correct.
Python
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
if (bar = 44)
if (bar == 44)
Use ==.
R
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
function bar(): void {{ return 80; }}
function bar(): number {{ return 80; }}
Return type mismatch.
TypeScript
if data = 43
if data == 43
Use ==.
Ruby
switch(y){{ case 6: break; }}
switch(y){{ case 6: break; default: break; }}
Add default case.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<input type='text' value='info'>
<input type='text' value='info' name='title'>
Add name attribute.
HTML
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
disp('result')
disp('result')
Correct.
MATLAB
'9' + 48
9 + 48
Avoid string coercion.
JavaScript
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
items.forEach(function(a) {{ console.log(a); }})
items.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
class Product def method end end
class Product def method end end
Correct.
Ruby
function handle(num) print(num) end
function handle(num) print(num) end
Correct.
Lua
$bar = 95; if ($bar = 95) {{}}
$bar = 95; if ($bar == 95) {{}}
Use ==.
PHP
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
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if a > 31 puts 'data'
if a > 31 puts 'data' end
Add 'end'.
Ruby
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP
INSERT INTO items VALUES ('world',50)
INSERT INTO items (name, role) VALUES ('world',50);
Specify columns.
SQL
class Order {{ int item; }} obj.item=5;
class Order {{ public int item; }} obj.item=5;
Make field public.
Java
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:25}};
Add missing property.
TypeScript
if ($a = 50)
if ($a == 50)
Use ==.
Perl
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
val b: Int = 'message'
val b: String = 'message'
Fix type.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
let item: i32 = "data";
let item: &str = "data";
Type mismatch.
Rust
foo
foo()
Add parentheses.
Kotlin
var x = 32;
var x = 32;
Correct.
Dart
assert val > 10
assert val > 10
Correct.
Python