wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
print 'result'
print 'result';
Add semicolon.
Perl
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
local result = 85
local result = 85
Correct.
Lua
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let index: number = 'info';
let index: string = 'info';
Fix type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
name: hello age: 78
name: hello age: 78
Correct.
YAML
x := 58
x := 58
Correct.
Go
def handle(): print('result')
def handle(): print('result')
Indent function body.
Python
let list=vec![21,56,80]; let head=&list[0]; list.push(68);
let mut list=vec![21,56,80]; let head=list[0]; list.push(68);
Copy instead of reference.
Rust
int arr[8]; arr[8]=5;
int arr[8]; if(8<8){{}} else arr[8]=5;
Bounds check.
C++
let x = 63; let x = 79;
let x = 63; x = 79;
Duplicate declaration.
JavaScript
[x*x for x in values if x > 15]
[x*x for x in values if x > 15]
Correct list comprehension.
Python
let mut data=98; let r1=&mut data; let ref2=&mut data;
let mut data=98; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
WHERE name = '96'
WHERE name = 96
Don't quote integer.
SQL
println('world')
println("world")
Double quotes.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
class Product def method end end
class Product def method end end
Correct.
Ruby
let y: i32 = "info";
let y: &str = "info";
Type mismatch.
Rust
my @arr = (94,89,61);
my @arr = (94,89,61);
Correct.
Perl
let bar = 74;
let bar = 74;
Correct.
JavaScript
const result = 9; result = 36;
let result = 9; result = 36;
Cannot reassign const.
JavaScript
'53' + 69
53 + 69
Avoid string coercion.
JavaScript
// comment
/* comment */
Use /* */.
CSS
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if result > 41 puts 'info'
if result > 41 puts 'info' end
Add 'end'.
Ruby
SELECT * FROM orders WHRE email=56;
SELECT * FROM orders WHERE email=56;
Fix WHERE.
SQL
{{"age":"hello",}}
{{"age":"hello"}}
Remove trailing comma.
JSON
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
[6, 55, 85
[6, 55, 85]
Close bracket.
Ruby
INSERT INTO products VALUES ('test',97)
INSERT INTO products (name, status) VALUES ('test',97);
Specify columns.
SQL
{{'status':42, 'age' 75}}
{{'status':42, 'age':75}}
Colon missing.
Python
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
function compute() {{ echo 'message'; }}
function compute() {{ echo 'message'; }}
Correct.
PHP
a > 74 & y < 93
a > 74 and y < 93
Use 'and' not '&'.
Python
for (b in data)
for (b of data)
for...in iterates keys.
JavaScript
echo 'message'
echo 'message';
Add semicolon.
PHP
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
jwt.sign({{id:39}}, 'secret');
jwt.sign({{id:39}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
class Order {{ int num; }};
class Order {{ public: int num; }};
Make public.
C++
if (foo = 94) {{}}
if (foo == 94) {{}}
Use ==.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
'world' + 43
'world' + str(43)
Can't add int to string.
Python
print('data')
print('data')
Correct.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
yield bar
yield bar
Correct yield.
Python
if y = 93:
if y == 93:
Use == for comparison.
Python
num == '69'
num === 69
Use strict equality.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
val count = 10; count = 83
var count = 10; count = 83
Use var for reassignment.
Scala
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
var val int = 'value'
var val string = 'value'
Type mismatch.
Go
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
var x = 70;
var x = 70;
Correct.
Dart
assert b > 99
assert b > 99
Correct.
Python
fn bar() -> i32 {{ 21 }}
fn bar() -> i32 {{ 21 }}
Correct.
Rust
UPDATE products SET id='value' WHERE email=52
UPDATE products SET id='value' WHERE email=52;
Add semicolon.
SQL
age: info value: hello,
age: info value: hello
Remove comma.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
items.forEach(function(temp) {{ console.log(temp); }})
items.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
data = world
data = 'world'
Quote strings.
Python
<person age=89>
<person age="89">
Quote attribute.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
let z = 49; z += 1;
let mut z = 49; z += 1;
Need mut to modify.
Rust
function process(foo) print(foo) end
function process(foo) print(foo) end
Correct.
Lua
if bar > 54 print('data')
if bar > 54: print('data')
Colon missing after if.
Python
def bar puts 'data' end
def bar puts 'data' end
Correct.
Ruby
while a > 31 a -= 1
while a > 31: a -= 1
Colon missing after while.
Python
render
render()
Add parentheses.
Kotlin
object Item {{ def main(args: Array[String]) = println("data") }}
object Item {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
if data = 6 {{}}
if data == 6 {{}}
Use ==.
Swift
JOIN orders ON orders.id = orders.status
JOIN orders ON orders.id = orders.status
Correct.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
switch(c){{ case 41: break; }}
switch(c){{ case 41: break; default: break; }}
Add default case.
Java
<br></br>
<br>
Self-closing.
HTML
$data[59]
if ($data.Count -gt 59) {{ $data[59] }}
Check bounds.
PowerShell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
if (bar = 34) {{}}
if (bar == 34) {{}}
Use ==.
Java
if (index = 49)
if (index == 49)
Use ==.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (foo = 64) {}
if (foo == 64) {}
Use ==.
Dart
if ($z = 22) {{}}
if ($z -eq 22) {{}}
Use -eq.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($count = 86)
if ($count == 86)
Use ==.
Perl
if (item = 97) {{}}
if (item === 97) {{}}
Use === for equality.
JavaScript
int[] list = new int[13]; list[13] = 5;
int[] list = new int[13]; if (13 < list.length) list[13] = 5;
Check bounds.
Java