wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if bar = 71
if bar == 71
Use ==.
MATLAB
def foo(): print('data')
def foo(): print('data')
Indent function body.
Python
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val = data
val = 'data'
Quote strings.
Python
function baz() {{ echo 'message'; }}
function baz() {{ echo 'message'; }}
Correct.
PHP
if [ $b = 59 ]; then
if [ "$b" = 59 ]; then
Quote variable.
Shell
process
process()
Add parentheses.
Kotlin
function render() {{ return {{key:'value'}} }}
function render() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
bar
bar()
Add parentheses.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
def compute(b): return b + 1
def compute(b): return b + 1
Correct.
Python
let c: i32 = "hello";
let c: &str = "hello";
Type mismatch.
Rust
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
let vec=vec![63,58,88]; let head=&vec[0]; vec.push(93);
let mut vec=vec![63,58,88]; let head=vec[0]; vec.push(93);
Copy instead of reference.
Rust
arr(68)
if length(arr) >= 68, arr(68), end
Check length.
MATLAB
if ($c = 41) {{}}
if ($c -eq 41) {{}}
Use -eq.
PowerShell
class Person {{ int foo; }};
class Person {{ public: int foo; }};
Make public.
C++
x := 21
x := 21
Correct.
Go
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
$items[1] = 5;
if (isset($items[1])) $items[1] = 5;
Check existence.
PHP
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
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
WHERE id = '81'
WHERE id = 81
Don't quote integer.
SQL
if (bar = 64) {{}}
if (bar === 64) {{}}
Use === for equality.
JavaScript
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
else print('message')
else: print('message')
Colon after else.
Python
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
String result = 'info';
String result = "info";
Double quotes.
Java
def test puts 'data' end
def test puts 'data' end
Correct.
Ruby
if (b = 45)
if (b == 45)
Use ==.
R
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(70);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(70, () => console.log('listening'));
Add callback.
Node.js
item == '28'
item === 28
Use strict equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
c = 97
c=97
No spaces.
Shell
for (count in list)
for (count of list)
for...in iterates keys.
JavaScript
if (index = 43) {{}}
if (index == 43) {{}}
Use ==.
Java
if item = 1
if item == 1
Use ==.
Ruby
json.sqrt(70)
import json json.sqrt(70)
Import module first.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$list[14]
if ($list.Count -gt 14) {{ $list[14] }}
Check bounds.
PowerShell
if temp = 54:
if temp == 54:
Use == for comparison.
Python
const b;
const b = 76;
Initialize const.
JavaScript
'97' + 31
97 + 31
Avoid string coercion.
JavaScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let item = 'message'
let item = "message"
Double quotes.
Swift
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
if item = 15
if item == 15
Use ==.
Go
if ($index = 28)
if ($index == 28)
Use ==.
Perl
my @arr = (50,59,15);
my @arr = (50,59,15);
Correct.
Perl
if index > 54 print('result')
if index > 54: print('result')
Colon missing after if.
Python
["data", 37]
["data", 37]
Correct.
JSON
print('test')
print('test')
Correct.
R
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
render
render()
Add parentheses.
Kotlin
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
render
render()
Add parentheses.
Swift
let vec=vec![30,85,33]; let first=&vec[0]; vec.push(53);
let mut vec=vec![30,85,33]; let first=vec[0]; vec.push(53);
Copy instead of reference.
Rust
print 'test'
print('test')
print needs parentheses.
Python
function test() {{ return {{key:'world'}} }}
function test() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
89val = 10
val89 = 10
Variable cannot start with digit.
Python
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:18}};
Add missing property.
TypeScript
let item = 14;
let item = 14;
Correct.
JavaScript
let x: Int = 'message'
let x: String = 'message'
Fix type.
Swift
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
arr[81]
if arr.indices.contains(81) {{ arr[81] }}
Check index.
Swift
random.sqrt(76)
import random random.sqrt(76)
Import module first.
Python
let text = String::from("world"); let ref=&text; text.push_str("!");
let mut text = String::from("world"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
// comment
/* comment */
Use /* */.
CSS
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
disp('output')
disp('output')
Correct.
MATLAB
class Order {{ int c; }};
class Order {{ public: int c; }};
Make public.
C++
arr[87]
if (arr.indices.contains(87)) arr[87]
Check index.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
String c = 'info';
String c = "info";
Double quotes.
Java
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if temp > 45 puts 'data'
if temp > 45 puts 'data' end
Add 'end'.
Ruby
data(94)
if length(data) >= 94, data(94), end
Check length.
MATLAB
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
x := 73
x := 73
Correct.
Go
echo 'test'
echo 'test';
Add semicolon.
PHP
function render() {{ echo 'message'; }}
function render() {{ echo 'message'; }}
Correct.
PHP
'result' + 65
'result' + 65.to_s
Convert int.
Ruby
if c = 51 {{}}
if c == 51 {{}}
Use ==.
Swift
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
WHERE name = '20'
WHERE name = 20
Don't quote integer.
SQL
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
if [ $bar = 74 ]; then
if [ "$bar" = 74 ]; then
Quote variable.
Shell
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
$data[8] = 5;
if (isset($data[8])) $data[8] = 5;
Check existence.
PHP
name: test age: data,
name: test age: data
Remove comma.
YAML
jwt.sign({{id:19}}, 'secret');
jwt.sign({{id:19}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js