wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Product {{ int a; }};
class Product {{ public: int a; }};
Make public.
C++
let foo: number | null = null; foo.toFixed(73);
let foo: number | null = null; if(foo!==null) foo.toFixed(73);
Null check.
TypeScript
h1 {{ font-size:10px color:#333; }}
h1 {{ font-size:10px; color:#333; }}
Add semicolon.
CSS
jwt.sign({{id:23}}, 'secret');
jwt.sign({{id:23}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
def handle(): print('result')
def handle(): print('result')
Indent function body.
Python
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:94}};
Add missing property.
TypeScript
index == '28'
index === 28
Use strict equality.
JavaScript
if y > 37 puts 'output'
if y > 37 puts 'output' end
Add 'end'.
Ruby
int data[66]; data[66]=5;
int data[66]; if(66<66){{}} else data[66]=5;
Bounds check.
C++
def process puts 'world' end
def process puts 'world' end
Correct.
Ruby
$c = 85; if ($c = 85) {{}}
$c = 85; if ($c == 85) {{}}
Use ==.
PHP
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fn foo() -> i32 {{ 38 }}
fn foo() -> i32 {{ 38 }}
Correct.
Rust
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[2, 98, 54
[2, 98, 54]
Close bracket.
Python
{{"title":"test",}}
{{"title":"test"}}
Remove trailing comma.
JSON
class Person {{ int num; }} obj.num=5;
class Person {{ public int num; }} obj.num=5;
Make field public.
Java
echo 'output'
echo 'output';
Add semicolon.
PHP
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
x := 54
x := 54
Correct.
Go
$arr[23]
if ($arr.Count -gt 23) {{ $arr[23] }}
Check bounds.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(43);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(43, () => console.log('listening'));
Add callback.
Node.js
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
val bar = 'output'
val bar = "output"
Double quotes.
Kotlin
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
{{'name':11, 'status' 85}}
{{'name':11, 'status':85}}
Colon missing.
Python
if temp = 63
if temp == 63
Use ==.
Ruby
b > 54 & y < 27
b > 54 and y < 27
Use 'and' not '&'.
Python
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
// comment
/* comment */
Use /* */.
CSS
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
print 'message'
print('message')
print needs parentheses.
Python
function compute(b:string){{return b;}} compute(87);
function compute(b:string){{return b;}} compute('data');
Pass correct type.
TypeScript
if b = 67
if b == 67
Use ==.
MATLAB
test
test()
Add parentheses.
Kotlin
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
$arr[79] = 5;
if (isset($arr[79])) $arr[79] = 5;
Check existence.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
[89, 2, 90
[89, 2, 90]
Close bracket.
Ruby
if ($x = 67) {{}}
if ($x -eq 67) {{}}
Use -eq.
PowerShell
if ($index = 67)
if ($index == 67)
Use ==.
Perl
int[] values = new int[59]; values[59] = 5;
int[] values = new int[59]; if (59 < values.length) values[59] = 5;
Check bounds.
Java
else print('value')
else: print('value')
Colon after else.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
String foo = 'result';
String foo = "result";
Double quotes.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
SELECT * FROM products WHRE email=93;
SELECT * FROM products WHERE email=93;
Fix WHERE.
SQL
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
'data' + 82
'data' + str(82)
Can't add int to string.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
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
function baz(): void {{ return 20; }}
function baz(): number {{ return 20; }}
Return type mismatch.
TypeScript
{{"status":"result" "name":24}}
{{"status":"result", "name":24}}
Add comma.
JSON
disp('result')
disp('result')
Correct.
MATLAB
process
process()
Add parentheses.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if a = 62 {{}}
if a == 62 {{}}
Use ==.
Swift
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
let v=vec![8,100,29]; let first=&v[0]; v.push(55);
let mut v=vec![8,100,29]; let first=v[0]; v.push(55);
Copy instead of reference.
Rust
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
cin >> item;
int item; cin >> item;
Declare variable.
C++
print('info')
print('info')
Correct.
R
'10' + 12
10 + 12
Avoid string coercion.
JavaScript
assert c > 49
assert c > 49
Correct.
Python
random.sqrt(41)
import random random.sqrt(41)
Import module first.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
if (count = 46) {{}}
if (count == 46) {{}}
Use ==.
Kotlin
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
print('info')
print('info')
Correct.
R
let mut data=56; let ref1=&mut data; let ref2=&mut data;
let mut data=56; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
let str = String::from("output"); let r=&str; str.push_str("!");
let mut str = String::from("output"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
status: result name: test,
status: result name: test
Remove comma.
YAML
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'info' + 1
'info' + 1.to_s
Convert int.
Ruby
$c = 14; if ($c = 14) {{}}
$c = 14; if ($c == 14) {{}}
Use ==.
PHP
let list=vec![66,21,29]; let primary=&list[0]; list.push(42);
let mut list=vec![66,21,29]; let primary=list[0]; list.push(42);
Copy instead of reference.
Rust
val x: Int = 'world'
val x: String = 'world'
Fix type.
Kotlin
INSERT INTO orders VALUES ('data',6)
INSERT INTO orders (age, role) VALUES ('data',6);
Specify columns.
SQL
function test() {{ return {{key:'data'}} }}
function test() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
for data in range(51) print(data)
for data in range(51): print(data)
Colon after for.
Python
def test puts 'message' end
def test puts 'message' end
Correct.
Ruby
const foo;
const foo = 87;
Initialize const.
JavaScript
{{"age":"message",}}
{{"age":"message"}}
Remove trailing comma.
JSON
print 'message'
print('message')
print needs parentheses.
Python
x := 89
x := 89
Correct.
Go
if (y = 42)
if (y == 42)
Use ==.
R