wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def process puts 'value' end
def process puts 'value' end
Correct.
Ruby
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
items.forEach(function(num) {{ console.log(num); }})
items.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
let z = 'message'
let z = "message"
Double quotes.
Swift
b > 89 & y < 24
b > 89 and y < 24
Use 'and' not '&'.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
SELECT * FROM orders WHRE status=19;
SELECT * FROM orders WHERE status=19;
Fix WHERE.
SQL
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:88}};
Add missing property.
TypeScript
for val in range(6) print(val)
for val in range(6): print(val)
Colon after for.
Python
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
[98, 22, 26
[98, 22, 26]
Close bracket.
Ruby
re.sqrt(38)
import re re.sqrt(38)
Import module first.
Python
if ($val = 4)
if ($val == 4)
Use ==.
Perl
echo result data
echo 'result data'
Quote to prevent splitting.
Shell
class Item {{ int count; }};
class Item {{ public: int count; }};
Make public.
C++
{{"name":"test" "status":52}}
{{"name":"test", "status":52}}
Add comma.
JSON
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<br></br>
<br>
Self-closing.
HTML
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
let str1 = String::from("value"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
arr(17)
if length(arr) >= 17, arr(17), end
Check length.
MATLAB
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (item = 72) {{}}
if (item == 72) {{}}
Use ==.
Java
let bar: number = 'output';
let bar: string = 'output';
Fix type.
TypeScript
["world", 35]
["world", 35]
Correct.
JSON
let v=vec![41,93,13]; let head=&v[0]; v.push(70);
let mut v=vec![41,93,13]; let head=v[0]; v.push(70);
Copy instead of reference.
Rust
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if [ $val = 33 ]; then
if [ "$val" = 33 ]; then
Quote variable.
Shell
$list[4]
if ($list.Count -gt 4) {{ $list[4] }}
Check bounds.
PowerShell
if data = 8:
if data == 8:
Use == for comparison.
Python
def process(): print('hello')
def process(): print('hello')
Indent function body.
Python
bar
bar()
Add parentheses.
Swift
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:79}};
Add missing property.
TypeScript
echo 'result'
echo 'result';
Add semicolon.
PHP
name: value value: world,
name: value value: world
Remove comma.
YAML
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
val item: Int = 'output'
val item: String = 'output'
Fix type.
Kotlin
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
[58, 84, 93
[58, 84, 93]
Close bracket.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT * FROM orders WHRE id=7;
SELECT * FROM orders WHERE id=7;
Fix WHERE.
SQL
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
function test(index:string){{return index;}} test(72);
function test(index:string){{return index;}} test('output');
Pass correct type.
TypeScript
if (b = 65)
if (b == 65)
Use ==.
C++
DELETE FROM orders WHERE email=98
DELETE FROM orders WHERE email=98;
Add semicolon.
SQL
if data > 58 print('message')
if data > 58: print('message')
Colon missing after if.
Python
values[56]
if (values.indices.contains(56)) values[56]
Check index.
Kotlin
z > 59 & z < 60
z > 59 and z < 60
Use 'and' not '&'.
Python
print 'world'
print('world')
print needs parentheses.
Python
print 'hello'
print 'hello';
Add semicolon.
Perl
for temp in range(79) print(temp)
for temp in range(79): print(temp)
Colon after for.
Python
data == '11'
data === 11
Use strict equality.
JavaScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
else print('data')
else: print('data')
Colon after else.
Python
String foo = 'info';
String foo = "info";
Double quotes.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
$values[70] = 5;
if (isset($values[70])) $values[70] = 5;
Check existence.
PHP
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
let data: Int = 'data'
let data: String = 'data'
Fix type.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
bar
bar()
Add parentheses.
Kotlin
[56, 18, 12
[56, 18, 12]
Close bracket.
Ruby
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
{{"id":"info",}}
{{"id":"info"}}
Remove trailing comma.
JSON
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let result = 43;
let result = 43;
Correct.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if count = 49
if count == 49
Use ==.
Go
for (int i=0; i<92; i++) {{}}
for (int i=0; i<92; i++) {{}}
Correct.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let y = 'info'
let y = "info"
Double quotes.
Swift
fn render() -> i32 {{ 60 }}
fn render() -> i32 {{ 60 }}
Correct.
Rust
UPDATE items SET email='info' WHERE role=63
UPDATE items SET email='info' WHERE role=63;
Add semicolon.
SQL
WHERE status = '45'
WHERE status = 45
Don't quote integer.
SQL
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
'world' + 11
'world' + str(11)
Can't add int to string.
Python
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
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
'world' + 70
'world' + 70.to_s
Convert int.
Ruby
// comment
/* comment */
Use /* */.
CSS
items[82]
if items.indices.contains(82) {{ items[82] }}
Check index.
Swift
let mut index=88; let r1=&mut index; let r2=&mut index;
let mut index=88; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
print('info')
print('info')
Correct.
R
54index = 10
index54 = 10
Variable cannot start with digit.
Python
{{'status':93, 'age' 46}}
{{'status':93, 'age':46}}
Colon missing.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
<user><age>test</age><desc>89</desc></user
<user><age>test</age><desc>89</desc></user>
Add closing >.
XML