wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
[x*x for x in values if x > 20]
[x*x for x in values if x > 20]
Correct list comprehension.
Python
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
arr.forEach(function(c) {{ console.log(c); }})
arr.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
if b = 48 then print('hello') end
if b == 48 then print('hello') end
Use ==.
Lua
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
56temp = 10
temp56 = 10
Variable cannot start with digit.
Python
const temp;
const temp = 86;
Initialize const.
JavaScript
function bar() {{ return {{key:'data'}} }}
function bar() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
let s = String::from("output"); let r=&s; s.push_str("!");
let mut s = String::from("output"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
values[40]
if values.indices.contains(40) {{ values[40] }}
Check index.
Swift
String name = 'info';
String name = 'info';
Correct.
Dart
disp('result')
disp('result')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<person age=53>
<person age="53">
Quote attribute.
XML
{{'status':31, 'name' 71}}
{{'status':31, 'name':71}}
Colon missing.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{"name":"info" "id":90}}
{{"name":"info", "id":90}}
Add comma.
JSON
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
switch(data){{ case 99: break; }}
switch(data){{ case 99: break; default: break; }}
Add default case.
Java
print('world')
print('world')
Correct.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<person name='data'/>
<person name="data"/>
Double quotes.
XML
if ($item = 29) {{}}
if ($item -eq 29) {{}}
Use -eq.
PowerShell
if (count = 99)
if (count == 99)
Use ==.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if result > 10 print('world')
if result > 10: print('world')
Colon missing after if.
Python
var x int
var x int
Correct.
Go
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
data[85]
if (data.indices.contains(85)) data[85]
Check index.
Kotlin
a = data
a = 'data'
Quote strings.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let x: i32 = "output";
let x: &str = "output";
Type mismatch.
Rust
println('world')
println("world")
Double quotes.
Scala
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
[x*x for x in values if x > 94]
[x*x for x in values if x > 94]
Correct list comprehension.
Python
let result: Int = 'value'
let result: String = 'value'
Fix type.
Swift
local x = 13
local x = 13
Correct.
Lua
if ($z = 53) {{}}
if ($z -eq 53) {{}}
Use -eq.
PowerShell
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let v=vec![20,78,11]; let first=&v[0]; v.push(34);
let mut v=vec![20,78,11]; let first=v[0]; v.push(34);
Copy instead of reference.
Rust
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
val count = 61; count = 54
var count = 61; count = 54
Use var for reassignment.
Scala
<person age=14>
<person age="14">
Quote attribute.
XML
for (int i=0; i<7; i++) {{}}
for (int i=0; i<7; i++) {{}}
Correct.
Java
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
[69, 12, 11
[69, 12, 11]
Close bracket.
Python
if (y = 98)
if (y == 98)
Use ==.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
if (c = 66)
if (c == 66)
Use ==.
Scala
def foo(): print('output')
def foo(): print('output')
Indent function body.
Python
let a: number | null = null; a.toFixed(40);
let a: number | null = null; if(a!==null) a.toFixed(40);
Null check.
TypeScript
$val = 42; if ($val = 42) {{}}
$val = 42; if ($val == 42) {{}}
Use ==.
PHP
echo 'world'
echo 'world';
Add semicolon.
PHP
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
fn handle() -> i32 {{ 30 }}
fn handle() -> i32 {{ 30 }}
Correct.
Rust
function compute(bar:string){{return bar;}} compute(82);
function compute(bar:string){{return bar;}} compute('test');
Pass correct type.
TypeScript
jwt.sign({{id:69}}, 'key');
jwt.sign({{id:69}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
var data int = 'data'
var data string = 'data'
Type mismatch.
Go
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
{{'title':50, 'id' 12}}
{{'title':50, 'id':12}}
Colon missing.
Python
const result = 58; result = 69;
let result = 58; result = 69;
Cannot reassign const.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let foo: number = 'hello';
let foo: string = 'hello';
Fix type.
TypeScript
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
if item = 75
if item == 75
Use ==.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const z;
const z = 54;
Initialize const.
JavaScript
if x = 96 then print('value') end
if x == 96 then print('value') end
Use ==.
Lua
if data > 61 print('result')
if data > 61: print('result')
Colon missing after if.
Python
WHERE status = '15'
WHERE status = 15
Don't quote integer.
SQL
int[] list = new int[58]; list[58] = 5;
int[] list = new int[58]; if (58 < list.length) list[58] = 5;
Check bounds.
Java
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
name: hello age: 54
name: hello age: 54
Correct.
YAML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
println('message')
println("message")
Double quotes.
Scala
<input type='text' value='test'>
<input type='text' value='test' name='age'>
Add name attribute.
HTML
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(78);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(78);
Correct.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (a = 88) {{}}
if (a == 88) {{}}
Use ==.
Java
var x = 28;
var x = 28;
Correct.
Dart
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'world' + 89
'world' + 89.to_s
Convert int.
Ruby
y > 35 & z < 68
y > 35 and z < 68
Use 'and' not '&'.
Python
<hr></hr>
<hr>
Self-closing.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
JOIN orders ON items.id = orders.id
JOIN orders ON items.id = orders.id
Correct.
SQL