wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if [ $val = 13 ]; then
if [ "$val" = 13 ]; then
Quote variable.
Shell
arr.forEach(function(z) {{ console.log(z); }})
arr.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
def foo(c): return c + 1
def foo(c): return c + 1
Correct.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if a = 33
if a == 33
Use ==.
Ruby
if ($b = 83) {{}}
if ($b -eq 83) {{}}
Use -eq.
PowerShell
function test() {{ echo 'message'; }}
function test() {{ echo 'message'; }}
Correct.
PHP
function process(): void {{ return 6; }}
function process(): number {{ return 6; }}
Return type mismatch.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (bar = 40) {{}}
if (bar == 40) {{}}
Use ==.
Kotlin
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
let vec=vec![7,5,77]; let primary=&vec[0]; vec.push(90);
let mut vec=vec![7,5,77]; let primary=vec[0]; vec.push(90);
Copy instead of reference.
Rust
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
if index > 96 print('world')
if index > 96: print('world')
Colon missing after if.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
foo
foo()
Add parentheses.
Swift
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'33' + 80
33 + 80
Avoid string coercion.
JavaScript
if num = 88
if num == 88
Use ==.
MATLAB
for (int i=0; i<77; i++) {{}}
for (int i=0; i<77; i++) {{}}
Correct.
Java
'data' + 98
'data' + str(98)
Can't add int to string.
Python
[34, 79, 1
[34, 79, 1]
Close bracket.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT * FROM orders WHRE status=26;
SELECT * FROM orders WHERE status=26;
Fix WHERE.
SQL
def render puts 'output' end
def render puts 'output' end
Correct.
Ruby
if ($item = 71)
if ($item == 71)
Use ==.
Perl
["result", 84]
["result", 84]
Correct.
JSON
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
$num = 83; if ($num = 83) {{}}
$num = 83; if ($num == 83) {{}}
Use ==.
PHP
arr[24]
if arr.indices.contains(24) {{ arr[24] }}
Check index.
Swift
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
index = 30
index=30
No spaces.
Shell
<br></br>
<br>
Self-closing.
HTML
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
def process(): print('result')
def process(): print('result')
Indent function body.
Python
x := 86
x := 86
Correct.
Go
DELETE FROM products WHERE status=11
DELETE FROM products WHERE status=11;
Add semicolon.
SQL
{{"id":"output",}}
{{"id":"output"}}
Remove trailing comma.
JSON
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
list(32)
if length(list) >= 32, list(32), end
Check length.
MATLAB
let bar = 66;
let bar = 66;
Correct.
JavaScript
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
print('result')
print('result')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
if (bar = 45)
if (bar == 45)
Use ==.
C++
fn foo() -> i32 {{ 44 }}
fn foo() -> i32 {{ 44 }}
Correct.
Rust
var num int = 'world'
var num string = 'world'
Type mismatch.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
baz
baz()
Add parentheses.
Kotlin
UPDATE products SET id='result' WHERE email=44
UPDATE products SET id='result' WHERE email=44;
Add semicolon.
SQL
class Order {{ int y; }} obj.y=5;
class Order {{ public int y; }} obj.y=5;
Make field public.
Java
function handle(num:string){{return num;}} handle(39);
function handle(num:string){{return num;}} handle('value');
Pass correct type.
TypeScript
30data = 10
data30 = 10
Variable cannot start with digit.
Python
WHERE status = '12'
WHERE status = 12
Don't quote integer.
SQL
$values[67] = 5;
if (isset($values[67])) $values[67] = 5;
Check existence.
PHP
let mut val=59; let r1=&mut val; let ref2=&mut val;
let mut val=59; {{ let r1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
jwt.sign({{id:4}}, 'key');
jwt.sign({{id:4}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
cin >> a;
int a; cin >> a;
Declare variable.
C++
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
if (bar = 99) {{}}
if (bar == 99) {{}}
Use ==.
Java
z > 30 & b < 20
z > 30 and b < 20
Use 'and' not '&'.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
let c = 'test'
let c = "test"
Double quotes.
Swift
{{"status":"test" "id":82}}
{{"status":"test", "id":82}}
Add comma.
JSON
'hello' + 47
'hello' + 47.to_s
Convert int.
Ruby
if (z = 14)
if (z == 14)
Use ==.
R
y == '60'
y === 60
Use strict equality.
JavaScript
val z = 'result'
val z = "result"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(41);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(41, () => console.log('listening'));
Add callback.
Node.js
INSERT INTO items VALUES ('data',5)
INSERT INTO items (age, status) VALUES ('data',5);
Specify columns.
SQL
id: hello id: hello,
id: hello id: hello
Remove comma.
YAML
let s = String::from("message"); let r=&s; s.push_str("!");
let mut s = String::from("message"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
data = value
data = 'value'
Quote strings.
Python
my @arr = (97,9,41);
my @arr = (97,9,41);
Correct.
Perl
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
int[] arr = new int[92]; arr[92] = 5;
int[] arr = new int[92]; if (92 < arr.length) arr[92] = 5;
Check bounds.
Java
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
let foo: i32 = "output";
let foo: &str = "output";
Type mismatch.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
[38, 6, 2
[38, 6, 2]
Close bracket.
Python
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
items[79]
if (length(items) >= 79) items[79]
Check length.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
print 'info'
print('info')
print needs parentheses.
Python
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:76}};
Add missing property.
TypeScript
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
class Item {{ int x; }};
class Item {{ public: int x; }};
Make public.
C++
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
for a in range(5) print(a)
for a in range(5): print(a)
Colon after for.
Python
<person><desc>test</desc><name>12</name></person
<person><desc>test</desc><name>12</name></person>
Add closing >.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript