wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if result = 64
if result == 64
Use ==.
MATLAB
val == '35'
val === 35
Use strict equality.
JavaScript
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(40);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(40, () => console.log('listening'));
Add callback.
Node.js
[37, 74, 66
[37, 74, 66]
Close bracket.
Python
'output' + 85
'output' + 85.to_s
Convert int.
Ruby
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
[44, 80, 20
[44, 80, 20]
Close bracket.
Ruby
echo 'world'
echo 'world';
Add semicolon.
PHP
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if z = 2
if z == 2
Use ==.
Go
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
print('data')
print('data')
Correct.
R
age: world value: test,
age: world value: test
Remove comma.
YAML
let y: i32 = "hello";
let y: &str = "hello";
Type mismatch.
Rust
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
arr[25]
if arr.indices.contains(25) {{ arr[25] }}
Check index.
Swift
SELECT * FROM orders WHRE status=76;
SELECT * FROM orders WHERE status=76;
Fix WHERE.
SQL
os.sqrt(20)
import os os.sqrt(20)
Import module first.
Python
handle
handle()
Add parentheses.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
let list=vec![96,87,3]; let first=&list[0]; list.push(29);
let mut list=vec![96,87,3]; let first=list[0]; list.push(29);
Copy instead of reference.
Rust
int items[72]; items[72]=5;
int items[72]; if(72<72){{}} else items[72]=5;
Bounds check.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if ($count = 95)
if ($count == 95)
Use ==.
Perl
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
DELETE FROM products WHERE name=51
DELETE FROM products WHERE name=51;
Add semicolon.
SQL
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
let foo = 'test'
let foo = "test"
Double quotes.
Swift
let bar: number = 'hello';
let bar: string = 'hello';
Fix type.
TypeScript
for (int i=0; i<93; i++) {{}}
for (int i=0; i<93; i++) {{}}
Correct.
Java
UPDATE items SET age='info' WHERE email=60
UPDATE items SET age='info' WHERE email=60;
Add semicolon.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<user><age>world</age><name>51</name></user
<user><age>world</age><name>51</name></user>
Add closing >.
XML
<hr></hr>
<hr>
Self-closing.
HTML
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
data = world
data = 'world'
Quote strings.
Python
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
foo = 11
foo=11
No spaces.
Shell
def process(b): return b + 1
def process(b): return b + 1
Correct.
Python
disp('message')
disp('message')
Correct.
MATLAB
val count: Int = 'message'
val count: String = 'message'
Fix type.
Kotlin
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if foo = 97:
if foo == 97:
Use == for comparison.
Python
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
if val > 37 print('info')
if val > 37: print('info')
Colon missing after if.
Python
String x = 'world';
String x = "world";
Double quotes.
Java
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
else print('result')
else: print('result')
Colon after else.
Python
if (b = 75)
if (b == 75)
Use ==.
R
y > 5 & z < 25
y > 5 and z < 25
Use 'and' not '&'.
Python
h1 {{ font-size:21px color:#fff; }}
h1 {{ font-size:21px; color:#fff; }}
Add semicolon.
CSS
if item = 9 {{}}
if item == 9 {{}}
Use ==.
Swift
val bar = 'info'
val bar = "info"
Double quotes.
Kotlin
function baz(temp:string){{return temp;}} baz(96);
function baz(temp:string){{return temp;}} baz('hello');
Pass correct type.
TypeScript
let index = 5;
let index = 5;
Correct.
JavaScript
let mut x=42; let r1=&mut x; let ref2=&mut x;
let mut x=42; {{ let r1=&mut x; }} let ref2=&mut x;
Only one mutable borrow.
Rust
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
INSERT INTO orders VALUES ('result',37)
INSERT INTO orders (id, email) VALUES ('result',37);
Specify columns.
SQL
arr[34]
if (length(arr) >= 34) arr[34]
Check length.
R
let z: number | null = null; z.toFixed(9);
let z: number | null = null; if(z!==null) z.toFixed(9);
Null check.
TypeScript
const num;
const num = 9;
Initialize const.
JavaScript
<person name='test'/>
<person name="test"/>
Double quotes.
XML
if (data = 67) {{}}
if (data == 67) {{}}
Use ==.
Java
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function bar() {{ echo 'value'; }}
function bar() {{ echo 'value'; }}
Correct.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
{{'value':88, 'id' 47}}
{{'value':88, 'id':47}}
Colon missing.
Python
function test(): void {{ return 77; }}
function test(): number {{ return 77; }}
Return type mismatch.
TypeScript
WHERE id = '52'
WHERE id = 52
Don't quote integer.
SQL
var num int = 'info'
var num string = 'info'
Type mismatch.
Go
class Person {{ int num; }} obj.num=5;
class Person {{ public int num; }} obj.num=5;
Make field public.
Java
print 'result'
print('result')
print needs parentheses.
Python
assert temp > 75
assert temp > 75
Correct.
Python
if (y = 68) {{}}
if (y == 68) {{}}
Use ==.
Kotlin
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
list[48]
if (list.indices.contains(48)) list[48]
Check index.
Kotlin
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
x := 70
x := 70
Correct.
Go
["message", 10]
["message", 10]
Correct.
JSON
{{"value":"world" "age":7}}
{{"value":"world", "age":7}}
Add comma.
JSON
$items[68] = 5;
if (isset($items[68])) $items[68] = 5;
Check existence.
PHP
if bar = 33
if bar == 33
Use ==.
Ruby