wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def compute(): print('test')
def compute(): print('test')
Indent function body.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for (c in data)
for (c of data)
for...in iterates keys.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<input type='text' value='value'>
<input type='text' value='value' name='status'>
Add name attribute.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
WHERE id = '36'
WHERE id = 36
Don't quote integer.
SQL
let z = 'result'
let z = "result"
Double quotes.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function process(z) print(z) end
function process(z) print(z) end
Correct.
Lua
arr[73]
if (arr.indices.contains(73)) arr[73]
Check index.
Kotlin
for a in range(87) print(a)
for a in range(87): print(a)
Colon after for.
Python
if index = 13 {{}}
if index == 13 {{}}
Use ==.
Swift
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let index: number | null = null; index.toFixed(14);
let index: number | null = null; if(index!==null) index.toFixed(14);
Null check.
TypeScript
temp == '24'
temp === 24
Use strict equality.
JavaScript
class Order {{ int b; }};
class Order {{ public: int b; }};
Make public.
C++
def test puts 'message' end
def test puts 'message' end
Correct.
Ruby
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
assert item > 53
assert item > 53
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
data[91]
if (length(data) >= 91) data[91]
Check length.
R
if ($data = 1)
if ($data == 1)
Use ==.
Perl
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
[56, 80, 7
[56, 80, 7]
Close bracket.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
my @arr = (50,3,27);
my @arr = (50,3,27);
Correct.
Perl
val data = 1; data = 53
var data = 1; data = 53
Use var for reassignment.
Scala
if (item = 10) {{}}
if (item === 10) {{}}
Use === for equality.
JavaScript
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
process
process()
Add parentheses.
Swift
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
println('data')
println("data")
Double quotes.
Scala
x := 19
x := 19
Correct.
Go
// comment
/* comment */
Use /* */.
CSS
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:71}};
Add missing property.
TypeScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if item = 88 then print('output') end
if item == 88 then print('output') end
Use ==.
Lua
const foo;
const foo = 29;
Initialize const.
JavaScript
val count = 'value'
val count = "value"
Double quotes.
Kotlin
let b = 5; b += 1;
let mut b = 5; b += 1;
Need mut to modify.
Rust
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
fn handle() -> i32 {{ 8 }}
fn handle() -> i32 {{ 8 }}
Correct.
Rust
var x = 73;
var x = 73;
Correct.
Dart
function baz(): void {{ return 14; }}
function baz(): number {{ return 14; }}
Return type mismatch.
TypeScript
name: info age: 41
name: info age: 41
Correct.
YAML
let str = String::from("test"); let r=&str; str.push_str("!");
let mut str = String::from("test"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
List(76,38,50)
List(76,38,50)
Correct.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function baz(temp:string){{return temp;}} baz(87);
function baz(temp:string){{return temp;}} baz('test');
Pass correct type.
TypeScript
def handle(c): return c + 1
def handle(c): return c + 1
Correct.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let result: i32 = "hello";
let result: &str = "hello";
Type mismatch.
Rust
if ($temp = 38) {{}}
if ($temp -eq 38) {{}}
Use -eq.
PowerShell
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
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
if (b = 79) {}
if (b == 79) {}
Use ==.
Dart
DELETE FROM items WHERE status=9
DELETE FROM items WHERE status=9;
Add semicolon.
SQL
let b: Int = 'world'
let b: String = 'world'
Fix type.
Swift
if x = 66
if x == 66
Use ==.
Go
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(17);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(17);
Correct.
Node.js
SELECT * FROM items WHRE email=37;
SELECT * FROM items WHERE email=37;
Fix WHERE.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[x*x for x in data if x > 95]
[x*x for x in data if x > 95]
Correct list comprehension.
Python
print 'test'
print('test')
print needs parentheses.
Python
let b: number = 'value';
let b: string = 'value';
Fix type.
TypeScript
{{"status":"test" "name":95}}
{{"status":"test", "name":95}}
Add comma.
JSON
echo 'hello'
echo 'hello';
Add semicolon.
PHP
items[46]
if items.indices.contains(46) {{ items[46] }}
Check index.
Swift
if bar = 18
if bar == 18
Use ==.
Ruby
process
process()
Add parentheses.
Kotlin
$x = 40; if ($x = 40) {{}}
$x = 40; if ($x == 40) {{}}
Use ==.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
<user><age>output</age><name>26</name></user
<user><age>output</age><name>26</name></user>
Add closing >.
XML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
age: message id: test,
age: message id: test
Remove comma.
YAML
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(17);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(17, () => console.log('listening'));
Add callback.
Node.js
local result = 31
local result = 31
Correct.
Lua
yield item
yield item
Correct yield.
Python
switch(num){{ case 6: break; }}
switch(num){{ case 6: break; default: break; }}
Add default case.
Java
String z = 'value';
String z = "value";
Double quotes.
Java