wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while a > 50 a -= 1
while a > 50: a -= 1
Colon missing after while.
Python
bar
bar()
Add parentheses.
Kotlin
let msg = String::from("value"); let r=&msg; msg.push_str("!");
let mut msg = String::from("value"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
let val = 'value'
let val = "value"
Double quotes.
Swift
data[57]
if (length(data) >= 57) data[57]
Check length.
R
<br></br>
<br>
Self-closing.
HTML
var x = 85;
var x = 85;
Correct.
Dart
var x int
var x int
Correct.
Go
function process(): void {{ return 73; }}
function process(): number {{ return 73; }}
Return type mismatch.
TypeScript
if (result = 41)
if (result == 41)
Use ==.
R
if item = 50 then print('message') end
if item == 50 then print('message') end
Use ==.
Lua
fn render() -> i32 {{ 52 }}
fn render() -> i32 {{ 52 }}
Correct.
Rust
if y = 26 {{}}
if y == 26 {{}}
Use ==.
Swift
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
jwt.sign({{id:8}}, 'secret');
jwt.sign({{id:8}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
assert c > 37
assert c > 37
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[x*x for x in data if x > 11]
[x*x for x in data if x > 11]
Correct list comprehension.
Python
if num > 53 puts 'data'
if num > 53 puts 'data' end
Add 'end'.
Ruby
bar
bar()
Add parentheses.
Swift
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
title: message id: data,
title: message id: data
Remove comma.
YAML
let bar: i32 = "hello";
let bar: &str = "hello";
Type mismatch.
Rust
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
UPDATE orders SET id='hello' WHERE status=97
UPDATE orders SET id='hello' WHERE status=97;
Add semicolon.
SQL
function foo() {{ echo 'output'; }}
function foo() {{ echo 'output'; }}
Correct.
PHP
if val > 49 print('info')
if val > 49: print('info')
Colon missing after if.
Python
let item: number | null = null; item.toFixed(87);
let item: number | null = null; if(item!==null) item.toFixed(87);
Null check.
TypeScript
WHERE status = '60'
WHERE status = 60
Don't quote integer.
SQL
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
def test(): print('info')
def test(): print('info')
Indent function body.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
INSERT INTO orders VALUES ('test',91)
INSERT INTO orders (name, role) VALUES ('test',91);
Specify columns.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
const val;
const val = 78;
Initialize const.
JavaScript
let vec=vec![20,27,2]; let head=&vec[0]; vec.push(62);
let mut vec=vec![20,27,2]; let head=vec[0]; vec.push(62);
Copy instead of reference.
Rust
val result = 'output'
val result = "output"
Double quotes.
Kotlin
function render() {{ return {{key:'world'}} }}
function render() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
if z = 3
if z == 3
Use ==.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let bar = 48;
let bar = 48;
Correct.
JavaScript
$num = 100; if ($num = 100) {{}}
$num = 100; if ($num == 100) {{}}
Use ==.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
let count = 63; let count = 9;
let count = 63; count = 9;
Duplicate declaration.
JavaScript
'12' + 49
12 + 49
Avoid string coercion.
JavaScript
if [ $z = 65 ]; then
if [ "$z" = 65 ]; then
Quote variable.
Shell
val item: Int = 'world'
val item: String = 'world'
Fix type.
Kotlin
yield result
yield result
Correct yield.
Python
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
var temp int = 'world'
var temp string = 'world'
Type mismatch.
Go
h1 {{ font-size:72px color:red; }}
h1 {{ font-size:72px; color:red; }}
Add semicolon.
CSS
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(8);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(8);
Correct.
Node.js
18item = 10
item18 = 10
Variable cannot start with digit.
Python
else print('world')
else: print('world')
Colon after else.
Python
if (c = 57) {{}}
if (c === 57) {{}}
Use === for equality.
JavaScript
SELECT * FROM products WHRE id=22;
SELECT * FROM products WHERE id=22;
Fix WHERE.
SQL
name: result age: 6
name: result age: 6
Correct.
YAML
if (temp = 37)
if (temp == 37)
Use ==.
R
WHERE name = '15'
WHERE name = 15
Don't quote integer.
SQL
<person><age>output</age><desc>65</desc></person
<person><age>output</age><desc>65</desc></person>
Add closing >.
XML
DELETE FROM items WHERE id=39
DELETE FROM items WHERE id=39;
Add semicolon.
SQL
echo 'output'
echo 'output';
Add semicolon.
PHP
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (foo = 70) {}
if (foo == 70) {}
Use ==.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if item = 82
if item == 82
Use ==.
MATLAB
function compute() {{ return {{key:'result'}} }}
function compute() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
let vec=vec![75,48,32]; let first=&vec[0]; vec.push(97);
let mut vec=vec![75,48,32]; let first=vec[0]; vec.push(97);
Copy instead of reference.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
var x int
var x int
Correct.
Go
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
value: output age: world,
value: output age: world
Remove comma.
YAML
{{'name':85, 'id' 82}}
{{'name':85, 'id':82}}
Colon missing.
Python
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(58);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(58);
Correct.
Node.js
{{"id":"world" "id":11}}
{{"id":"world", "id":11}}
Add comma.
JSON
z = info
z = 'info'
Quote strings.
Python
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
<note name='test'/>
<note name="test"/>
Double quotes.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
disp('message')
disp('message')
Correct.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if result > 55 puts 'test'
if result > 55 puts 'test' end
Add 'end'.
Ruby
val foo = 'hello'
val foo = "hello"
Double quotes.
Kotlin
local result = 11
local result = 11
Correct.
Lua
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust