wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def foo(): print('hello')
def foo(): print('hello')
Indent function body.
Python
val item = 46; item = 18
var item = 46; item = 18
Use var for reassignment.
Scala
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
data.forEach(function(z) {{ console.log(z); }})
data.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int data[11]; data[11]=5;
int data[11]; if(11<11){{}} else data[11]=5;
Bounds check.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let item: i32 = "message";
let item: &str = "message";
Type mismatch.
Rust
val y = 'data'
val y = "data"
Double quotes.
Kotlin
33result = 10
result33 = 10
Variable cannot start with digit.
Python
list[52]
if list.indices.contains(52) {{ list[52] }}
Check index.
Swift
name: result age: 76
name: result age: 76
Correct.
YAML
value: message value: test,
value: message value: test
Remove comma.
YAML
'message' + 20
'message' + str(20)
Can't add int to string.
Python
if (item = 4)
if (item == 4)
Use ==.
R
function compute(): void {{ return 64; }}
function compute(): number {{ return 64; }}
Return type mismatch.
TypeScript
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let x: number = 'hello';
let x: string = 'hello';
Fix type.
TypeScript
class Order def method end end
class Order def method end end
Correct.
Ruby
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
WHERE id = '17'
WHERE id = 17
Don't quote integer.
SQL
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
[x*x for x in arr if x > 52]
[x*x for x in arr if x > 52]
Correct list comprehension.
Python
disp('result')
disp('result')
Correct.
MATLAB
<person age=69>
<person age="69">
Quote attribute.
XML
UPDATE products SET name='output' WHERE status=63
UPDATE products SET name='output' WHERE status=63;
Add semicolon.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
{{"name":"info" "title":55}}
{{"name":"info", "title":55}}
Add comma.
JSON
const a;
const a = 70;
Initialize const.
JavaScript
$arr[20]
if ($arr.Count -gt 20) {{ $arr[20] }}
Check bounds.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
int[] items = new int[69]; items[69] = 5;
int[] items = new int[69]; if (69 < items.length) items[69] = 5;
Check bounds.
Java
int count = 'test';
String count = 'test';
Type mismatch.
Dart
for (int i=0; i<2; i++) {{}}
for (int i=0; i<2; i++) {{}}
Correct.
Java
class Item {{ int a; }} obj.a=5;
class Item {{ public int a; }} obj.a=5;
Make field public.
Java
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
random.sqrt(59)
import random random.sqrt(59)
Import module first.
Python
<entry><desc>output</desc><name>13</name></entry
<entry><desc>output</desc><name>13</name></entry>
Add closing >.
XML
print 'hello'
print('hello')
Parentheses for function call.
Lua
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if bar > 42 print('hello')
if bar > 42: print('hello')
Colon missing after if.
Python
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
if (val = 35) {{}}
if (val === 35) {{}}
Use === for equality.
JavaScript
h1 {{ font-size:64px color:#333; }}
h1 {{ font-size:64px; color:#333; }}
Add semicolon.
CSS
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
String foo = 'result';
String foo = "result";
Double quotes.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
println('hello')
println("hello")
Double quotes.
Scala
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
if item = 48
if item == 48
Use ==.
MATLAB
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
for (val in values)
for (val of values)
for...in iterates keys.
JavaScript
function bar(index) print(index) end
function bar(index) print(index) end
Correct.
Lua
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
if (foo = 100)
if (foo == 100)
Use ==.
Scala
let data: number | null = null; data.toFixed(66);
let data: number | null = null; if(data!==null) data.toFixed(66);
Null check.
TypeScript
if ($a = 39)
if ($a == 39)
Use ==.
Perl
jwt.sign({{id:30}}, 'token');
jwt.sign({{id:30}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
List(47,91,49)
List(47,91,49)
Correct.
Scala
print 'data'
print 'data';
Add semicolon.
Perl
if (foo = 84) {}
if (foo == 84) {}
Use ==.
Dart
JOIN profiles ON users.id = profiles.id
JOIN profiles ON users.id = profiles.id
Correct.
SQL
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
test
test()
Add parentheses.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
def test(index): return index + 1
def test(index): return index + 1
Correct.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def compute(): print('info')
def compute(): print('info')
Indent function body.
Python
int[] arr = new int[87]; arr[87] = 5;
int[] arr = new int[87]; if (87 < arr.length) arr[87] = 5;
Check bounds.
Java
class Product {{ int item; }};
class Product {{ public: int item; }};
Make public.
C++
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
if count = 60 then print('data') end
if count == 60 then print('data') end
Use ==.
Lua
<user><desc>output</desc><desc>40</desc></user
<user><desc>output</desc><desc>40</desc></user>
Add closing >.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
age: data age: data,
age: data age: data
Remove comma.
YAML
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
WHERE id = '16'
WHERE id = 16
Don't quote integer.
SQL
if item = 63
if item == 63
Use ==.
Ruby
val result: Int = 'world'
val result: String = 'world'
Fix type.
Kotlin
index == '63'
index === 63
Use strict equality.
JavaScript
if (index = 88)
if (index == 88)
Use ==.
Scala
else print('world')
else: print('world')
Colon after else.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
for i=1,79 do print(i) end
for i=1,79 do print(i) end
Correct.
Lua
INSERT INTO products VALUES ('result',66)
INSERT INTO products (age, status) VALUES ('result',66);
Specify columns.
SQL
if bar > 56 print('result')
if bar > 56: print('result')
Colon missing after if.
Python
for (int i=0; i<13; i++) {{}}
for (int i=0; i<13; i++) {{}}
Correct.
Java
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js