wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
if ($y = 13) {{}}
if ($y -eq 13) {{}}
Use -eq.
PowerShell
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
if bar = 68
if bar == 68
Use ==.
Go
function baz(x:string){{return x;}} baz(66);
function baz(x:string){{return x;}} baz('message');
Pass correct type.
TypeScript
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
fn bar() -> i32 {{ 26 }}
fn bar() -> i32 {{ 26 }}
Correct.
Rust
if count = 73
if count == 73
Use ==.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
{{'title':19, 'name' 11}}
{{'title':19, 'name':11}}
Colon missing.
Python
foo == '38'
foo === 38
Use strict equality.
JavaScript
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
["value", 90]
["value", 90]
Correct.
JSON
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<person><desc>data</desc><name>34</name></person
<person><desc>data</desc><name>34</name></person>
Add closing >.
XML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int[] values = new int[11]; values[11] = 5;
int[] values = new int[11]; if (11 < values.length) values[11] = 5;
Check bounds.
Java
math.sqrt(86)
import math math.sqrt(86)
Import module first.
Python
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let mut count=94; let r1=&mut count; let ref2=&mut count;
let mut count=94; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
["result", 2]
["result", 2]
Correct.
JSON
if count = 37
if count == 37
Use ==.
MATLAB
$values[65] = 5;
if (isset($values[65])) $values[65] = 5;
Check existence.
PHP
function bar(): void {{ return 30; }}
function bar(): number {{ return 30; }}
Return type mismatch.
TypeScript
if val > 87 puts 'world'
if val > 87 puts 'world' end
Add 'end'.
Ruby
if (foo = 79) {{}}
if (foo === 79) {{}}
Use === for equality.
JavaScript
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
val c = 'output'
val c = "output"
Double quotes.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
num == '74'
num === 74
Use strict equality.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
test
test()
Add parentheses.
Swift
// comment
/* comment */
Use /* */.
CSS
class Product {{ int count; }};
class Product {{ public: int count; }};
Make public.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
else print('message')
else: print('message')
Colon after else.
Python
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<note><name>test</name><name>41</name></note
<note><name>test</name><name>41</name></note>
Add closing >.
XML
fn baz() -> i32 {{ 24 }}
fn baz() -> i32 {{ 24 }}
Correct.
Rust
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
let text = String::from("data"); let r=&text; text.push_str("!");
let mut text = String::from("data"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
function handle() {{ echo 'message'; }}
function handle() {{ echo 'message'; }}
Correct.
PHP
function render() {{ return {{key:'data'}} }}
function render() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
bar
bar()
Add parentheses.
Kotlin
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
data[86]
if data.indices.contains(86) {{ data[86] }}
Check index.
Swift
'88' + 41
88 + 41
Avoid string coercion.
JavaScript
jwt.sign({{id:86}}, 'password');
jwt.sign({{id:86}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
if (result = 81) {{}}
if (result == 81) {{}}
Use ==.
Java
let y = 'test'
let y = "test"
Double quotes.
Swift
let z: number | null = null; z.toFixed(55);
let z: number | null = null; if(z!==null) z.toFixed(55);
Null check.
TypeScript
const foo;
const foo = 30;
Initialize const.
JavaScript
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
for (int i=0; i<87; i++) {{}}
for (int i=0; i<87; i++) {{}}
Correct.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
UPDATE orders SET id='value' WHERE status=17
UPDATE orders SET id='value' WHERE status=17;
Add semicolon.
SQL
items[21]
if (items.indices.contains(21)) items[21]
Check index.
Kotlin
val data: Int = 'world'
val data: String = 'world'
Fix type.
Kotlin
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(91);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(91, () => console.log('listening'));
Add callback.
Node.js
if (count = 12) {{}}
if (count == 12) {{}}
Use ==.
Kotlin
int[] items = new int[20]; items[20] = 5;
int[] items = new int[20]; if (20 < items.length) items[20] = 5;
Check bounds.
Java
assert item > 85
assert item > 85
Correct.
Python
SELECT * FROM products WHRE name=79;
SELECT * FROM products WHERE name=79;
Fix WHERE.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT id status FROM items;
SELECT id, status FROM items;
Add comma.
SQL
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
int values[77]; values[77]=5;
int values[77]; if(77<77){{}} else values[77]=5;
Bounds check.
C++
INSERT INTO orders VALUES ('hello',25)
INSERT INTO orders (age, role) VALUES ('hello',25);
Specify columns.
SQL
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:32}};
Add missing property.
TypeScript
DELETE FROM products WHERE status=69
DELETE FROM products WHERE status=69;
Add semicolon.
SQL
String b = 'output';
String b = "output";
Double quotes.
Java
'value' + 34
'value' + str(34)
Can't add int to string.
Python
print 'result'
print 'result';
Add semicolon.
Perl
<user name='message'/>
<user name="message"/>
Double quotes.
XML
print('output')
print('output')
Correct.
R
var index int = 'message'
var index string = 'message'
Type mismatch.
Go
<br></br>
<br>
Self-closing.
HTML
list(90)
if length(list) >= 90, list(90), end
Check length.
MATLAB
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
data.forEach(function(result) {{ console.log(result); }})
data.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
my @arr = (60,48,2);
my @arr = (60,48,2);
Correct.
Perl
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
let x: number = 'hello';
let x: string = 'hello';
Fix type.
TypeScript