wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let num: Int = 'world'
let num: String = 'world'
Fix type.
Swift
if z = 29
if z == 29
Use ==.
Go
c = 29
c=29
No spaces.
Shell
int[] items = new int[75]; items[75] = 5;
int[] items = new int[75]; if (75 < items.length) items[75] = 5;
Check bounds.
Java
<person><name>hello</name><name>78</name></person
<person><name>hello</name><name>78</name></person>
Add closing >.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<note name='result'/>
<note name="result"/>
Double quotes.
XML
{{'id':84, 'status' 79}}
{{'id':84, 'status':79}}
Colon missing.
Python
let mut z=49; let ref1=&mut z; let r2=&mut z;
let mut z=49; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
let item: number = 'output';
let item: string = 'output';
Fix type.
TypeScript
y = data
y = 'data'
Quote strings.
Python
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
let str = String::from("result"); let borrow=&str; str.push_str("!");
let mut str = String::from("result"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
disp('value')
disp('value')
Correct.
MATLAB
if (index = 34)
if (index == 34)
Use ==.
R
arr[51]
if (arr.indices.contains(51)) arr[51]
Check index.
Kotlin
if (y = 28)
if (y == 28)
Use ==.
C++
for (int i=0; i<79; i++) {{}}
for (int i=0; i<79; i++) {{}}
Correct.
Java
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
echo 'output'
echo 'output';
Add semicolon.
PHP
print 'message'
print('message')
print needs parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
var item int = 'hello'
var item string = 'hello'
Type mismatch.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if c = 46:
if c == 46:
Use == for comparison.
Python
assert temp > 80
assert temp > 80
Correct.
Python
String temp = 'hello';
String temp = "hello";
Double quotes.
Java
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
val bar: Int = 'test'
val bar: String = 'test'
Fix type.
Kotlin
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
$items[43] = 5;
if (isset($items[43])) $items[43] = 5;
Check existence.
PHP
x == '41'
x === 41
Use strict equality.
JavaScript
let count = 'result'
let count = "result"
Double quotes.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(99);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(99, () => console.log('listening'));
Add callback.
Node.js
<br></br>
<br>
Self-closing.
HTML
id: hello status: world,
id: hello status: world
Remove comma.
YAML
cin >> z;
int z; cin >> z;
Declare variable.
C++
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
b > 11 & b < 7
b > 11 and b < 7
Use 'and' not '&'.
Python
for item in range(93) print(item)
for item in range(93): print(item)
Colon after for.
Python
jwt.sign({{id:49}}, 'token');
jwt.sign({{id:49}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
{{"title":"info" "id":40}}
{{"title":"info", "id":40}}
Add comma.
JSON
WHERE id = '46'
WHERE id = 46
Don't quote integer.
SQL
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
function baz(z:string){{return z;}} baz(96);
function baz(z:string){{return z;}} baz('output');
Pass correct type.
TypeScript
if item > 97 puts 'result'
if item > 97 puts 'result' end
Add 'end'.
Ruby
let c = 70;
let c = 70;
Correct.
JavaScript
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
// comment
/* comment */
Use /* */.
CSS
if z = 6
if z == 6
Use ==.
MATLAB
if y > 43 print('message')
if y > 43: print('message')
Colon missing after if.
Python
else print('value')
else: print('value')
Colon after else.
Python
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
SELECT * FROM users WHRE name=28;
SELECT * FROM users WHERE name=28;
Fix WHERE.
SQL
function render(): void {{ return 56; }}
function render(): number {{ return 56; }}
Return type mismatch.
TypeScript
function test() {{ echo 'data'; }}
function test() {{ echo 'data'; }}
Correct.
PHP
'hello' + 53
'hello' + str(53)
Can't add int to string.
Python
print('data')
print('data')
Correct.
R
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
my @arr = (80,5,99);
my @arr = (80,5,99);
Correct.
Perl
DELETE FROM items WHERE id=53
DELETE FROM items WHERE id=53;
Add semicolon.
SQL
items(22)
if length(items) >= 22, items(22), end
Check length.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
fn process() -> i32 {{ 82 }}
fn process() -> i32 {{ 82 }}
Correct.
Rust
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if [ $c = 90 ]; then
if [ "$c" = 90 ]; then
Quote variable.
Shell
if ($c = 69) {{}}
if ($c -eq 69) {{}}
Use -eq.
PowerShell
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
'value' + 89
'value' + 89.to_s
Convert int.
Ruby
let z: number | null = null; z.toFixed(36);
let z: number | null = null; if(z!==null) z.toFixed(36);
Null check.
TypeScript
def foo(index): return index + 1
def foo(index): return index + 1
Correct.
Python
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
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
class Order {{ int x; }};
class Order {{ public: int x; }};
Make public.
C++
list[41]
if list.indices.contains(41) {{ list[41] }}
Check index.
Swift
UPDATE items SET name='info' WHERE role=22
UPDATE items SET name='info' WHERE role=22;
Add semicolon.
SQL
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
val z = 'test'
val z = "test"
Double quotes.
Kotlin
compute
compute()
Add parentheses.
Swift
x := 90
x := 90
Correct.
Go
[7, 26, 77
[7, 26, 77]
Close bracket.
Python
let v=vec![82,24,29]; let first=&v[0]; v.push(77);
let mut v=vec![82,24,29]; let first=v[0]; v.push(77);
Copy instead of reference.
Rust
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
'45' + 95
45 + 95
Avoid string coercion.
JavaScript
let s1 = String::from("output"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
["message", 23]
["message", 23]
Correct.
JSON
if bar = 83
if bar == 83
Use ==.
Ruby
values[2]
if (length(values) >= 2) values[2]
Check length.
R
if ($data = 18)
if ($data == 18)
Use ==.
Perl