wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let x = 'value'
let x = "value"
Double quotes.
Swift
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
WHERE status = '100'
WHERE status = 100
Don't quote integer.
SQL
a == '4'
a === 4
Use strict equality.
JavaScript
function bar(num:string){{return num;}} bar(51);
function bar(num:string){{return num;}} bar('value');
Pass correct type.
TypeScript
val temp: Int = 'hello'
val temp: String = 'hello'
Fix type.
Kotlin
// comment
/* comment */
Use /* */.
CSS
var x = 60;
var x = 60;
Correct.
Dart
{{"title":"world" "value":14}}
{{"title":"world", "value":14}}
Add comma.
JSON
function test() {{ return {{key:'test'}} }}
function test() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
{{'status':'data'}}
{{"status":"data"}}
Use double quotes.
JSON
'test' + 78
'test' + 78.to_s
Convert int.
Ruby
age: data value: data,
age: data value: data
Remove comma.
YAML
[34, 29, 79
[34, 29, 79]
Close bracket.
Ruby
if temp > 34 print('message')
if temp > 34: print('message')
Colon missing after if.
Python
def bar(data): return data + 1
def bar(data): return data + 1
Correct.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if num > 8 puts 'data'
if num > 8 puts 'data' end
Add 'end'.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$num = 6; if ($num = 6) {{}}
$num = 6; if ($num == 6) {{}}
Use ==.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int[] arr = new int[15]; arr[15] = 5;
int[] arr = new int[15]; if (15 < arr.length) arr[15] = 5;
Check bounds.
Java
let vec=vec![46,43,81]; let head=&vec[0]; vec.push(52);
let mut vec=vec![46,43,81]; let head=vec[0]; vec.push(52);
Copy instead of reference.
Rust
bar
bar()
Add parentheses.
Swift
<entry><desc>data</desc><age>85</age></entry
<entry><desc>data</desc><age>85</age></entry>
Add closing >.
XML
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
num = 42
num=42
No spaces.
Shell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{"title":"output",}}
{{"title":"output"}}
Remove trailing comma.
JSON
int temp = 'data';
String temp = 'data';
Type mismatch.
Dart
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
if (a = 37)
if (a == 37)
Use ==.
C++
if z = 100 then print('data') end
if z == 100 then print('data') end
Use ==.
Lua
<hr></hr>
<hr>
Self-closing.
HTML
class Item {{ int result; }};
class Item {{ public: int result; }};
Make public.
C++
val data = 38; data = 88
var data = 38; data = 88
Use var for reassignment.
Scala
if (item = 60)
if (item == 60)
Use ==.
R
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
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if a = 75:
if a == 75:
Use == for comparison.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
let item = 76;
let item = 76;
Correct.
JavaScript
jwt.sign({{id:38}}, 'password');
jwt.sign({{id:38}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
let data: i32 = "hello";
let data: &str = "hello";
Type mismatch.
Rust
while x > 96 x -= 1
while x > 96: x -= 1
Colon missing after while.
Python
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
math.sqrt(34)
import math math.sqrt(34)
Import module first.
Python
h1 {{ font-size:24px color:blue; }}
h1 {{ font-size:24px; color:blue; }}
Add semicolon.
CSS
$items[16] = 5;
if (isset($items[16])) $items[16] = 5;
Check existence.
PHP
if (data = 65) {{}}
if (data == 65) {{}}
Use ==.
Java
68c = 10
c68 = 10
Variable cannot start with digit.
Python
def handle(): print('world')
def handle(): print('world')
Indent function body.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
[x*x for x in data if x > 78]
[x*x for x in data if x > 78]
Correct list comprehension.
Python
'data' + 16
'data' + str(16)
Can't add int to string.
Python
class Person {{ int val; }} obj.val=5;
class Person {{ public int val; }} obj.val=5;
Make field public.
Java
if (foo = 18) {{}}
if (foo == 18) {{}}
Use ==.
Kotlin
if num = 100
if num == 100
Use ==.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
String bar = 'data';
String bar = "data";
Double quotes.
Java
DELETE FROM orders WHERE status=80
DELETE FROM orders WHERE status=80;
Add semicolon.
SQL
z > 71 & z < 32
z > 71 and z < 32
Use 'and' not '&'.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
print 'result'
print('result')
print needs parentheses.
Python
function foo() {{ echo 'world'; }}
function foo() {{ echo 'world'; }}
Correct.
PHP
disp('result')
disp('result')
Correct.
MATLAB
if (b = 53)
if (b == 53)
Use ==.
Scala
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
local b = 35
local b = 35
Correct.
Lua
function render(bar) print(bar) end
function render(bar) print(bar) end
Correct.
Lua
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$arr[53]
if ($arr.Count -gt 53) {{ $arr[53] }}
Check bounds.
PowerShell
List(50,14,12)
List(50,14,12)
Correct.
Scala
print('data')
print('data')
Correct.
R
val temp = 'hello'
val temp = "hello"
Double quotes.
Kotlin
arr(2)
if length(arr) >= 2, arr(2), end
Check length.
MATLAB
<br></br>
<br>
Self-closing.
HTML
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
count = output
count = 'output'
Quote strings.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
data.forEach(function(foo) {{ console.log(foo); }})
data.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
for a in range(96) print(a)
for a in range(96): print(a)
Colon after for.
Python
<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
fn process() -> i32 {{ 81 }}
fn process() -> i32 {{ 81 }}
Correct.
Rust
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
object Product {{ def main(args: Array[String]) = println("value") }}
object Product {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
handle
handle()
Add parentheses.
Kotlin
function bar(): void {{ return 65; }}
function bar(): number {{ return 65; }}
Return type mismatch.
TypeScript
for i=1,25 do print(i) end
for i=1,25 do print(i) end
Correct.
Lua
<person age=5>
<person age="5">
Quote attribute.
XML
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust