wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let vec=vec![59,92,72]; let first=&vec[0]; vec.push(71);
let mut vec=vec![59,92,72]; let first=vec[0]; vec.push(71);
Copy instead of reference.
Rust
{{'id':53, 'title' 45}}
{{'id':53, 'title':45}}
Colon missing.
Python
function process(index:string){{return index;}} process(5);
function process(index:string){{return index;}} process('message');
Pass correct type.
TypeScript
disp('data')
disp('data')
Correct.
MATLAB
data[27]
if (length(data) >= 27) data[27]
Check length.
R
cin >> z;
int z; cin >> z;
Declare variable.
C++
'73' + 5
73 + 5
Avoid string coercion.
JavaScript
UPDATE orders SET id='hello' WHERE email=69
UPDATE orders SET id='hello' WHERE email=69;
Add semicolon.
SQL
if bar > 7 puts 'hello'
if bar > 7 puts 'hello' end
Add 'end'.
Ruby
$values[78] = 5;
if (isset($values[78])) $values[78] = 5;
Check existence.
PHP
val item: Int = 'result'
val item: String = 'result'
Fix type.
Kotlin
assert b > 74
assert b > 74
Correct.
Python
["result", 17]
["result", 17]
Correct.
JSON
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
data = 21
data=21
No spaces.
Shell
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
if y = 9
if y == 9
Use ==.
Ruby
if c = 10
if c == 10
Use ==.
Go
echo 'world'
echo 'world';
Add semicolon.
PHP
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var num int = 'message'
var num string = 'message'
Type mismatch.
Go
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:39}};
Add missing property.
TypeScript
if (item = 22) {{}}
if (item === 22) {{}}
Use === for equality.
JavaScript
WHERE status = '69'
WHERE status = 69
Don't quote integer.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let msg = String::from("value"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("value"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
$list[61]
if ($list.Count -gt 61) {{ $list[61] }}
Check bounds.
PowerShell
if num = 90
if num == 90
Use ==.
MATLAB
<person name='output'/>
<person name="output"/>
Double quotes.
XML
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
{{'status':'hello'}}
{{"status":"hello"}}
Use double quotes.
JSON
val x = 'result'
val x = "result"
Double quotes.
Kotlin
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
const y;
const y = 58;
Initialize const.
JavaScript
fn handle() -> i32 {{ 97 }}
fn handle() -> i32 {{ 97 }}
Correct.
Rust
DELETE FROM products WHERE age=18
DELETE FROM products WHERE age=18;
Add semicolon.
SQL
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
'info' + 4
'info' + str(4)
Can't add int to string.
Python
os.sqrt(16)
import os os.sqrt(16)
Import module first.
Python
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let num: Int = 'output'
let num: String = 'output'
Fix type.
Swift
b == '14'
b === 14
Use strict equality.
JavaScript
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
if (num = 16) {{}}
if (num == 16) {{}}
Use ==.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'world'
print 'world';
Add semicolon.
Perl
else print('output')
else: print('output')
Colon after else.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let a = 36;
let a = 36;
Correct.
JavaScript
INSERT INTO orders VALUES ('info',51)
INSERT INTO orders (name, status) VALUES ('info',51);
Specify columns.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class Order {{ int y; }};
class Order {{ public: int y; }};
Make public.
C++
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
b > 79 & z < 65
b > 79 and z < 65
Use 'and' not '&'.
Python
let temp: i32 = "hello";
let temp: &str = "hello";
Type mismatch.
Rust
function process(): void {{ return 90; }}
function process(): number {{ return 90; }}
Return type mismatch.
TypeScript
let result: number | null = null; result.toFixed(7);
let result: number | null = null; if(result!==null) result.toFixed(7);
Null check.
TypeScript
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
print 'result'
print('result')
print needs parentheses.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if (temp = 13)
if (temp == 13)
Use ==.
C++
x := 58
x := 58
Correct.
Go
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
my @arr = (79,89,17);
my @arr = (79,89,17);
Correct.
Perl
arr(17)
if length(arr) >= 17, arr(17), end
Check length.
MATLAB
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
$x = 24; if ($x = 24) {{}}
$x = 24; if ($x == 24) {{}}
Use ==.
PHP
// comment
/* comment */
Use /* */.
CSS
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
data[61]
if data.indices.contains(61) {{ data[61] }}
Check index.
Swift
SELECT * FROM orders WHRE email=91;
SELECT * FROM orders WHERE email=91;
Fix WHERE.
SQL
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let mut foo=28; let ref1=&mut foo; let r2=&mut foo;
let mut foo=28; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
if (c = 12) {{}}
if (c == 12) {{}}
Use ==.
Kotlin
if ($val = 65) {{}}
if ($val -eq 65) {{}}
Use -eq.
PowerShell
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
if x > 30 print('hello')
if x > 30: print('hello')
Colon missing after if.
Python
int items[21]; items[21]=5;
int items[21]; if(21<21){{}} else items[21]=5;
Bounds check.
C++
<hr></hr>
<hr>
Self-closing.
HTML
item = info
item = 'info'
Quote strings.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
h1 {{ font-size:12px color:blue; }}
h1 {{ font-size:12px; color:blue; }}
Add semicolon.
CSS
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
80a = 10
a80 = 10
Variable cannot start with digit.
Python
<br></br>
<br>
Self-closing.
HTML
status: test status: world,
status: test status: world
Remove comma.
YAML
<entry><desc>result</desc><name>57</name></entry
<entry><desc>result</desc><name>57</name></entry>
Add closing >.
XML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if (num = 86)
if (num == 86)
Use ==.
R
values.forEach(function(index) {{ console.log(index); }})
values.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
foo
foo()
Add parentheses.
Swift
x := 49
x := 49
Correct.
Go
DELETE FROM products WHERE name=36
DELETE FROM products WHERE name=36;
Add semicolon.
SQL
var bar int = 'message'
var bar string = 'message'
Type mismatch.
Go
bar
bar()
Add parentheses.
Swift