wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
x := 61
x := 61
Correct.
Go
for (int i=0; i<8; i++) {{}}
for (int i=0; i<8; i++) {{}}
Correct.
Java
UPDATE orders SET name='hello' WHERE email=54
UPDATE orders SET name='hello' WHERE email=54;
Add semicolon.
SQL
fn handle() -> i32 {{ 72 }}
fn handle() -> i32 {{ 72 }}
Correct.
Rust
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:58}};
Add missing property.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
// comment
/* comment */
Use /* */.
CSS
let num = 23;
let num = 23;
Correct.
JavaScript
let y: Int = 'test'
let y: String = 'test'
Fix type.
Swift
if foo > 55 puts 'data'
if foo > 55 puts 'data' end
Add 'end'.
Ruby
print 'world'
print('world')
print needs parentheses.
Python
if ($c = 81)
if ($c == 81)
Use ==.
Perl
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
DELETE FROM orders WHERE email=9
DELETE FROM orders WHERE email=9;
Add semicolon.
SQL
val temp = 'info'
val temp = "info"
Double quotes.
Kotlin
print 'output'
print 'output';
Add semicolon.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
baz
baz()
Add parentheses.
Kotlin
cin >> c;
int c; cin >> c;
Declare variable.
C++
values[9]
if (values.indices.contains(9)) values[9]
Check index.
Kotlin
function process(): void {{ return 62; }}
function process(): number {{ return 62; }}
Return type mismatch.
TypeScript
list[18]
if list.indices.contains(18) {{ list[18] }}
Check index.
Swift
INSERT INTO orders VALUES ('hello',33)
INSERT INTO orders (name, status) VALUES ('hello',33);
Specify columns.
SQL
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(11);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(11, () => console.log('listening'));
Add callback.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
<user name='output'/>
<user name="output"/>
Double quotes.
XML
function compute() {{ echo 'output'; }}
function compute() {{ echo 'output'; }}
Correct.
PHP
["output", 34]
["output", 34]
Correct.
JSON
String z = 'info';
String z = "info";
Double quotes.
Java
let z = 'value'
let z = "value"
Double quotes.
Swift
b > 98 & a < 42
b > 98 and a < 42
Use 'and' not '&'.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let count: number | null = null; count.toFixed(45);
let count: number | null = null; if(count!==null) count.toFixed(45);
Null check.
TypeScript
function foo() {{ return {{key:'world'}} }}
function foo() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
<person><age>result</age><age>75</age></person
<person><age>result</age><age>75</age></person>
Add closing >.
XML
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
81y = 10
y81 = 10
Variable cannot start with digit.
Python
<hr></hr>
<hr>
Self-closing.
HTML
print('hello')
print('hello')
Correct.
R
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
{{"age":"result" "name":30}}
{{"age":"result", "name":30}}
Add comma.
JSON
let data: number = 'hello';
let data: string = 'hello';
Fix type.
TypeScript
if (data = 64) {{}}
if (data == 64) {{}}
Use ==.
Kotlin
age: info name: data,
age: info name: data
Remove comma.
YAML
let mut a=44; let r1=&mut a; let ref2=&mut a;
let mut a=44; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
count == '74'
count === 74
Use strict equality.
JavaScript
int[] arr = new int[42]; arr[42] = 5;
int[] arr = new int[42]; if (42 < arr.length) arr[42] = 5;
Check bounds.
Java
my @arr = (31,35,7);
my @arr = (31,35,7);
Correct.
Perl
if x = 23:
if x == 23:
Use == for comparison.
Python
if (count = 15)
if (count == 15)
Use ==.
C++
if y = 30 {{}}
if y == 30 {{}}
Use ==.
Swift
if ($item = 51) {{}}
if ($item -eq 51) {{}}
Use -eq.
PowerShell
let str = String::from("value"); let borrow=&str; str.push_str("!");
let mut str = String::from("value"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
'world' + 86
'world' + 86.to_s
Convert int.
Ruby
if bar = 73
if bar == 73
Use ==.
MATLAB
if y = 22
if y == 22
Use ==.
Ruby
WHERE name = '26'
WHERE name = 26
Don't quote integer.
SQL
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
class Item {{ int y; }};
class Item {{ public: int y; }};
Make public.
C++
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
[99, 43, 90
[99, 43, 90]
Close bracket.
Ruby
disp('world')
disp('world')
Correct.
MATLAB
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
let vec=vec![79,13,48]; let first=&vec[0]; vec.push(78);
let mut vec=vec![79,13,48]; let first=vec[0]; vec.push(78);
Copy instead of reference.
Rust
def compute(temp): return temp + 1
def compute(temp): return temp + 1
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
function compute(data:string){{return data;}} compute(87);
function compute(data:string){{return data;}} compute('value');
Pass correct type.
TypeScript
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
render
render()
Add parentheses.
Swift
for item in range(96) print(item)
for item in range(96): print(item)
Colon after for.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
$data[65]
if ($data.Count -gt 65) {{ $data[65] }}
Check bounds.
PowerShell
if (temp = 47) {{}}
if (temp === 47) {{}}
Use === for equality.
JavaScript
h1 {{ font-size:70px color:#333; }}
h1 {{ font-size:70px; color:#333; }}
Add semicolon.
CSS
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
<br></br>
<br>
Self-closing.
HTML
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var bar int = 'value'
var bar string = 'value'
Type mismatch.
Go
$values[12] = 5;
if (isset($values[12])) $values[12] = 5;
Check existence.
PHP
'4' + 90
4 + 90
Avoid string coercion.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
{{'age':17, 'id' 21}}
{{'age':17, 'id':21}}
Colon missing.
Python
values[98]
if (length(values) >= 98) values[98]
Check length.
R
if item > 39 print('data')
if item > 39: print('data')
Colon missing after if.
Python
int values[44]; values[44]=5;
int values[44]; if(44<44){{}} else values[44]=5;
Bounds check.
C++
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
for (a in items)
for (a of items)
for...in iterates keys.
JavaScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
def compute puts 'output' end
def compute puts 'output' end
Correct.
Ruby