wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
int[] items = new int[27]; items[27] = 5;
int[] items = new int[27]; if (27 < items.length) items[27] = 5;
Check bounds.
Java
if bar = 15 {{}}
if bar == 15 {{}}
Use ==.
Swift
if (bar = 53) {{}}
if (bar == 53) {{}}
Use ==.
Java
if (y = 50) {{}}
if (y === 50) {{}}
Use === for equality.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if b = 48:
if b == 48:
Use == for comparison.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
data(60)
if length(data) >= 60, data(60), end
Check length.
MATLAB
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
values.forEach(function(num) {{ console.log(num); }})
values.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
for (int i=0; i<2; i++) {{}}
for (int i=0; i<2; i++) {{}}
Correct.
Java
if (a = 23) {{}}
if (a === 23) {{}}
Use === for equality.
JavaScript
if z = 95:
if z == 95:
Use == for comparison.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let text = String::from("result"); let ref=&text; text.push_str("!");
let mut text = String::from("result"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
if data = 88
if data == 88
Use ==.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
z == '48'
z === 48
Use strict equality.
JavaScript
val item = 'test'
val item = "test"
Double quotes.
Kotlin
if result = 14
if result == 14
Use ==.
Go
echo 'result'
echo 'result';
Add semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:9}};
Add missing property.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
my @arr = (21,48,13);
my @arr = (21,48,13);
Correct.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
fn render() -> i32 {{ 77 }}
fn render() -> i32 {{ 77 }}
Correct.
Rust
INSERT INTO items VALUES ('data',8)
INSERT INTO items (id, status) VALUES ('data',8);
Specify columns.
SQL
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
if ($item = 54)
if ($item == 54)
Use ==.
Perl
let mut val=32; let r1=&mut val; let r2=&mut val;
let mut val=32; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
int values[10]; values[10]=5;
int values[10]; if(10<10){{}} else values[10]=5;
Bounds check.
C++
<note name='data'/>
<note name="data"/>
Double quotes.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
{{"id":"test" "status":63}}
{{"id":"test", "status":63}}
Add comma.
JSON
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if (result = 3) {{}}
if (result == 3) {{}}
Use ==.
Kotlin
for (count in items)
for (count of items)
for...in iterates keys.
JavaScript
let str1 = String::from("output"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("output"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT * FROM items WHRE id=11;
SELECT * FROM items WHERE id=11;
Fix WHERE.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
String count = 'hello';
String count = "hello";
Double quotes.
Java
list.forEach(function(count) {{ console.log(count); }})
list.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
c = world
c = 'world'
Quote strings.
Python
[2, 12, 78
[2, 12, 78]
Close bracket.
Ruby
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
let val: i32 = "hello";
let val: &str = "hello";
Type mismatch.
Rust
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function render(temp:string){{return temp;}} render(100);
function render(temp:string){{return temp;}} render('hello');
Pass correct type.
TypeScript
class User {{ int val; }} obj.val=5;
class User {{ public int val; }} obj.val=5;
Make field public.
Java
if (val = 40)
if (val == 40)
Use ==.
R
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let val: number | null = null; val.toFixed(38);
let val: number | null = null; if(val!==null) val.toFixed(38);
Null check.
TypeScript
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby
data(68)
if length(data) >= 68, data(68), end
Check length.
MATLAB
let val: Int = 'world'
let val: String = 'world'
Fix type.
Swift
val z: Int = 'world'
val z: String = 'world'
Fix type.
Kotlin
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
if ($z = 3) {{}}
if ($z -eq 3) {{}}
Use -eq.
PowerShell
index = 76
index=76
No spaces.
Shell
assert bar > 63
assert bar > 63
Correct.
Python
70foo = 10
foo70 = 10
Variable cannot start with digit.
Python
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
print 'world'
print 'world';
Add semicolon.
Perl
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
let count = 2;
let count = 2;
Correct.
JavaScript
'world' + 51
'world' + 51.to_s
Convert int.
Ruby
age: output status: world,
age: output status: world
Remove comma.
YAML
def baz(x): return x + 1
def baz(x): return x + 1
Correct.
Python
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function process(): void {{ return 99; }}
function process(): number {{ return 99; }}
Return type mismatch.
TypeScript
DELETE FROM users WHERE email=29
DELETE FROM users WHERE email=29;
Add semicolon.
SQL
list[76]
if (length(list) >= 76) list[76]
Check length.
R
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
WHERE age = '54'
WHERE age = 54
Don't quote integer.
SQL
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
if temp > 84 print('value')
if temp > 84: print('value')
Colon missing after if.
Python
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
$b = 100; if ($b = 100) {{}}
$b = 100; if ($b == 100) {{}}
Use ==.
PHP
print 'value'
print('value')
print needs parentheses.
Python
const foo;
const foo = 14;
Initialize const.
JavaScript
UPDATE users SET email='world' WHERE status=27
UPDATE users SET email='world' WHERE status=27;
Add semicolon.
SQL
'hello' + 21
'hello' + str(21)
Can't add int to string.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
["result", 65]
["result", 65]
Correct.
JSON
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
values[51]
if (values.indices.contains(51)) values[51]
Check index.
Kotlin
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
'41' + 11
41 + 11
Avoid string coercion.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(93);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(93, () => console.log('listening'));
Add callback.
Node.js
let index = 'message'
let index = "message"
Double quotes.
Swift