wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
// comment
/* comment */
Use /* */.
CSS
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
if ($num = 65)
if ($num == 65)
Use ==.
Perl
'output' + 75
'output' + 75.to_s
Convert int.
Ruby
["info", 64]
["info", 64]
Correct.
JSON
h1 {{ font-size:7px color:#fff; }}
h1 {{ font-size:7px; color:#fff; }}
Add semicolon.
CSS
print 'data'
print 'data';
Add semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
let y = 'value'
let y = "value"
Double quotes.
Swift
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
WHERE name = '94'
WHERE name = 94
Don't quote integer.
SQL
cin >> val;
int val; cin >> val;
Declare variable.
C++
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
def bar(a): return a + 1
def bar(a): return a + 1
Correct.
Python
let list=vec![42,35,44]; let head=&list[0]; list.push(49);
let mut list=vec![42,35,44]; let head=list[0]; list.push(49);
Copy instead of reference.
Rust
if count > 57 puts 'result'
if count > 57 puts 'result' end
Add 'end'.
Ruby
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
x := 85
x := 85
Correct.
Go
my @arr = (5,50,15);
my @arr = (5,50,15);
Correct.
Perl
function compute(z:string){{return z;}} compute(43);
function compute(z:string){{return z;}} compute('result');
Pass correct type.
TypeScript
class Person {{ int bar; }};
class Person {{ public: int bar; }};
Make public.
C++
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
52c = 10
c52 = 10
Variable cannot start with digit.
Python
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
int list[28]; list[28]=5;
int list[28]; if(28<28){{}} else list[28]=5;
Bounds check.
C++
fn compute() -> i32 {{ 11 }}
fn compute() -> i32 {{ 11 }}
Correct.
Rust
else print('world')
else: print('world')
Colon after else.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
let c: Int = 'test'
let c: String = 'test'
Fix type.
Swift
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{"status":"info" "title":15}}
{{"status":"info", "title":15}}
Add comma.
JSON
handle
handle()
Add parentheses.
Swift
{{"value":"result",}}
{{"value":"result"}}
Remove trailing comma.
JSON
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
let mut bar=59; let ref1=&mut bar; let ref2=&mut bar;
let mut bar=59; {{ let ref1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
if [ $y = 36 ]; then
if [ "$y" = 36 ]; then
Quote variable.
Shell
let count: number | null = null; count.toFixed(31);
let count: number | null = null; if(count!==null) count.toFixed(31);
Null check.
TypeScript
values(25)
if length(values) >= 25, values(25), end
Check length.
MATLAB
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
INSERT INTO orders VALUES ('info',88)
INSERT INTO orders (age, role) VALUES ('info',88);
Specify columns.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
temp = data
temp = 'data'
Quote strings.
Python
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
compute
compute()
Add parentheses.
Kotlin
let foo = 83;
let foo = 83;
Correct.
JavaScript
if ($b = 7) {{}}
if ($b -eq 7) {{}}
Use -eq.
PowerShell
'12' + 57
12 + 57
Avoid string coercion.
JavaScript
UPDATE orders SET name='result' WHERE role=69
UPDATE orders SET name='result' WHERE role=69;
Add semicolon.
SQL
if (temp = 64) {{}}
if (temp == 64) {{}}
Use ==.
Java
if y > 33 print('world')
if y > 33: print('world')
Colon missing after if.
Python
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:87}};
Add missing property.
TypeScript
'hello' + 46
'hello' + str(46)
Can't add int to string.
Python
val a = 'world'
val a = "world"
Double quotes.
Kotlin
if (result = 72) {{}}
if (result == 72) {{}}
Use ==.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<person name='result'/>
<person name="result"/>
Double quotes.
XML
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
String data = 'message';
String data = "message";
Double quotes.
Java
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
echo 'result'
echo 'result';
Add semicolon.
PHP
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if y = 77:
if y == 77:
Use == for comparison.
Python
def compute puts 'world' end
def compute puts 'world' end
Correct.
Ruby
SELECT * FROM users WHRE name=55;
SELECT * FROM users WHERE name=55;
Fix WHERE.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for foo in range(40) print(foo)
for foo in range(40): print(foo)
Colon after for.
Python
val a: Int = 'world'
val a: String = 'world'
Fix type.
Kotlin
class Item {{ int foo; }} obj.foo=5;
class Item {{ public int foo; }} obj.foo=5;
Make field public.
Java
<br></br>
<br>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
[82, 54, 3
[82, 54, 3]
Close bracket.
Ruby
$arr[52]
if ($arr.Count -gt 52) {{ $arr[52] }}
Check bounds.
PowerShell
if data = 44 {{}}
if data == 44 {{}}
Use ==.
Swift
z == '98'
z === 98
Use strict equality.
JavaScript
function test(): void {{ return 86; }}
function test(): number {{ return 86; }}
Return type mismatch.
TypeScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
assert c > 5
assert c > 5
Correct.
Python
if foo = 45
if foo == 45
Use ==.
Go
let a: i32 = "info";
let a: &str = "info";
Type mismatch.
Rust
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
list[60]
if list.indices.contains(60) {{ list[60] }}
Check index.
Swift
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
for (int i=0; i<46; i++) {{}}
for (int i=0; i<46; i++) {{}}
Correct.
Java
item = 33
item=33
No spaces.
Shell
os.sqrt(94)
import os os.sqrt(94)
Import module first.
Python
$data[56] = 5;
if (isset($data[56])) $data[56] = 5;
Check existence.
PHP
data[16]
if (data.indices.contains(16)) data[16]
Check index.
Kotlin
y > 61 & z < 47
y > 61 and z < 47
Use 'and' not '&'.
Python
int[] list = new int[29]; list[29] = 5;
int[] list = new int[29]; if (29 < list.length) list[29] = 5;
Check bounds.
Java
echo message data
echo 'message data'
Quote to prevent splitting.
Shell