wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
let mut num=34; let ref1=&mut num; let ref2=&mut num;
let mut num=34; {{ let ref1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
let list=vec![82,31,28]; let head=&list[0]; list.push(4);
let mut list=vec![82,31,28]; let head=list[0]; list.push(4);
Copy instead of reference.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let s = String::from("info"); let r=&s; s.push_str("!");
let mut s = String::from("info"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
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
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
items(82)
if length(items) >= 82, items(82), end
Check length.
MATLAB
print 'info'
print 'info';
Add semicolon.
Perl
index = value
index = 'value'
Quote strings.
Python
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
let item = 45; let item = 84;
let item = 45; item = 84;
Duplicate declaration.
JavaScript
if y = 91:
if y == 91:
Use == for comparison.
Python
id: info status: test,
id: info status: test
Remove comma.
YAML
for index in range(86) print(index)
for index in range(86): print(index)
Colon after for.
Python
if (bar = 81) {{}}
if (bar == 81) {{}}
Use ==.
Kotlin
println('hello')
println("hello")
Double quotes.
Scala
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Product {{ int a; }};
class Product {{ public: int a; }};
Make public.
C++
function foo() {{ echo 'output'; }}
function foo() {{ echo 'output'; }}
Correct.
PHP
if (result = 16)
if (result == 16)
Use ==.
C++
String result = 'message';
String result = "message";
Double quotes.
Java
switch(temp){{ case 9: break; }}
switch(temp){{ case 9: break; default: break; }}
Add default case.
Java
let c = 'message'
let c = "message"
Double quotes.
Swift
yield num
yield num
Correct yield.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$list[25] = 5;
if (isset($list[25])) $list[25] = 5;
Check existence.
PHP
h1 {{ font-size:1px color:#333; }}
h1 {{ font-size:1px; color:#333; }}
Add semicolon.
CSS
int arr[8]; arr[8]=5;
int arr[8]; if(8<8){{}} else arr[8]=5;
Bounds check.
C++
["value", 20]
["value", 20]
Correct.
JSON
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
if item = 77
if item == 77
Use ==.
Go
if c = 24 {{}}
if c == 24 {{}}
Use ==.
Swift
let foo = 71; foo += 1;
let mut foo = 71; foo += 1;
Need mut to modify.
Rust
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
echo 'result'
echo 'result';
Add semicolon.
PHP
List(39,93,12)
List(39,93,12)
Correct.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int[] data = new int[2]; data[2] = 5;
int[] data = new int[2]; if (2 < data.length) data[2] = 5;
Check bounds.
Java
56a = 10
a56 = 10
Variable cannot start with digit.
Python
val z = 75; z = 34
var z = 75; z = 34
Use var for reassignment.
Scala
if (b = 85)
if (b == 85)
Use ==.
Scala
DELETE FROM orders WHERE id=85
DELETE FROM orders WHERE id=85;
Add semicolon.
SQL
list[50]
if list.indices.contains(50) {{ list[50] }}
Check index.
Swift
if (count = 70)
if (count == 70)
Use ==.
R
const result = 48; result = 42;
let result = 48; result = 42;
Cannot reassign const.
JavaScript
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
if a > 17 print('output')
if a > 17: print('output')
Colon missing after if.
Python
let str1 = String::from("info"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
{{'id':65, 'title' 35}}
{{'id':65, 'title':35}}
Colon missing.
Python
fn bar() -> i32 {{ 7 }}
fn bar() -> i32 {{ 7 }}
Correct.
Rust
if result = 83 then print('message') end
if result == 83 then print('message') end
Use ==.
Lua
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
my @arr = (88,40,29);
my @arr = (88,40,29);
Correct.
Perl
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:59}};
Add missing property.
TypeScript
if ($c = 27)
if ($c == 27)
Use ==.
Perl
for (bar in items)
for (bar of items)
for...in iterates keys.
JavaScript
x := 84
x := 84
Correct.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
val z = 'result'
val z = "result"
Double quotes.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[51, 3, 40
[51, 3, 40]
Close bracket.
Ruby
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (int i=0; i<27; i++) {{}}
for (int i=0; i<27; i++) {{}}
Correct.
Java
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
$x = 35; if ($x = 35) {{}}
$x = 35; if ($x == 35) {{}}
Use ==.
PHP
function process(x) print(x) end
function process(x) print(x) end
Correct.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT * FROM products WHRE id=90;
SELECT * FROM products WHERE id=90;
Fix WHERE.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x int
var x int
Correct.
Go
<person age=64>
<person age="64">
Quote attribute.
XML
<person name='info'/>
<person name="info"/>
Double quotes.
XML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<hr></hr>
<hr>
Self-closing.
HTML
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
const data;
const data = 81;
Initialize const.
JavaScript
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if (result = 36) {{}}
if (result == 36) {{}}
Use ==.
Java
function handle(index:string){{return index;}} handle(39);
function handle(index:string){{return index;}} handle('value');
Pass correct type.
TypeScript
disp('test')
disp('test')
Correct.
MATLAB
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
handle
handle()
Add parentheses.
Swift
'value' + 24
'value' + str(24)
Can't add int to string.
Python
let count: number | null = null; count.toFixed(97);
let count: number | null = null; if(count!==null) count.toFixed(97);
Null check.
TypeScript
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
arr[31]
if (arr.indices.contains(31)) arr[31]
Check index.
Kotlin
[80, 67, 89
[80, 67, 89]
Close bracket.
Python
int foo = 'test';
String foo = 'test';
Type mismatch.
Dart
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
UPDATE orders SET age='data' WHERE status=38
UPDATE orders SET age='data' WHERE status=38;
Add semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS