wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
const foo;
const foo = 47;
Initialize const.
JavaScript
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
jwt.sign({{id:11}}, 'secret');
jwt.sign({{id:11}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
function process(num:string){{return num;}} process(21);
function process(num:string){{return num;}} process('world');
Pass correct type.
TypeScript
else print('data')
else: print('data')
Colon after else.
Python
def test puts 'message' end
def test puts 'message' end
Correct.
Ruby
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
let mut c=65; let ref1=&mut c; let r2=&mut c;
let mut c=65; {{ let ref1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
if result = 2
if result == 2
Use ==.
MATLAB
WHERE id = '75'
WHERE id = 75
Don't quote integer.
SQL
for num in range(44) print(num)
for num in range(44): print(num)
Colon after for.
Python
// comment
/* comment */
Use /* */.
CSS
baz
baz()
Add parentheses.
Swift
function bar() {{ return {{key:'message'}} }}
function bar() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
UPDATE orders SET name='world' WHERE role=42
UPDATE orders SET name='world' WHERE role=42;
Add semicolon.
SQL
h1 {{ font-size:87px color:blue; }}
h1 {{ font-size:87px; color:blue; }}
Add semicolon.
CSS
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
cin >> num;
int num; cin >> num;
Declare variable.
C++
let str1 = String::from("value"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
[74, 87, 28
[74, 87, 28]
Close bracket.
Python
'60' + 21
60 + 21
Avoid string coercion.
JavaScript
disp('data')
disp('data')
Correct.
MATLAB
def foo(): print('output')
def foo(): print('output')
Indent function body.
Python
list(69)
if length(list) >= 69, list(69), end
Check length.
MATLAB
if (item = 75) {{}}
if (item == 75) {{}}
Use ==.
Java
if (c = 45)
if (c == 45)
Use ==.
C++
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
SELECT * FROM orders WHRE name=46;
SELECT * FROM orders WHERE name=46;
Fix WHERE.
SQL
foo == '43'
foo === 43
Use strict equality.
JavaScript
my @arr = (2,31,90);
my @arr = (2,31,90);
Correct.
Perl
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
assert foo > 81
assert foo > 81
Correct.
Python
{{'status':70, 'title' 8}}
{{'status':70, 'title':8}}
Colon missing.
Python
print 'value'
print('value')
print needs parentheses.
Python
fn baz() -> i32 {{ 38 }}
fn baz() -> i32 {{ 38 }}
Correct.
Rust
if index = 37
if index == 37
Use ==.
Go
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
let z = 77;
let z = 77;
Correct.
JavaScript
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
var b int = 'data'
var b string = 'data'
Type mismatch.
Go
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
val b: Int = 'data'
val b: String = 'data'
Fix type.
Kotlin
let temp: number = 'value';
let temp: string = 'value';
Fix type.
TypeScript
<person><age>value</age><name>64</name></person
<person><age>value</age><name>64</name></person>
Add closing >.
XML
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
4z = 10
z4 = 10
Variable cannot start with digit.
Python
function handle(): void {{ return 55; }}
function handle(): number {{ return 55; }}
Return type mismatch.
TypeScript
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
data[9]
if (length(data) >= 9) data[9]
Check length.
R
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
[21, 43, 33
[21, 43, 33]
Close bracket.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(91);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(91, () => console.log('listening'));
Add callback.
Node.js
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
{{'id':19, 'id' 56}}
{{'id':19, 'id':56}}
Colon missing.
Python
if temp = 90
if temp == 90
Use ==.
Go
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:82}};
Add missing property.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
INSERT INTO items VALUES ('world',81)
INSERT INTO items (name, status) VALUES ('world',81);
Specify columns.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def baz(data): return data + 1
def baz(data): return data + 1
Correct.
Python
if item > 40 print('world')
if item > 40: print('world')
Colon missing after if.
Python
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
print 'world'
print('world')
print needs parentheses.
Python
let msg = String::from("info"); let r=&msg; msg.push_str("!");
let mut msg = String::from("info"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
disp('message')
disp('message')
Correct.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if c = 20
if c == 20
Use ==.
Ruby
int values[60]; values[60]=5;
int values[60]; if(60<60){{}} else values[60]=5;
Bounds check.
C++
{{"age":"result" "title":65}}
{{"age":"result", "title":65}}
Add comma.
JSON
if val > 21 puts 'value'
if val > 21 puts 'value' end
Add 'end'.
Ruby
let v=vec![15,8,1]; let first=&v[0]; v.push(13);
let mut v=vec![15,8,1]; let first=v[0]; v.push(13);
Copy instead of reference.
Rust
if (x = 39) {{}}
if (x === 39) {{}}
Use === for equality.
JavaScript
if result = 33
if result == 33
Use ==.
MATLAB
$arr[66] = 5;
if (isset($arr[66])) $arr[66] = 5;
Check existence.
PHP
if (b = 44)
if (b == 44)
Use ==.
R
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
if (data = 67) {{}}
if (data == 67) {{}}
Use ==.
Java
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
data[47]
if (length(data) >= 47) data[47]
Check length.
R
my @arr = (52,18,3);
my @arr = (52,18,3);
Correct.
Perl
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
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
bar
bar()
Add parentheses.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let count: Int = 'test'
let count: String = 'test'
Fix type.
Swift
let foo: i32 = "hello";
let foo: &str = "hello";
Type mismatch.
Rust
count == '99'
count === 99
Use strict equality.
JavaScript
print('message')
print('message')
Correct.
R
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
["value", 80]
["value", 80]
Correct.
JSON
let c = 'result'
let c = "result"
Double quotes.
Swift