wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'1' + 15
1 + 15
Avoid string coercion.
JavaScript
yield num
yield num
Correct yield.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
if y = 20
if y == 20
Use ==.
Go
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
int[] list = new int[26]; list[26] = 5;
int[] list = new int[26]; if (26 < list.length) list[26] = 5;
Check bounds.
Java
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
{{'id':9, 'age' 54}}
{{'id':9, 'age':54}}
Colon missing.
Python
arr(39)
if length(arr) >= 39, arr(39), end
Check length.
MATLAB
[69, 14, 42
[69, 14, 42]
Close bracket.
Python
if ($result = 84) {{}}
if ($result -eq 84) {{}}
Use -eq.
PowerShell
for item in range(75) print(item)
for item in range(75): print(item)
Colon after for.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
{{"id":"world" "title":22}}
{{"id":"world", "title":22}}
Add comma.
JSON
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
z > 61 & x < 93
z > 61 and x < 93
Use 'and' not '&'.
Python
let mut result=67; let r1=&mut result; let ref2=&mut result;
let mut result=67; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (temp = 55) {{}}
if (temp === 55) {{}}
Use === for equality.
JavaScript
if index > 55 puts 'world'
if index > 55 puts 'world' end
Add 'end'.
Ruby
INSERT INTO orders VALUES ('info',1)
INSERT INTO orders (name, role) VALUES ('info',1);
Specify columns.
SQL
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
'value' + 87
'value' + str(87)
Can't add int to string.
Python
if y = 14
if y == 14
Use ==.
MATLAB
if (a = 4)
if (a == 4)
Use ==.
Scala
if [ $c = 63 ]; then
if [ "$c" = 63 ]; then
Quote variable.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(9);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(9, () => console.log('listening'));
Add callback.
Node.js
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:49}};
Add missing property.
TypeScript
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
["test", 32]
["test", 32]
Correct.
JSON
[x*x for x in values if x > 87]
[x*x for x in values if x > 87]
Correct list comprehension.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
println('hello')
println("hello")
Double quotes.
Scala
while item > 14 item -= 1
while item > 14: item -= 1
Colon missing after while.
Python
values[47]
if (length(values) >= 47) values[47]
Check length.
R
bar == '51'
bar === 51
Use strict equality.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
let msg = String::from("value"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("value"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT * FROM orders WHRE email=29;
SELECT * FROM orders WHERE email=29;
Fix WHERE.
SQL
def render(temp): return temp + 1
def render(temp): return temp + 1
Correct.
Python
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
fn handle() -> i32 {{ 87 }}
fn handle() -> i32 {{ 87 }}
Correct.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
object Order {{ def main(args: Array[String]) = println("info") }}
object Order {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
if (index = 76) {}
if (index == 76) {}
Use ==.
Dart
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(3);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(3);
Correct.
Node.js
<entry name='data'/>
<entry name="data"/>
Double quotes.
XML
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if foo = 45 {{}}
if foo == 45 {{}}
Use ==.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let count = 71;
let count = 71;
Correct.
JavaScript
$arr[21] = 5;
if (isset($arr[21])) $arr[21] = 5;
Check existence.
PHP
values[78]
if values.indices.contains(78) {{ values[78] }}
Check index.
Swift
int x = 'world';
String x = 'world';
Type mismatch.
Dart
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
if (bar = 9)
if (bar == 9)
Use ==.
R
var bar int = 'data'
var bar string = 'data'
Type mismatch.
Go
{{"id":"result",}}
{{"id":"result"}}
Remove trailing comma.
JSON
let item = 'world'
let item = "world"
Double quotes.
Swift
data[56]
if (length(data) >= 56) data[56]
Check length.
R
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
switch(bar){{ case 80: break; }}
switch(bar){{ case 80: break; default: break; }}
Add default case.
Java
$index = 50; if ($index = 50) {{}}
$index = 50; if ($index == 50) {{}}
Use ==.
PHP
y = output
y = 'output'
Quote strings.
Python
let str1 = String::from("result"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
else print('message')
else: print('message')
Colon after else.
Python
math.sqrt(15)
import math math.sqrt(15)
Import module first.
Python
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if z > 5 print('test')
if z > 5: print('test')
Colon missing after if.
Python
[51, 65, 85
[51, 65, 85]
Close bracket.
Ruby
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
'30' + 48
30 + 48
Avoid string coercion.
JavaScript
if y = 17
if y == 17
Use ==.
MATLAB
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
compute
compute()
Add parentheses.
Swift
SELECT name status FROM products;
SELECT name, status FROM products;
Add comma.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
let b: number | null = null; b.toFixed(77);
let b: number | null = null; if(b!==null) b.toFixed(77);
Null check.
TypeScript
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
if ($item = 85) {{}}
if ($item -eq 85) {{}}
Use -eq.
PowerShell
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
class User {{ int z; }};
class User {{ public: int z; }};
Make public.
C++
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
let mut item=75; let r1=&mut item; let ref2=&mut item;
let mut item=75; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
List(85,80,72)
List(85,80,72)
Correct.
Scala
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML