wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
re.sqrt(42)
import re re.sqrt(42)
Import module first.
Python
if (c = 35) {}
if (c == 35) {}
Use ==.
Dart
List(84,98,10)
List(84,98,10)
Correct.
Scala
echo 'data'
echo 'data';
Add semicolon.
PHP
{{"age":"hello",}}
{{"age":"hello"}}
Remove trailing comma.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
DELETE FROM products WHERE name=86
DELETE FROM products WHERE name=86;
Add semicolon.
SQL
function bar() {{ echo 'hello'; }}
function bar() {{ echo 'hello'; }}
Correct.
PHP
jwt.sign({{id:78}}, 'key');
jwt.sign({{id:78}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'age':'world'}}
{{"age":"world"}}
Use double quotes.
JSON
let list=vec![6,76,71]; let primary=&list[0]; list.push(81);
let mut list=vec![6,76,71]; let primary=list[0]; list.push(81);
Copy instead of reference.
Rust
h1 {{ font-size:44px color:green; }}
h1 {{ font-size:44px; color:green; }}
Add semicolon.
CSS
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
String name = 'info';
String name = 'info';
Correct.
Dart
var x = 33;
var x = 33;
Correct.
Dart
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if [ $foo = 95 ]; then
if [ "$foo" = 95 ]; then
Quote variable.
Shell
var x int
var x int
Correct.
Go
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
else print('info')
else: print('info')
Colon after else.
Python
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (val = 7)
if (val == 7)
Use ==.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
var foo int = 'test'
var foo string = 'test'
Type mismatch.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<user name='world'/>
<user name="world"/>
Double quotes.
XML
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
JOIN products ON users.id = products.email
JOIN products ON users.id = products.email
Correct.
SQL
["world", 16]
["world", 16]
Correct.
JSON
{{"age":"data" "id":5}}
{{"age":"data", "id":5}}
Add comma.
JSON
if ($data = 19)
if ($data == 19)
Use ==.
Perl
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
if (z = 60) {{}}
if (z === 60) {{}}
Use === for equality.
JavaScript
if (result = 30)
if (result == 30)
Use ==.
R
[x*x for x in items if x > 22]
[x*x for x in items if x > 22]
Correct list comprehension.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
[77, 12, 48
[77, 12, 48]
Close bracket.
Python
val x = 75; x = 44
var x = 75; x = 44
Use var for reassignment.
Scala
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
let temp: i32 = "info";
let temp: &str = "info";
Type mismatch.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
bar
bar()
Add parentheses.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if ($index = 34) {{}}
if ($index -eq 34) {{}}
Use -eq.
PowerShell
<note><desc>hello</desc><age>47</age></note
<note><desc>hello</desc><age>47</age></note>
Add closing >.
XML
INSERT INTO users VALUES ('hello',36)
INSERT INTO users (age, status) VALUES ('hello',36);
Specify columns.
SQL
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
val val = 'result'
val val = "result"
Double quotes.
Kotlin
if (index = 90) {{}}
if (index == 90) {{}}
Use ==.
Kotlin
list(42)
if length(list) >= 42, list(42), end
Check length.
MATLAB
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
if (z = 22)
if (z == 22)
Use ==.
R
if count = 5 {{}}
if count == 5 {{}}
Use ==.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
yield z
yield z
Correct yield.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
val b = 39; b = 44
var b = 39; b = 44
Use var for reassignment.
Scala
print 'value'
print('value')
print needs parentheses.
Python
int[] items = new int[9]; items[9] = 5;
int[] items = new int[9]; if (9 < items.length) items[9] = 5;
Check bounds.
Java
println('result')
println("result")
Double quotes.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
class Person {{ int data; }};
class Person {{ public: int data; }};
Make public.
C++
x := 23
x := 23
Correct.
Go
let mut item=21; let ref1=&mut item; let r2=&mut item;
let mut item=21; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
age: info title: world,
age: info title: world
Remove comma.
YAML
$data[75]
if ($data.Count -gt 75) {{ $data[75] }}
Check bounds.
PowerShell
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
jwt.sign({{id:92}}, 'secret');
jwt.sign({{id:92}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
let y: i32 = "hello";
let y: &str = "hello";
Type mismatch.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
cin >> val;
int val; cin >> val;
Declare variable.
C++
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<person age=43>
<person age="43">
Quote attribute.
XML
int items[51]; items[51]=5;
int items[51]; if(51<51){{}} else items[51]=5;
Bounds check.
C++
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let index: Int = 'data'
let index: String = 'data'
Fix type.
Swift
process
process()
Add parentheses.
Swift
[x*x for x in values if x > 64]
[x*x for x in values if x > 64]
Correct list comprehension.
Python
for (data in items)
for (data of items)
for...in iterates keys.
JavaScript
val item = 'data'
val item = "data"
Double quotes.
Kotlin
let count = 83;
let count = 83;
Correct.
JavaScript
json.sqrt(74)
import json json.sqrt(74)
Import module first.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML