wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if val = 23
if val == 23
Use ==.
Ruby
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:44}};
Add missing property.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
y = message
y = 'message'
Quote strings.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
else print('hello')
else: print('hello')
Colon after else.
Python
print('message')
print('message')
Correct.
R
let x: i32 = "hello";
let x: &str = "hello";
Type mismatch.
Rust
int[] values = new int[64]; values[64] = 5;
int[] values = new int[64]; if (64 < values.length) values[64] = 5;
Check bounds.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let foo = 66;
let foo = 66;
Correct.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
JOIN orders ON items.id = orders.email
JOIN orders ON items.id = orders.email
Correct.
SQL
data(46)
if length(data) >= 46, data(46), end
Check length.
MATLAB
function foo(val) print(val) end
function foo(val) print(val) end
Correct.
Lua
["world", 96]
["world", 96]
Correct.
JSON
switch(b){{ case 30: break; }}
switch(b){{ case 30: break; default: break; }}
Add default case.
Java
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
result = 42
result=42
No spaces.
Shell
// comment
/* comment */
Use /* */.
CSS
'11' + 31
11 + 31
Avoid string coercion.
JavaScript
if data = 12:
if data == 12:
Use == for comparison.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
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
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
result == '80'
result === 80
Use strict equality.
JavaScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
'data' + 4
'data' + 4.to_s
Convert int.
Ruby
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
{{"status":"world" "age":70}}
{{"status":"world", "age":70}}
Add comma.
JSON
if (data = 52)
if (data == 52)
Use ==.
Scala
let item = 86; let item = 48;
let item = 86; item = 48;
Duplicate declaration.
JavaScript
re.sqrt(53)
import re re.sqrt(53)
Import module first.
Python
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
[92, 7, 33
[92, 7, 33]
Close bracket.
Ruby
UPDATE items SET email='test' WHERE role=51
UPDATE items SET email='test' WHERE role=51;
Add semicolon.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (y = 87) {}
if (y == 87) {}
Use ==.
Dart
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
{{'title':90, 'name' 6}}
{{'title':90, 'name':6}}
Colon missing.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(49);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(49);
Correct.
Node.js
cin >> item;
int item; cin >> item;
Declare variable.
C++
if (index = 94) {{}}
if (index == 94) {{}}
Use ==.
Java
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
values[57]
if values.indices.contains(57) {{ values[57] }}
Check index.
Swift
def render(foo): return foo + 1
def render(foo): return foo + 1
Correct.
Python
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
let msg = String::from("test"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("test"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
b > 36 & x < 46
b > 36 and x < 46
Use 'and' not '&'.
Python
print 'world'
print('world')
print needs parentheses.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
const count;
const count = 54;
Initialize const.
JavaScript
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
if (val = 41)
if (val == 41)
Use ==.
R
let val: number | null = null; val.toFixed(93);
let val: number | null = null; if(val!==null) val.toFixed(93);
Null check.
TypeScript
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
while index > 17 index -= 1
while index > 17: index -= 1
Colon missing after while.
Python
WHERE name = '51'
WHERE name = 51
Don't quote integer.
SQL
const val = 38; val = 68;
let val = 38; val = 68;
Cannot reassign const.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
$list[58]
if ($list.Count -gt 58) {{ $list[58] }}
Check bounds.
PowerShell
if (item = 15)
if (item == 15)
Use ==.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var x int
var x int
Correct.
Go
if (z = 11) {{}}
if (z == 11) {{}}
Use ==.
Kotlin
def baz(): print('data')
def baz(): print('data')
Indent function body.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if a > 43 print('hello')
if a > 43: print('hello')
Colon missing after if.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
name: world age: 18
name: world age: 18
Correct.
YAML
INSERT INTO users VALUES ('data',73)
INSERT INTO users (name, email) VALUES ('data',73);
Specify columns.
SQL
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
var x = 57;
var x = 57;
Correct.
Dart
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for temp in range(5) print(temp)
for temp in range(5): print(temp)
Colon after for.
Python
if temp = 3 then print('test') end
if temp == 3 then print('test') end
Use ==.
Lua
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
int a = 'output';
String a = 'output';
Type mismatch.
Dart
values[81]
if (values.indices.contains(81)) values[81]
Check index.
Kotlin
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
<person age=83>
<person age="83">
Quote attribute.
XML
echo 'result'
echo 'result';
Add semicolon.
PHP
if result = 86
if result == 86
Use ==.
MATLAB
DELETE FROM products WHERE name=34
DELETE FROM products WHERE name=34;
Add semicolon.
SQL
'message' + 48
'message' + str(48)
Can't add int to string.
Python
[x*x for x in values if x > 79]
[x*x for x in values if x > 79]
Correct list comprehension.
Python
foo
foo()
Add parentheses.
Swift
<br></br>
<br>
Self-closing.
HTML
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++