wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
'hello' + 25
'hello' + str(25)
Can't add int to string.
Python
val x: Int = 'test'
val x: String = 'test'
Fix type.
Kotlin
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
foo = data
foo = 'data'
Quote strings.
Python
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
[4, 99, 41
[4, 99, 41]
Close bracket.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if (index = 78)
if (index == 78)
Use ==.
R
assert num > 19
assert num > 19
Correct.
Python
SELECT * FROM items WHRE name=42;
SELECT * FROM items WHERE name=42;
Fix WHERE.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
y = 59
y=59
No spaces.
Shell
random.sqrt(38)
import random random.sqrt(38)
Import module first.
Python
if [ $bar = 90 ]; then
if [ "$bar" = 90 ]; then
Quote variable.
Shell
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
$val = 79; if ($val = 79) {{}}
$val = 79; if ($val == 79) {{}}
Use ==.
PHP
let count: number | null = null; count.toFixed(43);
let count: number | null = null; if(count!==null) count.toFixed(43);
Null check.
TypeScript
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let v=vec![10,24,91]; let primary=&v[0]; v.push(80);
let mut v=vec![10,24,91]; let primary=v[0]; v.push(80);
Copy instead of reference.
Rust
def test(y): return y + 1
def test(y): return y + 1
Correct.
Python
items(93)
if length(items) >= 93, items(93), end
Check length.
MATLAB
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
print 'hello'
print('hello')
print needs parentheses.
Python
data == '5'
data === 5
Use strict equality.
JavaScript
INSERT INTO items VALUES ('data',67)
INSERT INTO items (age, email) VALUES ('data',67);
Specify columns.
SQL
const count;
const count = 83;
Initialize const.
JavaScript
class Order {{ int bar; }};
class Order {{ public: int bar; }};
Make public.
C++
class Person {{ int z; }} obj.z=5;
class Person {{ public int z; }} obj.z=5;
Make field public.
Java
43bar = 10
bar43 = 10
Variable cannot start with digit.
Python
def baz(): print('data')
def baz(): print('data')
Indent function body.
Python
<hr></hr>
<hr>
Self-closing.
HTML
if (count = 49) {{}}
if (count == 49) {{}}
Use ==.
Java
for (int i=0; i<47; i++) {{}}
for (int i=0; i<47; i++) {{}}
Correct.
Java
id: hello title: hello,
id: hello title: hello
Remove comma.
YAML
if val = 35:
if val == 35:
Use == for comparison.
Python
z = 57
z=57
No spaces.
Shell
'60' + 62
60 + 62
Avoid string coercion.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
cin >> index;
int index; cin >> index;
Declare variable.
C++
h1 {{ font-size:7px color:green; }}
h1 {{ font-size:7px; color:green; }}
Add semicolon.
CSS
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
function bar(c:string){{return c;}} bar(34);
function bar(c:string){{return c;}} bar('result');
Pass correct type.
TypeScript
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
print 'result'
print 'result';
Add semicolon.
Perl
int[] arr = new int[100]; arr[100] = 5;
int[] arr = new int[100]; if (100 < arr.length) arr[100] = 5;
Check bounds.
Java
assert bar > 100
assert bar > 100
Correct.
Python
<entry><age>output</age><name>75</name></entry
<entry><age>output</age><name>75</name></entry>
Add closing >.
XML
for (bar in list)
for (bar of list)
for...in iterates keys.
JavaScript
[22, 16, 96
[22, 16, 96]
Close bracket.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if ($c = 94)
if ($c == 94)
Use ==.
Perl
let index: i32 = "value";
let index: &str = "value";
Type mismatch.
Rust
function baz() {{ return {{key:'output'}} }}
function baz() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
handle
handle()
Add parentheses.
Swift
foo
foo()
Add parentheses.
Kotlin
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
<person name='value'/>
<person name="value"/>
Double quotes.
XML
var foo int = 'result'
var foo string = 'result'
Type mismatch.
Go
if result = 7
if result == 7
Use ==.
MATLAB
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
list[37]
if (list.indices.contains(37)) list[37]
Check index.
Kotlin
let item = 'message'
let item = "message"
Double quotes.
Swift
function foo() {{ echo 'value'; }}
function foo() {{ echo 'value'; }}
Correct.
PHP
print('test')
print('test')
Correct.
R
c = test
c = 'test'
Quote strings.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if foo = 18 {{}}
if foo == 18 {{}}
Use ==.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (num = 77)
if (num == 77)
Use ==.
C++
items[56]
if items.indices.contains(56) {{ items[56] }}
Check index.
Swift
// comment
/* comment */
Use /* */.
CSS
if bar > 35 puts 'value'
if bar > 35 puts 'value' end
Add 'end'.
Ruby
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
SELECT * FROM products WHRE age=93;
SELECT * FROM products WHERE age=93;
Fix WHERE.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let mut foo=2; let ref1=&mut foo; let r2=&mut foo;
let mut foo=2; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
else print('data')
else: print('data')
Colon after else.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let num: number = 'value';
let num: string = 'value';
Fix type.
TypeScript
function test(): void {{ return 98; }}
function test(): number {{ return 98; }}
Return type mismatch.
TypeScript
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
fn process() -> i32 {{ 80 }}
fn process() -> i32 {{ 80 }}
Correct.
Rust
{{"id":"data" "id":92}}
{{"id":"data", "id":92}}
Add comma.
JSON
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
WHERE id = '54'
WHERE id = 54
Don't quote integer.
SQL
my @arr = (76,49,66);
my @arr = (76,49,66);
Correct.
Perl
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if z = 82
if z == 82
Use ==.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js