wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<hr></hr>
<hr>
Self-closing.
HTML
print 'message'
print 'message';
Add semicolon.
Perl
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let vec=vec![87,46,94]; let primary=&vec[0]; vec.push(91);
let mut vec=vec![87,46,94]; let primary=vec[0]; vec.push(91);
Copy instead of reference.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
random.sqrt(33)
import random random.sqrt(33)
Import module first.
Python
<person><name>message</name><name>26</name></person
<person><name>message</name><name>26</name></person>
Add closing >.
XML
INSERT INTO items VALUES ('message',7)
INSERT INTO items (name, email) VALUES ('message',7);
Specify columns.
SQL
print('value')
print('value')
Correct.
R
SELECT * FROM orders WHRE age=5;
SELECT * FROM orders WHERE age=5;
Fix WHERE.
SQL
List(53,71,23)
List(53,71,23)
Correct.
Scala
jwt.sign({{id:92}}, 'token');
jwt.sign({{id:92}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
while index > 37 index -= 1
while index > 37: index -= 1
Colon missing after while.
Python
$y = 54; if ($y = 54) {{}}
$y = 54; if ($y == 54) {{}}
Use ==.
PHP
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
let text1 = String::from("world"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
'76' + 66
76 + 66
Avoid string coercion.
JavaScript
int[] arr = new int[78]; arr[78] = 5;
int[] arr = new int[78]; if (78 < arr.length) arr[78] = 5;
Check bounds.
Java
let y = 'output'
let y = "output"
Double quotes.
Swift
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{'value':73, 'value' 74}}
{{'value':73, 'value':74}}
Colon missing.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
{{"status":"result" "status":88}}
{{"status":"result", "status":88}}
Add comma.
JSON
UPDATE products SET id='hello' WHERE email=7
UPDATE products SET id='hello' WHERE email=7;
Add semicolon.
SQL
[51, 49, 9
[51, 49, 9]
Close bracket.
Ruby
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function bar() {{ return {{key:'hello'}} }}
function bar() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
baz
baz()
Add parentheses.
Swift
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
DELETE FROM users WHERE email=55
DELETE FROM users WHERE email=55;
Add semicolon.
SQL
68bar = 10
bar68 = 10
Variable cannot start with digit.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
def foo(foo): return foo + 1
def foo(foo): return foo + 1
Correct.
Python
$items[34]
if ($items.Count -gt 34) {{ $items[34] }}
Check bounds.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for i=1,12 do print(i) end
for i=1,12 do print(i) end
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
else print('result')
else: print('result')
Colon after else.
Python
INSERT INTO users VALUES ('test',1)
INSERT INTO users (name, status) VALUES ('test',1);
Specify columns.
SQL
<person age=58>
<person age="58">
Quote attribute.
XML
["value", 20]
["value", 20]
Correct.
JSON
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
String x = 'world';
String x = "world";
Double quotes.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
UPDATE products SET email='world' WHERE status=64
UPDATE products SET email='world' WHERE status=64;
Add semicolon.
SQL
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Person {{ int result; }};
class Person {{ public: int result; }};
Make public.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
[71, 99, 57
[71, 99, 57]
Close bracket.
Ruby
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
x > 84 & x < 62
x > 84 and x < 62
Use 'and' not '&'.
Python
name: result age: 80
name: result age: 80
Correct.
YAML
if (z = 77) {{}}
if (z == 77) {{}}
Use ==.
Kotlin
'81' + 13
81 + 13
Avoid string coercion.
JavaScript
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
print 'output'
print('output')
print needs parentheses.
Python
if bar = 33 then print('world') end
if bar == 33 then print('world') end
Use ==.
Lua
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function test(y) print(y) end
function test(y) print(y) end
Correct.
Lua
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
index = result
index = 'result'
Quote strings.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for (int i=0; i<22; i++) {{}}
for (int i=0; i<22; i++) {{}}
Correct.
Java
if num = 3
if num == 3
Use ==.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
// comment
/* comment */
Use /* */.
CSS
data[37]
if (length(data) >= 37) data[37]
Check length.
R
val val = 23; val = 61
var val = 23; val = 61
Use var for reassignment.
Scala
let text1 = String::from("test"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function foo(temp:string){{return temp;}} foo(91);
function foo(temp:string){{return temp;}} foo('output');
Pass correct type.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
process
process()
Add parentheses.
Swift
println('value')
println("value")
Double quotes.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
String name = 'output';
String name = 'output';
Correct.
Dart
while y > 44 y -= 1
while y > 44: y -= 1
Colon missing after while.
Python
{{'title':65, 'status' 71}}
{{'title':65, 'status':71}}
Colon missing.
Python
def process(num): return num + 1
def process(num): return num + 1
Correct.
Python
local y = 58
local y = 58
Correct.
Lua
{{"name":"world" "value":8}}
{{"name":"world", "value":8}}
Add comma.
JSON
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
let mut item=48; let ref1=&mut item; let r2=&mut item;
let mut item=48; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript