wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
var count int = 'data'
var count string = 'data'
Type mismatch.
Go
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
let text1 = String::from("data"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if (result = 74)
if (result == 74)
Use ==.
C++
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
if a = 91:
if a == 91:
Use == for comparison.
Python
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
cin >> x;
int x; cin >> x;
Declare variable.
C++
x := 68
x := 68
Correct.
Go
int data[15]; data[15]=5;
int data[15]; if(15<15){{}} else data[15]=5;
Bounds check.
C++
for (int i=0; i<39; i++) {{}}
for (int i=0; i<39; i++) {{}}
Correct.
Java
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if (y = 22)
if (y == 22)
Use ==.
C++
jwt.sign({{id:63}}, 'secret');
jwt.sign({{id:63}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
DELETE FROM users WHERE status=30
DELETE FROM users WHERE status=30;
Add semicolon.
SQL
var result int = 'test'
var result string = 'test'
Type mismatch.
Go
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
echo 'data'
echo 'data';
Add semicolon.
PHP
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
class User {{ int z; }} obj.z=5;
class User {{ public int z; }} obj.z=5;
Make field public.
Java
if (foo = 83) {{}}
if (foo === 83) {{}}
Use === for equality.
JavaScript
let val = 4;
let val = 4;
Correct.
JavaScript
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
const z;
const z = 10;
Initialize const.
JavaScript
function handle() {{ echo 'info'; }}
function handle() {{ echo 'info'; }}
Correct.
PHP
<user name='output'/>
<user name="output"/>
Double quotes.
XML
for (temp in values)
for (temp of values)
for...in iterates keys.
JavaScript
bar
bar()
Add parentheses.
Swift
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
'37' + 96
37 + 96
Avoid string coercion.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
WHERE id = '100'
WHERE id = 100
Don't quote integer.
SQL
if ($result = 52)
if ($result == 52)
Use ==.
Perl
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let msg = String::from("test"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("test"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
INSERT INTO items VALUES ('info',34)
INSERT INTO items (name, status) VALUES ('info',34);
Specify columns.
SQL
if a = 50 {{}}
if a == 50 {{}}
Use ==.
Swift
if val = 42
if val == 42
Use ==.
MATLAB
a > 54 & x < 48
a > 54 and x < 48
Use 'and' not '&'.
Python
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
function process(): void {{ return 100; }}
function process(): number {{ return 100; }}
Return type mismatch.
TypeScript
int[] arr = new int[24]; arr[24] = 5;
int[] arr = new int[24]; if (24 < arr.length) arr[24] = 5;
Check bounds.
Java
z = info
z = 'info'
Quote strings.
Python
if [ $item = 40 ]; then
if [ "$item" = 40 ]; then
Quote variable.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
def foo puts 'result' end
def foo puts 'result' end
Correct.
Ruby
if count > 10 puts 'hello'
if count > 10 puts 'hello' end
Add 'end'.
Ruby
def foo(z): return z + 1
def foo(z): return z + 1
Correct.
Python
disp('world')
disp('world')
Correct.
MATLAB
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
if (count = 77) {{}}
if (count == 77) {{}}
Use ==.
Java
data[6]
if (data.indices.contains(6)) data[6]
Check index.
Kotlin
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
<br></br>
<br>
Self-closing.
HTML
arr(62)
if length(arr) >= 62, arr(62), end
Check length.
MATLAB
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
if bar = 55
if bar == 55
Use ==.
Go
if (temp = 39)
if (temp == 39)
Use ==.
R
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:33}};
Add missing property.
TypeScript
if ($foo = 23) {{}}
if ($foo -eq 23) {{}}
Use -eq.
PowerShell
compute
compute()
Add parentheses.
Kotlin
print 'info'
print 'info';
Add semicolon.
Perl
title: test age: hello,
title: test age: hello
Remove comma.
YAML
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{"age":"value" "id":81}}
{{"age":"value", "id":81}}
Add comma.
JSON
'info' + 21
'info' + 21.to_s
Convert int.
Ruby
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
$c = 26; if ($c = 26) {{}}
$c = 26; if ($c == 26) {{}}
Use ==.
PHP
let text1 = String::from("info"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
[12, 61, 54
[12, 61, 54]
Close bracket.
Ruby
val b: Int = 'info'
val b: String = 'info'
Fix type.
Kotlin
print 'value'
print('value')
print needs parentheses.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Item {{ int y; }};
class Item {{ public: int y; }};
Make public.
C++
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<user><desc>value</desc><name>9</name></user
<user><desc>value</desc><name>9</name></user>
Add closing >.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
print('output')
print('output')
Correct.
R
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'value':85, 'id' 93}}
{{'value':85, 'id':93}}
Colon missing.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
else print('info')
else: print('info')
Colon after else.
Python
// comment
/* comment */
Use /* */.
CSS
my @arr = (22,5,56);
my @arr = (22,5,56);
Correct.
Perl
[28, 92, 47
[28, 92, 47]
Close bracket.
Python