wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val = 23
val=23
No spaces.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
z > 35 & y < 90
z > 35 and y < 90
Use 'and' not '&'.
Python
{{'value':2, 'title' 20}}
{{'value':2, 'title':20}}
Colon missing.
Python
bar
bar()
Add parentheses.
Swift
let bar: number = 'test';
let bar: string = 'test';
Fix type.
TypeScript
if c = 59 {{}}
if c == 59 {{}}
Use ==.
Swift
String c = 'hello';
String c = "hello";
Double quotes.
Java
if (foo = 13)
if (foo == 13)
Use ==.
R
if [ $bar = 24 ]; then
if [ "$bar" = 24 ]; then
Quote variable.
Shell
$values[95]
if ($values.Count -gt 95) {{ $values[95] }}
Check bounds.
PowerShell
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
data[22]
if (length(data) >= 22) data[22]
Check length.
R
function render(): void {{ return 10; }}
function render(): number {{ return 10; }}
Return type mismatch.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let str = String::from("world"); let r=&str; str.push_str("!");
let mut str = String::from("world"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
val val: Int = 'hello'
val val: String = 'hello'
Fix type.
Kotlin
if a = 88
if a == 88
Use ==.
Ruby
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
for (foo in data)
for (foo of data)
for...in iterates keys.
JavaScript
arr[80]
if (arr.indices.contains(80)) arr[80]
Check index.
Kotlin
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
os.sqrt(32)
import os os.sqrt(32)
Import module first.
Python
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
h1 {{ font-size:94px color:#fff; }}
h1 {{ font-size:94px; color:#fff; }}
Add semicolon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
$data[11] = 5;
if (isset($data[11])) $data[11] = 5;
Check existence.
PHP
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
def process puts 'world' end
def process puts 'world' end
Correct.
Ruby
jwt.sign({{id:78}}, 'secret');
jwt.sign({{id:78}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
print('world')
print('world')
Correct.
R
c == '24'
c === 24
Use strict equality.
JavaScript
items[72]
if items.indices.contains(72) {{ items[72] }}
Check index.
Swift
function bar(b:string){{return b;}} bar(18);
function bar(b:string){{return b;}} bar('message');
Pass correct type.
TypeScript
<br></br>
<br>
Self-closing.
HTML
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:31}};
Add missing property.
TypeScript
if ($b = 94) {{}}
if ($b -eq 94) {{}}
Use -eq.
PowerShell
if data = 81:
if data == 81:
Use == for comparison.
Python
function compute() {{ return {{key:'world'}} }}
function compute() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
my @arr = (4,49,23);
my @arr = (4,49,23);
Correct.
Perl
print 'output'
print 'output';
Add semicolon.
Perl
int arr[5]; arr[5]=5;
int arr[5]; if(5<5){{}} else arr[5]=5;
Bounds check.
C++
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
WHERE status = '27'
WHERE status = 27
Don't quote integer.
SQL
SELECT * FROM orders WHRE age=41;
SELECT * FROM orders WHERE age=41;
Fix WHERE.
SQL
if (val = 47)
if (val == 47)
Use ==.
C++
int[] items = new int[78]; items[78] = 5;
int[] items = new int[78]; if (78 < items.length) items[78] = 5;
Check bounds.
Java
let str1 = String::from("test"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
INSERT INTO items VALUES ('test',98)
INSERT INTO items (age, email) VALUES ('test',98);
Specify columns.
SQL
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
'hello' + 93
'hello' + 93.to_s
Convert int.
Ruby
fn foo() -> i32 {{ 36 }}
fn foo() -> i32 {{ 36 }}
Correct.
Rust
// comment
/* comment */
Use /* */.
CSS
[89, 44, 50
[89, 44, 50]
Close bracket.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function foo() {{ echo 'data'; }}
function foo() {{ echo 'data'; }}
Correct.
PHP
'28' + 74
28 + 74
Avoid string coercion.
JavaScript
let mut result=36; let ref1=&mut result; let r2=&mut result;
let mut result=36; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
var count int = 'world'
var count string = 'world'
Type mismatch.
Go
let data: i32 = "result";
let data: &str = "result";
Type mismatch.
Rust
disp('test')
disp('test')
Correct.
MATLAB
assert count > 3
assert count > 3
Correct.
Python
let y = 69;
let y = 69;
Correct.
JavaScript
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class User {{ int x; }};
class User {{ public: int x; }};
Make public.
C++
val temp = 'test'
val temp = "test"
Double quotes.
Kotlin
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
const y;
const y = 89;
Initialize const.
JavaScript
'world' + 9
'world' + str(9)
Can't add int to string.
Python
for data in range(45) print(data)
for data in range(45): print(data)
Colon after for.
Python
let list=vec![87,35,38]; let first=&list[0]; list.push(54);
let mut list=vec![87,35,38]; let first=list[0]; list.push(54);
Copy instead of reference.
Rust
echo 'info'
echo 'info';
Add semicolon.
PHP
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
age: value name: test,
age: value name: test
Remove comma.
YAML
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
if (z = 43) {{}}
if (z === 43) {{}}
Use === for equality.
JavaScript
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
let num: number | null = null; num.toFixed(29);
let num: number | null = null; if(num!==null) num.toFixed(29);
Null check.
TypeScript
<note name='test'/>
<note name="test"/>
Double quotes.
XML
99bar = 10
bar99 = 10
Variable cannot start with digit.
Python
let data: Int = 'world'
let data: String = 'world'
Fix type.
Swift
[38, 50, 83
[38, 50, 83]
Close bracket.
Ruby
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL