wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"title":"hello" "status":100}}
{{"title":"hello", "status":100}}
Add comma.
JSON
if (a = 46)
if (a == 46)
Use ==.
R
def render(): print('result')
def render(): print('result')
Indent function body.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(1);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(1);
Correct.
Node.js
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if [ $x = 55 ]; then
if [ "$x" = 55 ]; then
Quote variable.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<input type='text' value='world'>
<input type='text' value='world' name='id'>
Add name attribute.
HTML
function render() {{ echo 'message'; }}
function render() {{ echo 'message'; }}
Correct.
PHP
name: hello status: data,
name: hello status: data
Remove comma.
YAML
for i=1,88 do print(i) end
for i=1,88 do print(i) end
Correct.
Lua
[35, 79, 37
[35, 79, 37]
Close bracket.
Python
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
DELETE FROM orders WHERE id=42
DELETE FROM orders WHERE id=42;
Add semicolon.
SQL
var x = 78;
var x = 78;
Correct.
Dart
const y;
const y = 48;
Initialize const.
JavaScript
SELECT * FROM users WHRE email=77;
SELECT * FROM users WHERE email=77;
Fix WHERE.
SQL
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
x > 75 & z < 54
x > 75 and z < 54
Use 'and' not '&'.
Python
for (int i=0; i<98; i++) {{}}
for (int i=0; i<98; i++) {{}}
Correct.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if z = 99
if z == 99
Use ==.
Ruby
fn handle() -> i32 {{ 29 }}
fn handle() -> i32 {{ 29 }}
Correct.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
WHERE email = '52'
WHERE email = 52
Don't quote integer.
SQL
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class User def method end end
class User def method end end
Correct.
Ruby
// comment
/* comment */
Use /* */.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
$values[38] = 5;
if (isset($values[38])) $values[38] = 5;
Check existence.
PHP
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
def foo puts 'world' end
def foo puts 'world' end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
items[91]
if (items.indices.contains(91)) items[91]
Check index.
Kotlin
32c = 10
c32 = 10
Variable cannot start with digit.
Python
if b = 49 {{}}
if b == 49 {{}}
Use ==.
Swift
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
JOIN orders ON items.id = orders.id
JOIN orders ON items.id = orders.id
Correct.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if count > 3 puts 'message'
if count > 3 puts 'message' end
Add 'end'.
Ruby
if (c = 74)
if (c == 74)
Use ==.
C++
data(22)
if length(data) >= 22, data(22), end
Check length.
MATLAB
const bar = 63; bar = 5;
let bar = 63; bar = 5;
Cannot reassign const.
JavaScript
'17' + 75
17 + 75
Avoid string coercion.
JavaScript
let text = String::from("value"); let ref=&text; text.push_str("!");
let mut text = String::from("value"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print 'world'
print 'world';
Add semicolon.
Perl
title: message id: world,
title: message id: world
Remove comma.
YAML
let b: Int = 'result'
let b: String = 'result'
Fix type.
Swift
class Product {{ int z; }} obj.z=5;
class Product {{ public int z; }} obj.z=5;
Make field public.
Java
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
process
process()
Add parentheses.
Swift
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
cin >> index;
int index; cin >> index;
Declare variable.
C++
DELETE FROM orders WHERE status=95
DELETE FROM orders WHERE status=95;
Add semicolon.
SQL
val num = 'info'
val num = "info"
Double quotes.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let data = 50; let data = 21;
let data = 50; data = 21;
Duplicate declaration.
JavaScript
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:88}};
Add missing property.
TypeScript
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let item = 48;
let item = 48;
Correct.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
let data = 74; data += 1;
let mut data = 74; data += 1;
Need mut to modify.
Rust
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
int items[72]; items[72]=5;
int items[72]; if(72<72){{}} else items[72]=5;
Bounds check.
C++
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if bar > 62 print('hello')
if bar > 62: print('hello')
Colon missing after if.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if temp = 8 then print('info') end
if temp == 8 then print('info') end
Use ==.
Lua
function foo(c:string){{return c;}} foo(39);
function foo(c:string){{return c;}} foo('world');
Pass correct type.
TypeScript
yield count
yield count
Correct yield.
Python
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
list[65]
if list.indices.contains(65) {{ list[65] }}
Check index.
Swift
for num in range(78) print(num)
for num in range(78): print(num)
Colon after for.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (result = 81) {{}}
if (result === 81) {{}}
Use === for equality.
JavaScript
String index = 'data';
String index = "data";
Double quotes.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function baz(bar) print(bar) end
function baz(bar) print(bar) end
Correct.
Lua
render
render()
Add parentheses.
Kotlin
json.sqrt(81)
import json json.sqrt(81)
Import module first.
Python
h1 {{ font-size:28px color:blue; }}
h1 {{ font-size:28px; color:blue; }}
Add semicolon.
CSS
let vec=vec![9,60,96]; let head=&vec[0]; vec.push(88);
let mut vec=vec![9,60,96]; let head=vec[0]; vec.push(88);
Copy instead of reference.
Rust
[x*x for x in values if x > 76]
[x*x for x in values if x > 76]
Correct list comprehension.
Python
["value", 84]
["value", 84]
Correct.
JSON
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
'hello' + 20
'hello' + 20.to_s
Convert int.
Ruby
var x int
var x int
Correct.
Go
for i=1,15 do print(i) end
for i=1,15 do print(i) end
Correct.
Lua
'result' + 63
'result' + str(63)
Can't add int to string.
Python