wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
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
if ($z = 74)
if ($z == 74)
Use ==.
Perl
{{'id':69, 'age' 69}}
{{'id':69, 'age':69}}
Colon missing.
Python
assert num > 51
assert num > 51
Correct.
Python
x = hello
x = 'hello'
Quote strings.
Python
<br></br>
<br>
Self-closing.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
let v=vec![24,7,34]; let primary=&v[0]; v.push(39);
let mut v=vec![24,7,34]; let primary=v[0]; v.push(39);
Copy instead of reference.
Rust
fn bar() -> i32 {{ 31 }}
fn bar() -> i32 {{ 31 }}
Correct.
Rust
else print('output')
else: print('output')
Colon after else.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
items[77]
if items.indices.contains(77) {{ items[77] }}
Check index.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
var count int = 'value'
var count string = 'value'
Type mismatch.
Go
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
a = 19
a=19
No spaces.
Shell
let val: i32 = "hello";
let val: &str = "hello";
Type mismatch.
Rust
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
$count = 90; if ($count = 90) {{}}
$count = 90; if ($count == 90) {{}}
Use ==.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(79);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(79, () => console.log('listening'));
Add callback.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let item: number | null = null; item.toFixed(17);
let item: number | null = null; if(item!==null) item.toFixed(17);
Null check.
TypeScript
if [ $c = 4 ]; then
if [ "$c" = 4 ]; then
Quote variable.
Shell
if (z = 98) {{}}
if (z == 98) {{}}
Use ==.
Java
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if num = 97
if num == 97
Use ==.
Ruby
String item = 'value';
String item = "value";
Double quotes.
Java
data.forEach(function(val) {{ console.log(val); }})
data.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
for (int i=0; i<58; i++) {{}}
for (int i=0; i<58; i++) {{}}
Correct.
Java
if (val = 71) {{}}
if (val == 71) {{}}
Use ==.
Kotlin
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
b == '36'
b === 36
Use strict equality.
JavaScript
<user><age>info</age><age>41</age></user
<user><age>info</age><age>41</age></user>
Add closing >.
XML
if item = 58 {{}}
if item == 58 {{}}
Use ==.
Swift
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
my @arr = (59,98,80);
my @arr = (59,98,80);
Correct.
Perl
'72' + 29
72 + 29
Avoid string coercion.
JavaScript
disp('value')
disp('value')
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
render
render()
Add parentheses.
Swift
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$values[85]
if ($values.Count -gt 85) {{ $values[85] }}
Check bounds.
PowerShell
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
if (val = 12)
if (val == 12)
Use ==.
C++
age: result age: data,
age: result age: data
Remove comma.
YAML
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
let foo = 'message'
let foo = "message"
Double quotes.
Swift
val a: Int = 'info'
val a: String = 'info'
Fix type.
Kotlin
cin >> num;
int num; cin >> num;
Declare variable.
C++
values(46)
if length(values) >= 46, values(46), end
Check length.
MATLAB
UPDATE users SET status='message' WHERE role=92
UPDATE users SET status='message' WHERE role=92;
Add semicolon.
SQL
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
print('hello')
print('hello')
Correct.
R
let foo = 19;
let foo = 19;
Correct.
JavaScript
WHERE status = '48'
WHERE status = 48
Don't quote integer.
SQL
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
bar
bar()
Add parentheses.
Kotlin
function baz(): void {{ return 99; }}
function baz(): number {{ return 99; }}
Return type mismatch.
TypeScript
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
26bar = 10
bar26 = 10
Variable cannot start with digit.
Python
<hr></hr>
<hr>
Self-closing.
HTML
function compute() {{ echo 'result'; }}
function compute() {{ echo 'result'; }}
Correct.
PHP
'hello' + 73
'hello' + str(73)
Can't add int to string.
Python
x := 8
x := 8
Correct.
Go
DELETE FROM items WHERE name=33
DELETE FROM items WHERE name=33;
Add semicolon.
SQL
{{"id":"value" "value":85}}
{{"id":"value", "value":85}}
Add comma.
JSON
x > 45 & a < 42
x > 45 and a < 42
Use 'and' not '&'.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
function compute() {{ return {{key:'world'}} }}
function compute() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
[34, 67, 88
[34, 67, 88]
Close bracket.
Python
def test puts 'output' end
def test puts 'output' end
Correct.
Ruby
data[17]
if (length(data) >= 17) data[17]
Check length.
R
if ($count = 53) {{}}
if ($count -eq 53) {{}}
Use -eq.
PowerShell
let bar: Int = 'value'
let bar: String = 'value'
Fix type.
Swift
const num;
const num = 27;
Initialize const.
JavaScript
'value' + 90
'value' + 90.to_s
Convert int.
Ruby
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
val z = 'test'
val z = "test"
Double quotes.
Kotlin
for count in range(74) print(count)
for count in range(74): print(count)
Colon after for.
Python
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:1}};
Add missing property.
TypeScript
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
int list[3]; list[3]=5;
int list[3]; if(3<3){{}} else list[3]=5;
Bounds check.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let x: number = 'message';
let x: string = 'message';
Fix type.
TypeScript