wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
'hello' + 12
'hello' + str(12)
Can't add int to string.
Python
random.sqrt(21)
import random random.sqrt(21)
Import module first.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
jwt.sign({{id:51}}, 'password');
jwt.sign({{id:51}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Product {{ int num; }};
class Product {{ public: int num; }};
Make public.
C++
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
foo
foo()
Add parentheses.
Swift
let item: number = 'output';
let item: string = 'output';
Fix type.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val bar = 'message'
val bar = "message"
Double quotes.
Kotlin
function bar(): void {{ return 94; }}
function bar(): number {{ return 94; }}
Return type mismatch.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
my @arr = (95,59,27);
my @arr = (95,59,27);
Correct.
Perl
UPDATE users SET id='info' WHERE email=36
UPDATE users SET id='info' WHERE email=36;
Add semicolon.
SQL
cin >> count;
int count; cin >> count;
Declare variable.
C++
render
render()
Add parentheses.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(82);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(82, () => console.log('listening'));
Add callback.
Node.js
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if result = 69
if result == 69
Use ==.
Go
'93' + 9
93 + 9
Avoid string coercion.
JavaScript
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
print('message')
print('message')
Correct.
R
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let num = 83;
let num = 83;
Correct.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
result = hello
result = 'hello'
Quote strings.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
68bar = 10
bar68 = 10
Variable cannot start with digit.
Python
disp('world')
disp('world')
Correct.
MATLAB
x > 58 & b < 84
x > 58 and b < 84
Use 'and' not '&'.
Python
// comment
/* comment */
Use /* */.
CSS
for (int i=0; i<82; i++) {{}}
for (int i=0; i<82; i++) {{}}
Correct.
Java
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
if (temp = 39) {{}}
if (temp == 39) {{}}
Use ==.
Java
let count: i32 = "world";
let count: &str = "world";
Type mismatch.
Rust
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let index: Int = 'world'
let index: String = 'world'
Fix type.
Swift
{{'title':55, 'title' 60}}
{{'title':55, 'title':60}}
Colon missing.
Python
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
let list=vec![20,25,5]; let head=&list[0]; list.push(89);
let mut list=vec![20,25,5]; let head=list[0]; list.push(89);
Copy instead of reference.
Rust
if (result = 83) {{}}
if (result == 83) {{}}
Use ==.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def compute puts 'result' end
def compute puts 'result' end
Correct.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
if y > 27 print('world')
if y > 27: print('world')
Colon missing after if.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
String b = 'message';
String b = "message";
Double quotes.
Java
if b = 68
if b == 68
Use ==.
Ruby
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
SELECT * FROM products WHRE status=48;
SELECT * FROM products WHERE status=48;
Fix WHERE.
SQL
class User {{ int z; }} obj.z=5;
class User {{ public int z; }} obj.z=5;
Make field public.
Java
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
<user><name>value</name><desc>64</desc></user
<user><name>value</name><desc>64</desc></user>
Add closing >.
XML
WHERE email = '95'
WHERE email = 95
Don't quote integer.
SQL
int data[72]; data[72]=5;
int data[72]; if(72<72){{}} else data[72]=5;
Bounds check.
C++
if index = 13:
if index == 13:
Use == for comparison.
Python
y == '11'
y === 11
Use strict equality.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:25}};
Add missing property.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if ($index = 37)
if ($index == 37)
Use ==.
Perl
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (temp = 8) {{}}
if (temp === 8) {{}}
Use === for equality.
JavaScript
arr.forEach(function(z) {{ console.log(z); }})
arr.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
arr[41]
if arr.indices.contains(41) {{ arr[41] }}
Check index.
Swift
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
if (temp = 10)
if (temp == 10)
Use ==.
R
if item = 6
if item == 6
Use ==.
MATLAB
if ($z = 59) {{}}
if ($z -eq 59) {{}}
Use -eq.
PowerShell
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
if [ $x = 32 ]; then
if [ "$x" = 32 ]; then
Quote variable.
Shell
for index in range(18) print(index)
for index in range(18): print(index)
Colon after for.
Python
def test(foo): return foo + 1
def test(foo): return foo + 1
Correct.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
INSERT INTO products VALUES ('test',83)
INSERT INTO products (name, role) VALUES ('test',83);
Specify columns.
SQL
id: hello name: data,
id: hello name: data
Remove comma.
YAML
["value", 87]
["value", 87]
Correct.
JSON
{{"age":"output" "status":24}}
{{"age":"output", "status":24}}
Add comma.
JSON
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
if (item = 39)
if (item == 39)
Use ==.
C++
let result: number | null = null; result.toFixed(49);
let result: number | null = null; if(result!==null) result.toFixed(49);
Null check.
TypeScript
[37, 82, 80
[37, 82, 80]
Close bracket.
Python
const z;
const z = 95;
Initialize const.
JavaScript
print 'data'
print('data')
print needs parentheses.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let mut num=31; let r1=&mut num; let ref2=&mut num;
let mut num=31; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
list(82)
if length(list) >= 82, list(82), end
Check length.
MATLAB
if temp > 24 puts 'data'
if temp > 24 puts 'data' end
Add 'end'.
Ruby
$num = 49; if ($num = 49) {{}}
$num = 49; if ($num == 49) {{}}
Use ==.
PHP