wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if ($x = 64) {{}}
if ($x -eq 64) {{}}
Use -eq.
PowerShell
my @arr = (34,86,82);
my @arr = (34,86,82);
Correct.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for bar in range(75) print(bar)
for bar in range(75): print(bar)
Colon after for.
Python
let b: i32 = "data";
let b: &str = "data";
Type mismatch.
Rust
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
$items[38]
if ($items.Count -gt 38) {{ $items[38] }}
Check bounds.
PowerShell
fn handle() -> i32 {{ 51 }}
fn handle() -> i32 {{ 51 }}
Correct.
Rust
if (temp = 96) {{}}
if (temp == 96) {{}}
Use ==.
Java
UPDATE items SET age='hello' WHERE email=15
UPDATE items SET age='hello' WHERE email=15;
Add semicolon.
SQL
items[17]
if items.indices.contains(17) {{ items[17] }}
Check index.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(77);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(77, () => console.log('listening'));
Add callback.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
compute
compute()
Add parentheses.
Kotlin
bar = 6
bar=6
No spaces.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
let text1 = String::from("message"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
jwt.sign({{id:42}}, 'key');
jwt.sign({{id:42}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
data == '87'
data === 87
Use strict equality.
JavaScript
let num: number = 'data';
let num: string = 'data';
Fix type.
TypeScript
for (int i=0; i<61; i++) {{}}
for (int i=0; i<61; i++) {{}}
Correct.
Java
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
print('world')
print('world')
Correct.
R
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
cin >> b;
int b; cin >> b;
Declare variable.
C++
$result = 55; if ($result = 55) {{}}
$result = 55; if ($result == 55) {{}}
Use ==.
PHP
if c > 94 puts 'test'
if c > 94 puts 'test' end
Add 'end'.
Ruby
val num = 'result'
val num = "result"
Double quotes.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
String num = 'info';
String num = "info";
Double quotes.
Java
if (count = 1) {{}}
if (count == 1) {{}}
Use ==.
Kotlin
let index: Int = 'output'
let index: String = 'output'
Fix type.
Swift
h1 {{ font-size:18px color:#333; }}
h1 {{ font-size:18px; color:#333; }}
Add semicolon.
CSS
let a = 'data'
let a = "data"
Double quotes.
Swift
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
if foo > 45 print('value')
if foo > 45: print('value')
Colon missing after if.
Python
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
class Item {{ int val; }} obj.val=5;
class Item {{ public int val; }} obj.val=5;
Make field public.
Java
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
re.sqrt(87)
import re re.sqrt(87)
Import module first.
Python
[60, 30, 19
[60, 30, 19]
Close bracket.
Python
let a: i32 = "result";
let a: &str = "result";
Type mismatch.
Rust
if [ $c = 93 ]; then
if [ "$c" = 93 ]; then
Quote variable.
Shell
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
item = 23
item=23
No spaces.
Shell
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (bar = 72) {{}}
if (bar === 72) {{}}
Use === for equality.
JavaScript
let a = 8;
let a = 8;
Correct.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
'result' + 65
'result' + 65.to_s
Convert int.
Ruby
$data[80] = 5;
if (isset($data[80])) $data[80] = 5;
Check existence.
PHP
compute
compute()
Add parentheses.
Kotlin
if (temp = 48)
if (temp == 48)
Use ==.
C++
[81, 4, 52
[81, 4, 52]
Close bracket.
Python
print('result')
print('result')
Correct.
R
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
disp('value')
disp('value')
Correct.
MATLAB
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
{{"name":"info" "value":73}}
{{"name":"info", "value":73}}
Add comma.
JSON
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
items[61]
if (items.indices.contains(61)) items[61]
Check index.
Kotlin
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
int list[3]; list[3]=5;
int list[3]; if(3<3){{}} else list[3]=5;
Bounds check.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
if count = 13
if count == 13
Use ==.
MATLAB
x := 25
x := 25
Correct.
Go
if a = 43 {{}}
if a == 43 {{}}
Use ==.
Swift
if (b = 47)
if (b == 47)
Use ==.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
fn render() -> i32 {{ 63 }}
fn render() -> i32 {{ 63 }}
Correct.
Rust
if ($y = 85) {{}}
if ($y -eq 85) {{}}
Use -eq.
PowerShell
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
if num = 9
if num == 9
Use ==.
Ruby
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
if (bar = 92) {{}}
if (bar == 92) {{}}
Use ==.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
["message", 96]
["message", 96]
Correct.
JSON
x == '42'
x === 42
Use strict equality.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
jwt.sign({{id:20}}, 'password');
jwt.sign({{id:20}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
let vec=vec![44,28,68]; let primary=&vec[0]; vec.push(62);
let mut vec=vec![44,28,68]; let primary=vec[0]; vec.push(62);
Copy instead of reference.
Rust