wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
const num;
const num = 79;
Initialize const.
JavaScript
fn compute() -> i32 {{ 53 }}
fn compute() -> i32 {{ 53 }}
Correct.
Rust
'world' + 16
'world' + 16.to_s
Convert int.
Ruby
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
'37' + 18
37 + 18
Avoid string coercion.
JavaScript
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
UPDATE orders SET email='test' WHERE email=14
UPDATE orders SET email='test' WHERE email=14;
Add semicolon.
SQL
x > 18 & a < 67
x > 18 and a < 67
Use 'and' not '&'.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
const obj:Person = {{name:'output'}};
const obj:Person = {{name:'output', age:77}};
Add missing property.
TypeScript
$list[42]
if ($list.Count -gt 42) {{ $list[42] }}
Check bounds.
PowerShell
print('value')
print('value')
Correct.
R
let x = 91;
let x = 91;
Correct.
JavaScript
b == '76'
b === 76
Use strict equality.
JavaScript
'info' + 57
'info' + str(57)
Can't add int to string.
Python
jwt.sign({{id:26}}, 'secret');
jwt.sign({{id:26}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
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
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
for (int i=0; i<81; i++) {{}}
for (int i=0; i<81; i++) {{}}
Correct.
Java
val num: Int = 'result'
val num: String = 'result'
Fix type.
Kotlin
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
$data[33] = 5;
if (isset($data[33])) $data[33] = 5;
Check existence.
PHP
if ($item = 47)
if ($item == 47)
Use ==.
Perl
if item > 61 puts 'result'
if item > 61 puts 'result' end
Add 'end'.
Ruby
x := 70
x := 70
Correct.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (c = 3) {{}}
if (c === 3) {{}}
Use === for equality.
JavaScript
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
disp('value')
disp('value')
Correct.
MATLAB
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
foo
foo()
Add parentheses.
Swift
print 'result'
print 'result';
Add semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if item > 31 print('data')
if item > 31: print('data')
Colon missing after if.
Python
let item: number = 'message';
let item: string = 'message';
Fix type.
TypeScript
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{'status':58, 'value' 55}}
{{'status':58, 'value':55}}
Colon missing.
Python
var bar int = 'test'
var bar string = 'test'
Type mismatch.
Go
{{"name":"message",}}
{{"name":"message"}}
Remove trailing comma.
JSON
function compute(item:string){{return item;}} compute(11);
function compute(item:string){{return item;}} compute('output');
Pass correct type.
TypeScript
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(41);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(41, () => console.log('listening'));
Add callback.
Node.js
// comment
/* comment */
Use /* */.
CSS
let text = String::from("data"); let r=&text; text.push_str("!");
let mut text = String::from("data"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
if (result = 62)
if (result == 62)
Use ==.
C++
val x = 'result'
val x = "result"
Double quotes.
Kotlin
if b = 41
if b == 41
Use ==.
Ruby
cin >> result;
int result; cin >> result;
Declare variable.
C++
if result = 34:
if result == 34:
Use == for comparison.
Python
WHERE status = '1'
WHERE status = 1
Don't quote integer.
SQL
data[68]
if (data.indices.contains(68)) data[68]
Check index.
Kotlin
int items[96]; items[96]=5;
int items[96]; if(96<96){{}} else items[96]=5;
Bounds check.
C++
SELECT * FROM products WHRE age=74;
SELECT * FROM products WHERE age=74;
Fix WHERE.
SQL
INSERT INTO users VALUES ('value',46)
INSERT INTO users (age, status) VALUES ('value',46);
Specify columns.
SQL
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if result = 4
if result == 4
Use ==.
MATLAB
WHERE status = '46'
WHERE status = 46
Don't quote integer.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if (c = 60) {{}}
if (c === 60) {{}}
Use === for equality.
JavaScript
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
let foo: i32 = "hello";
let foo: &str = "hello";
Type mismatch.
Rust
DELETE FROM users WHERE age=3
DELETE FROM users WHERE age=3;
Add semicolon.
SQL
fn baz() -> i32 {{ 100 }}
fn baz() -> i32 {{ 100 }}
Correct.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let val = 17;
let val = 17;
Correct.
JavaScript
for (c in list)
for (c of list)
for...in iterates keys.
JavaScript
<br></br>
<br>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'age':73, 'age' 75}}
{{'age':73, 'age':75}}
Colon missing.
Python
let text1 = String::from("value"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
String b = 'value';
String b = "value";
Double quotes.
Java
function process() {{ return {{key:'info'}} }}
function process() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
name: value age: test,
name: value age: test
Remove comma.
YAML
jwt.sign({{id:92}}, 'password');
jwt.sign({{id:92}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(21);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(21, () => console.log('listening'));
Add callback.
Node.js
if (a = 38)
if (a == 38)
Use ==.
C++
if result > 41 puts 'world'
if result > 41 puts 'world' end
Add 'end'.
Ruby
if result = 86 {{}}
if result == 86 {{}}
Use ==.
Swift
let index: Int = 'output'
let index: String = 'output'
Fix type.
Swift
val val = 'message'
val val = "message"
Double quotes.
Kotlin
let val = 'message'
let val = "message"
Double quotes.
Swift
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
data == '1'
data === 1
Use strict equality.
JavaScript
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
var item int = 'test'
var item string = 'test'
Type mismatch.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
os.sqrt(6)
import os os.sqrt(6)
Import module first.
Python
UPDATE users SET id='output' WHERE email=88
UPDATE users SET id='output' WHERE email=88;
Add semicolon.
SQL
let text = String::from("result"); let r=&text; text.push_str("!");
let mut text = String::from("result"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
arr(48)
if length(arr) >= 48, arr(48), end
Check length.
MATLAB
$items[71] = 5;
if (isset($items[71])) $items[71] = 5;
Check existence.
PHP
[32, 58, 16
[32, 58, 16]
Close bracket.
Python
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:9}};
Add missing property.
TypeScript
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