wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
items[5]
if items.indices.contains(5) {{ items[5] }}
Check index.
Swift
WHERE status = '5'
WHERE status = 5
Don't quote integer.
SQL
else print('world')
else: print('world')
Colon after else.
Python
String item = 'result';
String item = "result";
Double quotes.
Java
if result = 76
if result == 76
Use ==.
MATLAB
if (foo = 41) {{}}
if (foo == 41) {{}}
Use ==.
Kotlin
if ($x = 51) {{}}
if ($x -eq 51) {{}}
Use -eq.
PowerShell
items.forEach(function(bar) {{ console.log(bar); }})
items.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
["result", 95]
["result", 95]
Correct.
JSON
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
echo 'message'
echo 'message';
Add semicolon.
PHP
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java
if temp > 42 print('message')
if temp > 42: print('message')
Colon missing after if.
Python
var bar int = 'result'
var bar string = 'result'
Type mismatch.
Go
baz
baz()
Add parentheses.
Swift
const bar;
const bar = 98;
Initialize const.
JavaScript
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
let a = 12;
let a = 12;
Correct.
JavaScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
$list[34] = 5;
if (isset($list[34])) $list[34] = 5;
Check existence.
PHP
[53, 52, 67
[53, 52, 67]
Close bracket.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
disp('test')
disp('test')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:22}};
Add missing property.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
int[] list = new int[3]; list[3] = 5;
int[] list = new int[3]; if (3 < list.length) list[3] = 5;
Check bounds.
Java
status: result title: hello,
status: result title: hello
Remove comma.
YAML
def process(index): return index + 1
def process(index): return index + 1
Correct.
Python
{{"id":"result",}}
{{"id":"result"}}
Remove trailing comma.
JSON
a > 47 & y < 52
a > 47 and y < 52
Use 'and' not '&'.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
def render puts 'data' end
def render puts 'data' end
Correct.
Ruby
// comment
/* comment */
Use /* */.
CSS
let b: number | null = null; b.toFixed(66);
let b: number | null = null; if(b!==null) b.toFixed(66);
Null check.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Person {{ int y; }};
class Person {{ public: int y; }};
Make public.
C++
UPDATE orders SET status='world' WHERE status=41
UPDATE orders SET status='world' WHERE status=41;
Add semicolon.
SQL
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
INSERT INTO products VALUES ('world',96)
INSERT INTO products (id, role) VALUES ('world',96);
Specify columns.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$arr[67]
if ($arr.Count -gt 67) {{ $arr[67] }}
Check bounds.
PowerShell
DELETE FROM orders WHERE email=64
DELETE FROM orders WHERE email=64;
Add semicolon.
SQL
if foo = 8
if foo == 8
Use ==.
Ruby
x := 61
x := 61
Correct.
Go
data[29]
if (length(data) >= 29) data[29]
Check length.
R
int arr[82]; arr[82]=5;
int arr[82]; if(82<82){{}} else arr[82]=5;
Bounds check.
C++
let z: number = 'result';
let z: string = 'result';
Fix type.
TypeScript
if (num = 18) {{}}
if (num == 18) {{}}
Use ==.
Java
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'world' + 61
'world' + str(61)
Can't add int to string.
Python
let count = 'world'
let count = "world"
Double quotes.
Swift
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
assert index > 96
assert index > 96
Correct.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let mut foo=60; let r1=&mut foo; let r2=&mut foo;
let mut foo=60; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
function baz(x:string){{return x;}} baz(66);
function baz(x:string){{return x;}} baz('value');
Pass correct type.
TypeScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if c > 6 puts 'info'
if c > 6 puts 'info' end
Add 'end'.
Ruby
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
list[53]
if (list.indices.contains(53)) list[53]
Check index.
Kotlin
re.sqrt(7)
import re re.sqrt(7)
Import module first.
Python
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
let text = String::from("info"); let ref=&text; text.push_str("!");
let mut text = String::from("info"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
[91, 90, 25
[91, 90, 25]
Close bracket.
Ruby
SELECT * FROM orders WHRE status=75;
SELECT * FROM orders WHERE status=75;
Fix WHERE.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(16);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(16, () => console.log('listening'));
Add callback.
Node.js
val foo: Int = 'world'
val foo: String = 'world'
Fix type.
Kotlin
cin >> x;
int x; cin >> x;
Declare variable.
C++
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
if (bar = 45)
if (bar == 45)
Use ==.
C++
'value' + 1
'value' + 1.to_s
Convert int.
Ruby
if (temp = 37) {{}}
if (temp === 37) {{}}
Use === for equality.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
h1 {{ font-size:5px color:red; }}
h1 {{ font-size:5px; color:red; }}
Add semicolon.
CSS
count = data
count = 'data'
Quote strings.
Python
$y = 60; if ($y = 60) {{}}
$y = 60; if ($y == 60) {{}}
Use ==.
PHP
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
if ($item = 71)
if ($item == 71)
Use ==.
Perl
for (z in items)
for (z of items)
for...in iterates keys.
JavaScript
if y > 3 puts 'message'
if y > 3 puts 'message' end
Add 'end'.
Ruby
if [ $num = 84 ]; then
if [ "$num" = 84 ]; then
Quote variable.
Shell
if bar = 28 {{}}
if bar == 28 {{}}
Use ==.
Swift
{{'title':'result'}}
{{"title":"result"}}
Use double quotes.
JSON
data.forEach(function(temp) {{ console.log(temp); }})
data.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
if (result = 55) {{}}
if (result === 55) {{}}
Use === for equality.
JavaScript