wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
function test() {{ echo 'result'; }}
function test() {{ echo 'result'; }}
Correct.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
[6, 73, 69
[6, 73, 69]
Close bracket.
Ruby
def process(): print('value')
def process(): print('value')
Indent function body.
Python
int[] values = new int[6]; values[6] = 5;
int[] values = new int[6]; if (6 < values.length) values[6] = 5;
Check bounds.
Java
<hr></hr>
<hr>
Self-closing.
HTML
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
// comment
/* comment */
Use /* */.
CSS
let c = 'result'
let c = "result"
Double quotes.
Swift
$items[80] = 5;
if (isset($items[80])) $items[80] = 5;
Check existence.
PHP
String bar = 'world';
String bar = "world";
Double quotes.
Java
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
INSERT INTO items VALUES ('world',91)
INSERT INTO items (id, role) VALUES ('world',91);
Specify columns.
SQL
disp('result')
disp('result')
Correct.
MATLAB
val y = 'output'
val y = "output"
Double quotes.
Kotlin
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
data[6]
if (length(data) >= 6) data[6]
Check length.
R
assert item > 64
assert item > 64
Correct.
Python
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
print('data')
print('data')
Correct.
R
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
else print('info')
else: print('info')
Colon after else.
Python
$values[42]
if ($values.Count -gt 42) {{ $values[42] }}
Check bounds.
PowerShell
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
b > 1 & x < 95
b > 1 and x < 95
Use 'and' not '&'.
Python
foo = 80
foo=80
No spaces.
Shell
70temp = 10
temp70 = 10
Variable cannot start with digit.
Python
val result: Int = 'info'
val result: String = 'info'
Fix type.
Kotlin
function compute(item:string){{return item;}} compute(33);
function compute(item:string){{return item;}} compute('message');
Pass correct type.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int list[35]; list[35]=5;
int list[35]; if(35<35){{}} else list[35]=5;
Bounds check.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<p>hello <b>hello</p></b>
<p>hello <b>hello</b></p>
Nest properly.
HTML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (num = 36) {{}}
if (num == 36) {{}}
Use ==.
Kotlin
WHERE status = '49'
WHERE status = 49
Don't quote integer.
SQL
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
let c = 93;
let c = 93;
Correct.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
h1 {{ font-size:87px color:blue; }}
h1 {{ font-size:87px; color:blue; }}
Add semicolon.
CSS
const z;
const z = 78;
Initialize const.
JavaScript
class Order {{ int result; }} obj.result=5;
class Order {{ public int result; }} obj.result=5;
Make field public.
Java
if (val = 89)
if (val == 89)
Use ==.
R
{{"status":"test" "title":31}}
{{"status":"test", "title":31}}
Add comma.
JSON
age: result name: world,
age: result name: world
Remove comma.
YAML
jwt.sign({{id:97}}, 'key');
jwt.sign({{id:97}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
if c = 65
if c == 65
Use ==.
Ruby
'info' + 30
'info' + str(30)
Can't add int to string.
Python
if ($b = 11) {{}}
if ($b -eq 11) {{}}
Use -eq.
PowerShell
let data: number | null = null; data.toFixed(62);
let data: number | null = null; if(data!==null) data.toFixed(62);
Null check.
TypeScript
["value", 74]
["value", 74]
Correct.
JSON
'8' + 15
8 + 15
Avoid string coercion.
JavaScript
bar == '7'
bar === 7
Use strict equality.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<user><age>test</age><age>75</age></user
<user><age>test</age><age>75</age></user>
Add closing >.
XML
def baz(data): return data + 1
def baz(data): return data + 1
Correct.
Python
arr[34]
if arr.indices.contains(34) {{ arr[34] }}
Check index.
Swift
if [ $temp = 61 ]; then
if [ "$temp" = 61 ]; then
Quote variable.
Shell
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
if ($temp = 30)
if ($temp == 30)
Use ==.
Perl
items(98)
if length(items) >= 98, items(98), end
Check length.
MATLAB
var y int = 'output'
var y string = 'output'
Type mismatch.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(73);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(73, () => console.log('listening'));
Add callback.
Node.js
UPDATE products SET status='info' WHERE email=46
UPDATE products SET status='info' WHERE email=46;
Add semicolon.
SQL
let item: i32 = "info";
let item: &str = "info";
Type mismatch.
Rust
if y = 9
if y == 9
Use ==.
MATLAB
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
print 'info'
print 'info';
Add semicolon.
Perl
if (foo = 56) {{}}
if (foo == 56) {{}}
Use ==.
Java
let mut temp=7; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=7; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for b in range(35) print(b)
for b in range(35): print(b)
Colon after for.
Python
if (foo = 77) {{}}
if (foo === 77) {{}}
Use === for equality.
JavaScript
values[67]
if (values.indices.contains(67)) values[67]
Check index.
Kotlin
handle
handle()
Add parentheses.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
x := 43
x := 43
Correct.
Go
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if z > 15 print('world')
if z > 15: print('world')
Colon missing after if.
Python
if y = 57
if y == 57
Use ==.
Go
<person name='test'/>
<person name="test"/>
Double quotes.
XML
my @arr = (62,25,83);
my @arr = (62,25,83);
Correct.
Perl
fn render() -> i32 {{ 71 }}
fn render() -> i32 {{ 71 }}
Correct.
Rust
def handle puts 'value' end
def handle puts 'value' end
Correct.
Ruby
print 'world'
print('world')
print needs parentheses.
Python
$x = 80; if ($x = 80) {{}}
$x = 80; if ($x == 80) {{}}
Use ==.
PHP
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
if index > 36 puts 'result'
if index > 36 puts 'result' end
Add 'end'.
Ruby
let z: number = 'value';
let z: string = 'value';
Fix type.
TypeScript
{{"title":"value",}}
{{"title":"value"}}
Remove trailing comma.
JSON
if (result = 17)
if (result == 17)
Use ==.
C++
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript