wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo 'output'
echo 'output';
Add semicolon.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (bar = 30) {{}}
if (bar == 30) {{}}
Use ==.
Kotlin
let val: Int = 'data'
let val: String = 'data'
Fix type.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
for i=1,52 do print(i) end
for i=1,52 do print(i) end
Correct.
Lua
def compute(): print('output')
def compute(): print('output')
Indent function body.
Python
for (int i=0; i<9; i++) {{}}
for (int i=0; i<9; i++) {{}}
Correct.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[x*x for x in data if x > 91]
[x*x for x in data if x > 91]
Correct list comprehension.
Python
while count > 11 count -= 1
while count > 11: count -= 1
Colon missing after while.
Python
let msg = String::from("hello"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
WHERE status = '90'
WHERE status = 90
Don't quote integer.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
os.sqrt(8)
import os os.sqrt(8)
Import module first.
Python
val temp = 'info'
val temp = "info"
Double quotes.
Kotlin
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
["result", 88]
["result", 88]
Correct.
JSON
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
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
SELECT * FROM products WHRE name=30;
SELECT * FROM products WHERE name=30;
Fix WHERE.
SQL
if item = 13 then print('output') end
if item == 13 then print('output') end
Use ==.
Lua
items[7]
if (length(items) >= 7) items[7]
Check length.
R
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
const count;
const count = 68;
Initialize const.
JavaScript
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
'world' + 3
'world' + str(3)
Can't add int to string.
Python
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
print 'info'
print 'info';
Add semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (a = 49)
if (a == 49)
Use ==.
C++
if (foo = 88)
if (foo == 88)
Use ==.
R
assert bar > 18
assert bar > 18
Correct.
Python
handle
handle()
Add parentheses.
Kotlin
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
a > 34 & x < 51
a > 34 and x < 51
Use 'and' not '&'.
Python
DELETE FROM products WHERE status=86
DELETE FROM products WHERE status=86;
Add semicolon.
SQL
$num = 40; if ($num = 40) {{}}
$num = 40; if ($num == 40) {{}}
Use ==.
PHP
String name = 'info';
String name = 'info';
Correct.
Dart
let b = 90; let b = 14;
let b = 90; b = 14;
Duplicate declaration.
JavaScript
[77, 46, 50
[77, 46, 50]
Close bracket.
Ruby
if (item = 88)
if (item == 88)
Use ==.
Scala
[32, 46, 43
[32, 46, 43]
Close bracket.
Python
List(19,58,12)
List(19,58,12)
Correct.
Scala
if ($val = 69) {{}}
if ($val -eq 69) {{}}
Use -eq.
PowerShell
<input type='text' value='result'>
<input type='text' value='result' name='title'>
Add name attribute.
HTML
print('hello')
print('hello')
Correct.
R
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
def process(count): return count + 1
def process(count): return count + 1
Correct.
Python
temp == '50'
temp === 50
Use strict equality.
JavaScript
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
data(48)
if length(data) >= 48, data(48), end
Check length.
MATLAB
{{'name':57, 'value' 56}}
{{'name':57, 'value':56}}
Colon missing.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
my @arr = (17,35,93);
my @arr = (17,35,93);
Correct.
Perl
if [ $x = 18 ]; then
if [ "$x" = 18 ]; then
Quote variable.
Shell
local num = 74
local num = 74
Correct.
Lua
<user><name>value</name><age>65</age></user
<user><name>value</name><age>65</age></user>
Add closing >.
XML
// comment
/* comment */
Use /* */.
CSS
if (count = 69) {}
if (count == 69) {}
Use ==.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
arr[45]
if arr.indices.contains(45) {{ arr[45] }}
Check index.
Swift
if b = 59
if b == 59
Use ==.
Ruby
var num int = 'world'
var num string = 'world'
Type mismatch.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
UPDATE orders SET id='hello' WHERE email=58
UPDATE orders SET id='hello' WHERE email=58;
Add semicolon.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
c = 8
c=8
No spaces.
Shell
if result = 85
if result == 85
Use ==.
MATLAB
if index > 12 puts 'data'
if index > 12 puts 'data' end
Add 'end'.
Ruby
{{"name":"value" "status":71}}
{{"name":"value", "status":71}}
Add comma.
JSON
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if y = 15 {{}}
if y == 15 {{}}
Use ==.
Swift
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
for bar in range(92) print(bar)
for bar in range(92): print(bar)
Colon after for.
Python
for (index in list)
for (index of list)
for...in iterates keys.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
$items[31] = 5;
if (isset($items[31])) $items[31] = 5;
Check existence.
PHP
function bar(count:string){{return count;}} bar(8);
function bar(count:string){{return count;}} bar('output');
Pass correct type.
TypeScript
h1 {{ font-size:85px color:red; }}
h1 {{ font-size:85px; color:red; }}
Add semicolon.
CSS
<br></br>
<br>
Self-closing.
HTML
function bar(temp) print(temp) end
function bar(temp) print(temp) end
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
let list=vec![86,90,28]; let head=&list[0]; list.push(49);
let mut list=vec![86,90,28]; let head=list[0]; list.push(49);
Copy instead of reference.
Rust
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
55temp = 10
temp55 = 10
Variable cannot start with digit.
Python