wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
["value", 99]
["value", 99]
Correct.
JSON
if (foo = 45) {{}}
if (foo === 45) {{}}
Use === for equality.
JavaScript
$data[33] = 5;
if (isset($data[33])) $data[33] = 5;
Check existence.
PHP
String c = 'output';
String c = "output";
Double quotes.
Java
jwt.sign({{id:44}}, 'token');
jwt.sign({{id:44}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
// comment
/* comment */
Use /* */.
CSS
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if [ $result = 42 ]; then
if [ "$result" = 42 ]; then
Quote variable.
Shell
print 'value'
print('value')
print needs parentheses.
Python
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
h1 {{ font-size:1px color:green; }}
h1 {{ font-size:1px; color:green; }}
Add semicolon.
CSS
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
c == '25'
c === 25
Use strict equality.
JavaScript
print('result')
print('result')
Correct.
R
function foo(x:string){{return x;}} foo(20);
function foo(x:string){{return x;}} foo('result');
Pass correct type.
TypeScript
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
def bar puts 'test' end
def bar puts 'test' end
Correct.
Ruby
DELETE FROM orders WHERE age=93
DELETE FROM orders WHERE age=93;
Add semicolon.
SQL
test
test()
Add parentheses.
Swift
let text = String::from("result"); let r=&text; text.push_str("!");
let mut text = String::from("result"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
let c: i32 = "test";
let c: &str = "test";
Type mismatch.
Rust
96num = 10
num96 = 10
Variable cannot start with digit.
Python
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
def compute(item): return item + 1
def compute(item): return item + 1
Correct.
Python
if ($x = 88)
if ($x == 88)
Use ==.
Perl
my @arr = (74,67,96);
my @arr = (74,67,96);
Correct.
Perl
UPDATE items SET age='message' WHERE role=78
UPDATE items SET age='message' WHERE role=78;
Add semicolon.
SQL
for num in range(55) print(num)
for num in range(55): print(num)
Colon after for.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
assert z > 45
assert z > 45
Correct.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
INSERT INTO products VALUES ('test',100)
INSERT INTO products (name, email) VALUES ('test',100);
Specify columns.
SQL
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
math.sqrt(94)
import math math.sqrt(94)
Import module first.
Python
if num = 94
if num == 94
Use ==.
Ruby
'output' + 27
'output' + 27.to_s
Convert int.
Ruby
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
let data = 'data'
let data = "data"
Double quotes.
Swift
val = 26
val=26
No spaces.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(88);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(88, () => console.log('listening'));
Add callback.
Node.js
if c = 55:
if c == 55:
Use == for comparison.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
if (count = 41)
if (count == 41)
Use ==.
C++
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
let list=vec![59,71,50]; let head=&list[0]; list.push(65);
let mut list=vec![59,71,50]; let head=list[0]; list.push(65);
Copy instead of reference.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Order {{ int num; }} obj.num=5;
class Order {{ public int num; }} obj.num=5;
Make field public.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (foo = 26) {{}}
if (foo == 26) {{}}
Use ==.
Java
function compute(): void {{ return 71; }}
function compute(): number {{ return 71; }}
Return type mismatch.
TypeScript
'2' + 66
2 + 66
Avoid string coercion.
JavaScript
fn test() -> i32 {{ 2 }}
fn test() -> i32 {{ 2 }}
Correct.
Rust
else print('message')
else: print('message')
Colon after else.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
items[66]
if (length(items) >= 66) items[66]
Check length.
R
let foo: number | null = null; foo.toFixed(100);
let foo: number | null = null; if(foo!==null) foo.toFixed(100);
Null check.
TypeScript
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
let z: number = 'data';
let z: string = 'data';
Fix type.
TypeScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let num = 23;
let num = 23;
Correct.
JavaScript
items[47]
if (items.indices.contains(47)) items[47]
Check index.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const result;
const result = 10;
Initialize const.
JavaScript
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
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
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function render() {{ echo 'world'; }}
function render() {{ echo 'world'; }}
Correct.
PHP
if item > 2 puts 'output'
if item > 2 puts 'output' end
Add 'end'.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
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
print 'data'
print 'data';
Add semicolon.
Perl
id: info age: test,
id: info age: test
Remove comma.
YAML
if (data = 48) {{}}
if (data == 48) {{}}
Use ==.
Kotlin
$x = 61; if ($x = 61) {{}}
$x = 61; if ($x == 61) {{}}
Use ==.
PHP
[85, 83, 67
[85, 83, 67]
Close bracket.
Python
cin >> data;
int data; cin >> data;
Declare variable.
C++
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
process
process()
Add parentheses.
Kotlin
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
WHERE status = '4'
WHERE status = 4
Don't quote integer.
SQL
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
items[94]
if items.indices.contains(94) {{ items[94] }}
Check index.
Swift
y > 70 & y < 66
y > 70 and y < 66
Use 'and' not '&'.
Python
if ($a = 59) {{}}
if ($a -eq 59) {{}}
Use -eq.
PowerShell
{{"age":"result",}}
{{"age":"result"}}
Remove trailing comma.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
<br></br>
<br>
Self-closing.
HTML
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
x := 53
x := 53
Correct.
Go
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{'id':71, 'id' 78}}
{{'id':71, 'id':78}}
Colon missing.
Python
disp('value')
disp('value')
Correct.
MATLAB