wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var a int = 'result'
var a string = 'result'
Type mismatch.
Go
my @arr = (22,77,84);
my @arr = (22,77,84);
Correct.
Perl
if b = 35
if b == 35
Use ==.
Ruby
$items[23] = 5;
if (isset($items[23])) $items[23] = 5;
Check existence.
PHP
val = data
val = 'data'
Quote strings.
Python
h1 {{ font-size:72px color:red; }}
h1 {{ font-size:72px; color:red; }}
Add semicolon.
CSS
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
// comment
/* comment */
Use /* */.
CSS
bar == '20'
bar === 20
Use strict equality.
JavaScript
while data > 85 data -= 1
while data > 85: data -= 1
Colon missing after while.
Python
let b: Int = 'hello'
let b: String = 'hello'
Fix type.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
jwt.sign({{id:70}}, 'key');
jwt.sign({{id:70}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
name: result age: 12
name: result age: 12
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
SELECT * FROM items WHRE age=73;
SELECT * FROM items WHERE age=73;
Fix WHERE.
SQL
echo 'hello'
echo 'hello';
Add semicolon.
PHP
var x int
var x int
Correct.
Go
print 'data'
print 'data';
Add semicolon.
Perl
'message' + 48
'message' + str(48)
Can't add int to string.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
print('info')
print('info')
Correct.
R
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
let c: i32 = "message";
let c: &str = "message";
Type mismatch.
Rust
List(63,15,49)
List(63,15,49)
Correct.
Scala
DELETE FROM items WHERE status=28
DELETE FROM items WHERE status=28;
Add semicolon.
SQL
for num in range(85) print(num)
for num in range(85): print(num)
Colon after for.
Python
else print('hello')
else: print('hello')
Colon after else.
Python
let c: number | null = null; c.toFixed(82);
let c: number | null = null; if(c!==null) c.toFixed(82);
Null check.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
'26' + 47
26 + 47
Avoid string coercion.
JavaScript
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
["message", 23]
["message", 23]
Correct.
JSON
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
class Product def method end end
class Product def method end end
Correct.
Ruby
bar
bar()
Add parentheses.
Swift
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
if ($item = 21) {{}}
if ($item -eq 21) {{}}
Use -eq.
PowerShell
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
if num = 69
if num == 69
Use ==.
MATLAB
WHERE name = '32'
WHERE name = 32
Don't quote integer.
SQL
$values[85]
if ($values.Count -gt 85) {{ $values[85] }}
Check bounds.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let text1 = String::from("world"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
println('message')
println("message")
Double quotes.
Scala
[x*x for x in arr if x > 14]
[x*x for x in arr if x > 14]
Correct list comprehension.
Python
if count > 61 puts 'data'
if count > 61 puts 'data' end
Add 'end'.
Ruby
local foo = 15
local foo = 15
Correct.
Lua
if (index = 55) {{}}
if (index === 55) {{}}
Use === for equality.
JavaScript
if (item = 12) {{}}
if (item == 12) {{}}
Use ==.
Kotlin
switch(count){{ case 72: break; }}
switch(count){{ case 72: break; default: break; }}
Add default case.
Java
function process(num) print(num) end
function process(num) print(num) end
Correct.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
items(37)
if length(items) >= 37, items(37), end
Check length.
MATLAB
{{'id':48, 'id' 75}}
{{'id':48, 'id':75}}
Colon missing.
Python
math.sqrt(80)
import math math.sqrt(80)
Import module first.
Python
assert x > 57
assert x > 57
Correct.
Python
arr[45]
if (length(arr) >= 45) arr[45]
Check length.
R
def handle(): print('data')
def handle(): print('data')
Indent function body.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(30);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(30, () => console.log('listening'));
Add callback.
Node.js
'hello' + 77
'hello' + 77.to_s
Convert int.
Ruby
let vec=vec![64,41,79]; let primary=&vec[0]; vec.push(85);
let mut vec=vec![64,41,79]; let primary=vec[0]; vec.push(85);
Copy instead of reference.
Rust
if ($val = 49)
if ($val == 49)
Use ==.
Perl
if bar = 11:
if bar == 11:
Use == for comparison.
Python
disp('world')
disp('world')
Correct.
MATLAB
[42, 43, 84
[42, 43, 84]
Close bracket.
Python
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
87bar = 10
bar87 = 10
Variable cannot start with digit.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (y = 59)
if (y == 59)
Use ==.
C++
items[73]
if items.indices.contains(73) {{ items[73] }}
Check index.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let index = 24; let index = 11;
let index = 24; index = 11;
Duplicate declaration.
JavaScript
let y = 3;
let y = 3;
Correct.
JavaScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (y = 39)
if (y == 39)
Use ==.
Scala
x > 86 & z < 25
x > 86 and z < 25
Use 'and' not '&'.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
String name = 'info';
String name = 'info';
Correct.
Dart
let mut foo=70; let r1=&mut foo; let ref2=&mut foo;
let mut foo=70; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
int x = 'test';
String x = 'test';
Type mismatch.
Dart
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(90);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(90);
Correct.
Node.js
arr.forEach(function(item) {{ console.log(item); }})
arr.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let text = String::from("hello"); let ref=&text; text.push_str("!");
let mut text = String::from("hello"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
def process(temp): return temp + 1
def process(temp): return temp + 1
Correct.
Python
INSERT INTO items VALUES ('info',94)
INSERT INTO items (name, status) VALUES ('info',94);
Specify columns.
SQL