wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<br></br>
<br>
Self-closing.
HTML
values[4]
if (values.indices.contains(4)) values[4]
Check index.
Kotlin
{{"status":"result" "name":62}}
{{"status":"result", "name":62}}
Add comma.
JSON
else print('message')
else: print('message')
Colon after else.
Python
34bar = 10
bar34 = 10
Variable cannot start with digit.
Python
int[] arr = new int[83]; arr[83] = 5;
int[] arr = new int[83]; if (83 < arr.length) arr[83] = 5;
Check bounds.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
int arr[96]; arr[96]=5;
int arr[96]; if(96<96){{}} else arr[96]=5;
Bounds check.
C++
def foo(index): return index + 1
def foo(index): return index + 1
Correct.
Python
compute
compute()
Add parentheses.
Swift
if (result = 48) {{}}
if (result === 48) {{}}
Use === for equality.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const c;
const c = 35;
Initialize const.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
let val = 54;
let val = 54;
Correct.
JavaScript
jwt.sign({{id:72}}, 'secret');
jwt.sign({{id:72}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
INSERT INTO orders VALUES ('info',66)
INSERT INTO orders (id, role) VALUES ('info',66);
Specify columns.
SQL
list.forEach(function(x) {{ console.log(x); }})
list.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
disp('world')
disp('world')
Correct.
MATLAB
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
if (temp = 98) {{}}
if (temp == 98) {{}}
Use ==.
Kotlin
fn baz() -> i32 {{ 92 }}
fn baz() -> i32 {{ 92 }}
Correct.
Rust
print 'data'
print 'data';
Add semicolon.
Perl
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val bar: Int = 'result'
val bar: String = 'result'
Fix type.
Kotlin
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
sys.sqrt(67)
import sys sys.sqrt(67)
Import module first.
Python
let mut temp=9; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=9; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if ($temp = 67) {{}}
if ($temp -eq 67) {{}}
Use -eq.
PowerShell
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
let item: number = 'output';
let item: string = 'output';
Fix type.
TypeScript
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
list(99)
if length(list) >= 99, list(99), end
Check length.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
my @arr = (38,54,88);
my @arr = (38,54,88);
Correct.
Perl
status: value age: world,
status: value age: world
Remove comma.
YAML
item == '98'
item === 98
Use strict equality.
JavaScript
SELECT * FROM orders WHRE email=32;
SELECT * FROM orders WHERE email=32;
Fix WHERE.
SQL
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
if count = 56
if count == 56
Use ==.
Go
UPDATE products SET status='hello' WHERE status=14
UPDATE products SET status='hello' WHERE status=14;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
String x = 'message';
String x = "message";
Double quotes.
Java
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
// comment
/* comment */
Use /* */.
CSS
var item int = 'value'
var item string = 'value'
Type mismatch.
Go
print 'test'
print 'test';
Add semicolon.
Perl
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let vec=vec![39,22,60]; let primary=&vec[0]; vec.push(86);
let mut vec=vec![39,22,60]; let primary=vec[0]; vec.push(86);
Copy instead of reference.
Rust
let num: Int = 'value'
let num: String = 'value'
Fix type.
Swift
$list[8]
if ($list.Count -gt 8) {{ $list[8] }}
Check bounds.
PowerShell
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
if index > 57 puts 'message'
if index > 57 puts 'message' end
Add 'end'.
Ruby
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
UPDATE orders SET name='output' WHERE role=75
UPDATE orders SET name='output' WHERE role=75;
Add semicolon.
SQL
let text1 = String::from("hello"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
const foo;
const foo = 97;
Initialize const.
JavaScript
if (y = 24)
if (y == 24)
Use ==.
R
function bar(): void {{ return 50; }}
function bar(): number {{ return 50; }}
Return type mismatch.
TypeScript
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
foo = 19
foo=19
No spaces.
Shell
class Item {{ int a; }} obj.a=5;
class Item {{ public int a; }} obj.a=5;
Make field public.
Java
44b = 10
b44 = 10
Variable cannot start with digit.
Python
'65' + 13
65 + 13
Avoid string coercion.
JavaScript
if z = 50:
if z == 50:
Use == for comparison.
Python
list[72]
if (length(list) >= 72) list[72]
Check length.
R
random.sqrt(77)
import random random.sqrt(77)
Import module first.
Python
'output' + 8
'output' + 8.to_s
Convert int.
Ruby
print 'hello'
print('hello')
print needs parentheses.
Python
INSERT INTO users VALUES ('hello',20)
INSERT INTO users (id, status) VALUES ('hello',20);
Specify columns.
SQL
WHERE status = '26'
WHERE status = 26
Don't quote integer.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
my @arr = (76,58,87);
my @arr = (76,58,87);
Correct.
Perl
// comment
/* comment */
Use /* */.
CSS
def handle(x): return x + 1
def handle(x): return x + 1
Correct.
Python
if ($temp = 61) {{}}
if ($temp -eq 61) {{}}
Use -eq.
PowerShell
values.forEach(function(a) {{ console.log(a); }})
values.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
class Product {{ int x; }};
class Product {{ public: int x; }};
Make public.
C++
data(33)
if length(data) >= 33, data(33), end
Check length.
MATLAB
assert x > 19
assert x > 19
Correct.
Python
SELECT * FROM products WHRE status=71;
SELECT * FROM products WHERE status=71;
Fix WHERE.
SQL