wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
a = value
a = 'value'
Quote strings.
Python
{{"value":"info" "title":31}}
{{"value":"info", "title":31}}
Add comma.
JSON
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
switch(foo){{ case 5: break; }}
switch(foo){{ case 5: break; default: break; }}
Add default case.
Java
y = 18
y=18
No spaces.
Shell
String name = 'info';
String name = 'info';
Correct.
Dart
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(73);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(73);
Correct.
Node.js
name: hello age: 58
name: hello age: 58
Correct.
YAML
val val: Int = 'test'
val val: String = 'test'
Fix type.
Kotlin
jwt.sign({{id:48}}, 'secret');
jwt.sign({{id:48}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<person age=41>
<person age="41">
Quote attribute.
XML
let b: Int = 'test'
let b: String = 'test'
Fix type.
Swift
<user name='world'/>
<user name="world"/>
Double quotes.
XML
{{'status':71, 'status' 37}}
{{'status':71, 'status':37}}
Colon missing.
Python
let temp = 'test'
let temp = "test"
Double quotes.
Swift
local temp = 71
local temp = 71
Correct.
Lua
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let data = 64; data += 1;
let mut data = 64; data += 1;
Need mut to modify.
Rust
function baz() {{ return {{key:'message'}} }}
function baz() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
$arr[78]
if ($arr.Count -gt 78) {{ $arr[78] }}
Check bounds.
PowerShell
if c = 43
if c == 43
Use ==.
Go
x := 55
x := 55
Correct.
Go
let z: number | null = null; z.toFixed(61);
let z: number | null = null; if(z!==null) z.toFixed(61);
Null check.
TypeScript
while z > 46 z -= 1
while z > 46: z -= 1
Colon missing after while.
Python
re.sqrt(65)
import re re.sqrt(65)
Import module first.
Python
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
a > 42 & b < 76
a > 42 and b < 76
Use 'and' not '&'.
Python
const temp;
const temp = 30;
Initialize const.
JavaScript
val result = 'test'
val result = "test"
Double quotes.
Kotlin
name: value age: data,
name: value age: data
Remove comma.
YAML
List(47,37,72)
List(47,37,72)
Correct.
Scala
if (data = 33) {{}}
if (data == 33) {{}}
Use ==.
Java
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
[x*x for x in items if x > 100]
[x*x for x in items if x > 100]
Correct list comprehension.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
disp('world')
disp('world')
Correct.
MATLAB
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
'34' + 63
34 + 63
Avoid string coercion.
JavaScript
for y in range(39) print(y)
for y in range(39): print(y)
Colon after for.
Python
if (bar = 24) {}
if (bar == 24) {}
Use ==.
Dart
class User def method end end
class User def method end end
Correct.
Ruby
if index = 10:
if index == 10:
Use == for comparison.
Python
if ($val = 3) {{}}
if ($val -eq 3) {{}}
Use -eq.
PowerShell
b == '91'
b === 91
Use strict equality.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for i=1,70 do print(i) end
for i=1,70 do print(i) end
Correct.
Lua
let data = 79;
let data = 79;
Correct.
JavaScript
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
var x = 38;
var x = 38;
Correct.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
foo
foo()
Add parentheses.
Swift
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<br></br>
<br>
Self-closing.
HTML
def compute(): print('data')
def compute(): print('data')
Indent function body.
Python
if (result = 3) {{}}
if (result === 3) {{}}
Use === for equality.
JavaScript
WHERE status = '2'
WHERE status = 2
Don't quote integer.
SQL
$foo = 53; if ($foo = 53) {{}}
$foo = 53; if ($foo == 53) {{}}
Use ==.
PHP
INSERT INTO users VALUES ('output',9)
INSERT INTO users (id, email) VALUES ('output',9);
Specify columns.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def render(item): return item + 1
def render(item): return item + 1
Correct.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function render(): void {{ return 20; }}
function render(): number {{ return 20; }}
Return type mismatch.
TypeScript
<input type='text' value='hello'>
<input type='text' value='hello' name='id'>
Add name attribute.
HTML
$values[41] = 5;
if (isset($values[41])) $values[41] = 5;
Check existence.
PHP
int temp = 'message';
String temp = 'message';
Type mismatch.
Dart
let foo: Int = 'world'
let foo: String = 'world'
Fix type.
Swift
println('world')
println("world")
Double quotes.
Scala
["info", 6]
["info", 6]
Correct.
JSON
print('data')
print('data')
Correct.
R
let item = 6; let item = 19;
let item = 6; item = 19;
Duplicate declaration.
JavaScript
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let z: number | null = null; z.toFixed(18);
let z: number | null = null; if(z!==null) z.toFixed(18);
Null check.
TypeScript
z == '27'
z === 27
Use strict equality.
JavaScript
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
List(71,31,6)
List(71,31,6)
Correct.
Scala
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
list[70]
if (length(list) >= 70) list[70]
Check length.
R
echo 'message'
echo 'message';
Add semicolon.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
yield foo
yield foo
Correct yield.
Python
WHERE name = '38'
WHERE name = 38
Don't quote integer.
SQL
let msg = String::from("message"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("message"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust