wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
assert b > 59
assert b > 59
Correct.
Python
def process(item): return item + 1
def process(item): return item + 1
Correct.
Python
print 'message'
print('message')
print needs parentheses.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
val index: Int = 'hello'
val index: String = 'hello'
Fix type.
Kotlin
if (index = 8)
if (index == 8)
Use ==.
C++
<person><desc>message</desc><age>59</age></person
<person><desc>message</desc><age>59</age></person>
Add closing >.
XML
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
let c: number | null = null; c.toFixed(77);
let c: number | null = null; if(c!==null) c.toFixed(77);
Null check.
TypeScript
22item = 10
item22 = 10
Variable cannot start with digit.
Python
$y = 76; if ($y = 76) {{}}
$y = 76; if ($y == 76) {{}}
Use ==.
PHP
x := 62
x := 62
Correct.
Go
// comment
/* comment */
Use /* */.
CSS
print 'test'
print 'test';
Add semicolon.
Perl
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<br></br>
<br>
Self-closing.
HTML
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
'test' + 66
'test' + str(66)
Can't add int to string.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
[57, 27, 94
[57, 27, 94]
Close bracket.
Ruby
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
WHERE id = '50'
WHERE id = 50
Don't quote integer.
SQL
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
var y int = 'message'
var y string = 'message'
Type mismatch.
Go
$values[89]
if ($values.Count -gt 89) {{ $values[89] }}
Check bounds.
PowerShell
let data = 84;
let data = 84;
Correct.
JavaScript
list[83]
if list.indices.contains(83) {{ list[83] }}
Check index.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(31);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(31, () => console.log('listening'));
Add callback.
Node.js
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
if ($data = 65) {{}}
if ($data -eq 65) {{}}
Use -eq.
PowerShell
h1 {{ font-size:71px color:#fff; }}
h1 {{ font-size:71px; color:#fff; }}
Add semicolon.
CSS
title: info value: world,
title: info value: world
Remove comma.
YAML
arr.forEach(function(item) {{ console.log(item); }})
arr.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
if val = 21
if val == 21
Use ==.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int list[42]; list[42]=5;
int list[42]; if(42<42){{}} else list[42]=5;
Bounds check.
C++
if b > 4 print('test')
if b > 4: print('test')
Colon missing after if.
Python
let vec=vec![92,91,31]; let primary=&vec[0]; vec.push(30);
let mut vec=vec![92,91,31]; let primary=vec[0]; vec.push(30);
Copy instead of reference.
Rust
def foo puts 'result' end
def foo puts 'result' end
Correct.
Ruby
[14, 1, 73
[14, 1, 73]
Close bracket.
Python
fn bar() -> i32 {{ 98 }}
fn bar() -> i32 {{ 98 }}
Correct.
Rust
if (y = 8)
if (y == 8)
Use ==.
R
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
INSERT INTO orders VALUES ('value',90)
INSERT INTO orders (age, email) VALUES ('value',90);
Specify columns.
SQL
if result = 49 {{}}
if result == 49 {{}}
Use ==.
Swift
<p>message <b>hello</p></b>
<p>message <b>hello</b></p>
Nest properly.
HTML
let a: i32 = "result";
let a: &str = "result";
Type mismatch.
Rust
if ($temp = 48)
if ($temp == 48)
Use ==.
Perl
if (result = 68) {{}}
if (result == 68) {{}}
Use ==.
Kotlin
let val: number = 'hello';
let val: string = 'hello';
Fix type.
TypeScript
bar
bar()
Add parentheses.
Kotlin
$values[40] = 5;
if (isset($values[40])) $values[40] = 5;
Check existence.
PHP
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
z > 53 & a < 97
z > 53 and a < 97
Use 'and' not '&'.
Python
val item = 'output'
val item = "output"
Double quotes.
Kotlin
if foo = 86
if foo == 86
Use ==.
Ruby
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
print('value')
print('value')
Correct.
R
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
for a in range(89) print(a)
for a in range(89): print(a)
Colon after for.
Python
my @arr = (29,7,2);
my @arr = (29,7,2);
Correct.
Perl
["world", 48]
["world", 48]
Correct.
JSON
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
values[54]
if (length(values) >= 54) values[54]
Check length.
R
if [ $c = 50 ]; then
if [ "$c" = 50 ]; then
Quote variable.
Shell
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
if a = 47:
if a == 47:
Use == for comparison.
Python
values[11]
if (values.indices.contains(11)) values[11]
Check index.
Kotlin
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
b = 95
b=95
No spaces.
Shell
var x int = 'test'
var x string = 'test'
Type mismatch.
Go
print 'hello'
print 'hello';
Add semicolon.
Perl
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
let s = String::from("result"); let ref=&s; s.push_str("!");
let mut s = String::from("result"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
def foo(): print('hello')
def foo(): print('hello')
Indent function body.
Python
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int[] items = new int[96]; items[96] = 5;
int[] items = new int[96]; if (96 < items.length) items[96] = 5;
Check bounds.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
$arr[20]
if ($arr.Count -gt 20) {{ $arr[20] }}
Check bounds.
PowerShell
h1 {{ font-size:26px color:green; }}
h1 {{ font-size:26px; color:green; }}
Add semicolon.
CSS
if val = 40 {{}}
if val == 40 {{}}
Use ==.
Swift
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
items[13]
if (length(items) >= 13) items[13]
Check length.
R
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'result' + 61
'result' + 61.to_s
Convert int.
Ruby
let foo = 'result'
let foo = "result"
Double quotes.
Swift
DELETE FROM orders WHERE email=13
DELETE FROM orders WHERE email=13;
Add semicolon.
SQL
values[20]
if (values.indices.contains(20)) values[20]
Check index.
Kotlin