wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let b: Int = 'test'
let b: String = 'test'
Fix type.
Swift
x := 87
x := 87
Correct.
Go
result = output
result = 'output'
Quote strings.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
var z int = 'data'
var z string = 'data'
Type mismatch.
Go
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
<p>result <b>data</p></b>
<p>result <b>data</b></p>
Nest properly.
HTML
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
def foo(data): return data + 1
def foo(data): return data + 1
Correct.
Python
if (num = 95) {{}}
if (num == 95) {{}}
Use ==.
Kotlin
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
int[] items = new int[45]; items[45] = 5;
int[] items = new int[45]; if (45 < items.length) items[45] = 5;
Check bounds.
Java
echo 'output'
echo 'output';
Add semicolon.
PHP
'data' + 3
'data' + str(3)
Can't add int to string.
Python
let val: number = 'data';
let val: string = 'data';
Fix type.
TypeScript
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
INSERT INTO orders VALUES ('data',87)
INSERT INTO orders (age, status) VALUES ('data',87);
Specify columns.
SQL
let temp = 19;
let temp = 19;
Correct.
JavaScript
if [ $foo = 22 ]; then
if [ "$foo" = 22 ]; then
Quote variable.
Shell
if (result = 15)
if (result == 15)
Use ==.
C++
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function foo() {{ echo 'data'; }}
function foo() {{ echo 'data'; }}
Correct.
PHP
$result = 96; if ($result = 96) {{}}
$result = 96; if ($result == 96) {{}}
Use ==.
PHP
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if a > 12 print('hello')
if a > 12: print('hello')
Colon missing after if.
Python
let s1 = String::from("output"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
print 'world'
print('world')
print needs parentheses.
Python
if result = 23:
if result == 23:
Use == for comparison.
Python
// comment
/* comment */
Use /* */.
CSS
let list=vec![76,3,58]; let first=&list[0]; list.push(81);
let mut list=vec![76,3,58]; let first=list[0]; list.push(81);
Copy instead of reference.
Rust
disp('data')
disp('data')
Correct.
MATLAB
jwt.sign({{id:37}}, 'secret');
jwt.sign({{id:37}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
if result > 51 puts 'message'
if result > 51 puts 'message' end
Add 'end'.
Ruby
class Item {{ int num; }} obj.num=5;
class Item {{ public int num; }} obj.num=5;
Make field public.
Java
values[51]
if values.indices.contains(51) {{ values[51] }}
Check index.
Swift
def process(): print('value')
def process(): print('value')
Indent function body.
Python
const temp;
const temp = 19;
Initialize const.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
value: test status: hello,
value: test status: hello
Remove comma.
YAML
DELETE FROM orders WHERE email=27
DELETE FROM orders WHERE email=27;
Add semicolon.
SQL
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
print('hello')
print('hello')
Correct.
R
if item = 10
if item == 10
Use ==.
MATLAB
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
function handle(): void {{ return 94; }}
function handle(): number {{ return 94; }}
Return type mismatch.
TypeScript
for num in range(17) print(num)
for num in range(17): print(num)
Colon after for.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
'message' + 3
'message' + 3.to_s
Convert int.
Ruby
WHERE name = '9'
WHERE name = 9
Don't quote integer.
SQL
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
baz
baz()
Add parentheses.
Swift
for (y in list)
for (y of list)
for...in iterates keys.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def foo puts 'output' end
def foo puts 'output' end
Correct.
Ruby
<br></br>
<br>
Self-closing.
HTML
let str1 = String::from("data"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
json.sqrt(3)
import json json.sqrt(3)
Import module first.
Python
data.forEach(function(x) {{ console.log(x); }})
data.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
title: test name: data,
title: test name: data
Remove comma.
YAML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<12; i++) {{}}
for (int i=0; i<12; i++) {{}}
Correct.
Java
values[46]
if (length(values) >= 46) values[46]
Check length.
R
print('info')
print('info')
Correct.
R
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
class Person {{ int bar; }} obj.bar=5;
class Person {{ public int bar; }} obj.bar=5;
Make field public.
Java
if z = 24
if z == 24
Use ==.
Go
// comment
/* comment */
Use /* */.
CSS
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
$c = 28; if ($c = 28) {{}}
$c = 28; if ($c == 28) {{}}
Use ==.
PHP
DELETE FROM users WHERE name=20
DELETE FROM users WHERE name=20;
Add semicolon.
SQL
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
[23, 29, 16
[23, 29, 16]
Close bracket.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
{{'name':'output'}}
{{"name":"output"}}
Use double quotes.
JSON
if ($result = 89) {{}}
if ($result -eq 89) {{}}
Use -eq.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
fn handle() -> i32 {{ 30 }}
fn handle() -> i32 {{ 30 }}
Correct.
Rust
var result int = 'output'
var result string = 'output'
Type mismatch.
Go
for count in range(98) print(count)
for count in range(98): print(count)
Colon after for.
Python
String result = 'result';
String result = "result";
Double quotes.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const data;
const data = 7;
Initialize const.
JavaScript
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
val x = 'world'
val x = "world"
Double quotes.
Kotlin
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'info' + 48
'info' + 48.to_s
Convert int.
Ruby
let temp: number = 'result';
let temp: string = 'result';
Fix type.
TypeScript
function handle(item:string){{return item;}} handle(3);
function handle(item:string){{return item;}} handle('info');
Pass correct type.
TypeScript