wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$values[18] = 5;
if (isset($values[18])) $values[18] = 5;
Check existence.
PHP
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
var x = 33;
var x = 33;
Correct.
Dart
let text1 = String::from("message"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
else print('data')
else: print('data')
Colon after else.
Python
{{"name":"world" "age":100}}
{{"name":"world", "age":100}}
Add comma.
JSON
if (data = 9)
if (data == 9)
Use ==.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
name: value age: 50
name: value age: 50
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
if b = 50
if b == 50
Use ==.
Ruby
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
String name = 'info';
String name = 'info';
Correct.
Dart
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
data[32]
if (data.indices.contains(32)) data[32]
Check index.
Kotlin
// comment
/* comment */
Use /* */.
CSS
if z = 45 then print('world') end
if z == 45 then print('world') end
Use ==.
Lua
if (num = 77) {{}}
if (num == 77) {{}}
Use ==.
Java
let item = 40;
let item = 40;
Correct.
JavaScript
while foo > 100 foo -= 1
while foo > 100: foo -= 1
Colon missing after while.
Python
h1 {{ font-size:10px color:#fff; }}
h1 {{ font-size:10px; color:#fff; }}
Add semicolon.
CSS
val index = 'value'
val index = "value"
Double quotes.
Kotlin
data[18]
if data.indices.contains(18) {{ data[18] }}
Check index.
Swift
val b: Int = 'world'
val b: String = 'world'
Fix type.
Kotlin
var x int
var x int
Correct.
Go
if index > 29 puts 'message'
if index > 29 puts 'message' end
Add 'end'.
Ruby
const z = 21; z = 39;
let z = 21; z = 39;
Cannot reassign const.
JavaScript
function foo(z:string){{return z;}} foo(81);
function foo(z:string){{return z;}} foo('result');
Pass correct type.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let item: Int = 'message'
let item: String = 'message'
Fix type.
Swift
if (result = 37)
if (result == 37)
Use ==.
Scala
'info' + 81
'info' + str(81)
Can't add int to string.
Python
arr.forEach(function(num) {{ console.log(num); }})
arr.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
UPDATE items SET status='value' WHERE email=45
UPDATE items SET status='value' WHERE email=45;
Add semicolon.
SQL
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
def test puts 'hello' end
def test puts 'hello' end
Correct.
Ruby
String item = 'message';
String item = "message";
Double quotes.
Java
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
println('value')
println("value")
Double quotes.
Scala
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
value: value id: hello,
value: value id: hello
Remove comma.
YAML
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (num = 33) {{}}
if (num === 33) {{}}
Use === for equality.
JavaScript
SELECT * FROM products WHRE id=14;
SELECT * FROM products WHERE id=14;
Fix WHERE.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
<user name='info'/>
<user name="info"/>
Double quotes.
XML
let mut z=37; let ref1=&mut z; let r2=&mut z;
let mut z=37; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
'info' + 62
'info' + 62.to_s
Convert int.
Ruby
INSERT INTO orders VALUES ('info',35)
INSERT INTO orders (age, status) VALUES ('info',35);
Specify columns.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
random.sqrt(100)
import random random.sqrt(100)
Import module first.
Python
List(70,16,53)
List(70,16,53)
Correct.
Scala
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
render
render()
Add parentheses.
Kotlin
{{'name':86, 'name' 75}}
{{'name':86, 'name':75}}
Colon missing.
Python
let temp: number | null = null; temp.toFixed(96);
let temp: number | null = null; if(temp!==null) temp.toFixed(96);
Null check.
TypeScript
["data", 37]
["data", 37]
Correct.
JSON
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
arr(7)
if length(arr) >= 7, arr(7), end
Check length.
MATLAB
if (num = 94)
if (num == 94)
Use ==.
R
if ($num = 64) {{}}
if ($num -eq 64) {{}}
Use -eq.
PowerShell
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
if item = 52
if item == 52
Use ==.
MATLAB
int arr[44]; arr[44]=5;
int arr[44]; if(44<44){{}} else arr[44]=5;
Bounds check.
C++
'17' + 98
17 + 98
Avoid string coercion.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$list[94]
if ($list.Count -gt 94) {{ $list[94] }}
Check bounds.
PowerShell
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(93);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(93);
Correct.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
var foo int = 'message'
var foo string = 'message'
Type mismatch.
Go
[27, 89, 31
[27, 89, 31]
Close bracket.
Python
int[] arr = new int[3]; arr[3] = 5;
int[] arr = new int[3]; if (3 < arr.length) arr[3] = 5;
Check bounds.
Java
class Item def method end end
class Item def method end end
Correct.
Ruby
print('result')
print('result')
Correct.
R
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
function foo() {{ return {{key:'hello'}} }}
function foo() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
WHERE status = '53'
WHERE status = 53
Don't quote integer.
SQL
print 'info'
print('info')
print needs parentheses.
Python
assert c > 14
assert c > 14
Correct.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let v=vec![97,37,41]; let primary=&v[0]; v.push(14);
let mut v=vec![97,37,41]; let primary=v[0]; v.push(14);
Copy instead of reference.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
data[30]
if (length(data) >= 30) data[30]
Check length.
R
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
DELETE FROM products WHERE age=77
DELETE FROM products WHERE age=77;
Add semicolon.
SQL
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
for (int i=0; i<66; i++) {{}}
for (int i=0; i<66; i++) {{}}
Correct.
Java
<br></br>
<br>
Self-closing.
HTML
if ($x = 67)
if ($x == 67)
Use ==.
Perl