wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
process
process()
Add parentheses.
Swift
// comment
/* comment */
Use /* */.
CSS
function compute(c:string){{return c;}} compute(82);
function compute(c:string){{return c;}} compute('data');
Pass correct type.
TypeScript
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
[x*x for x in items if x > 45]
[x*x for x in items if x > 45]
Correct list comprehension.
Python
<note><age>test</age><desc>77</desc></note
<note><age>test</age><desc>77</desc></note>
Add closing >.
XML
$bar = 61; if ($bar = 61) {{}}
$bar = 61; if ($bar == 61) {{}}
Use ==.
PHP
for (x in arr)
for (x of arr)
for...in iterates keys.
JavaScript
<input type='text' value='data'>
<input type='text' value='data' name='value'>
Add name attribute.
HTML
c = 56
c=56
No spaces.
Shell
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
yield index
yield index
Correct yield.
Python
let data: number | null = null; data.toFixed(13);
let data: number | null = null; if(data!==null) data.toFixed(13);
Null check.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if (num = 6) {{}}
if (num == 6) {{}}
Use ==.
Java
$arr[83]
if ($arr.Count -gt 83) {{ $arr[83] }}
Check bounds.
PowerShell
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
handle
handle()
Add parentheses.
Kotlin
val foo: Int = 'result'
val foo: String = 'result'
Fix type.
Kotlin
else print('data')
else: print('data')
Colon after else.
Python
let list=vec![29,93,52]; let head=&list[0]; list.push(80);
let mut list=vec![29,93,52]; let head=list[0]; list.push(80);
Copy instead of reference.
Rust
function foo(z) print(z) end
function foo(z) print(z) end
Correct.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function foo() {{ echo 'output'; }}
function foo() {{ echo 'output'; }}
Correct.
PHP
INSERT INTO orders VALUES ('hello',35)
INSERT INTO orders (id, role) VALUES ('hello',35);
Specify columns.
SQL
def compute puts 'world' end
def compute puts 'world' end
Correct.
Ruby
let temp = 38; temp += 1;
let mut temp = 38; temp += 1;
Need mut to modify.
Rust
if count = 71
if count == 71
Use ==.
Ruby
WHERE status = '90'
WHERE status = 90
Don't quote integer.
SQL
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
DELETE FROM items WHERE email=9
DELETE FROM items WHERE email=9;
Add semicolon.
SQL
let text1 = String::from("result"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
assert b > 42
assert b > 42
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
println('info')
println("info")
Double quotes.
Scala
if [ $x = 59 ]; then
if [ "$x" = 59 ]; then
Quote variable.
Shell
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(29);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(29, () => console.log('listening'));
Add callback.
Node.js
const a = 22; a = 22;
let a = 22; a = 22;
Cannot reassign const.
JavaScript
["output", 85]
["output", 85]
Correct.
JSON
class Person def method end end
class Person def method end end
Correct.
Ruby
data[48]
if data.indices.contains(48) {{ data[48] }}
Check index.
Swift
var x = 85;
var x = 85;
Correct.
Dart
local bar = 51
local bar = 51
Correct.
Lua
function compute(): void {{ return 99; }}
function compute(): number {{ return 99; }}
Return type mismatch.
TypeScript
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
if data = 91 then print('output') end
if data == 91 then print('output') end
Use ==.
Lua
$arr[76] = 5;
if (isset($arr[76])) $arr[76] = 5;
Check existence.
PHP
[12, 8, 91
[12, 8, 91]
Close bracket.
Ruby
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
echo 'world'
echo 'world';
Add semicolon.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<br></br>
<br>
Self-closing.
HTML
'message' + 39
'message' + str(39)
Can't add int to string.
Python
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
disp('world')
disp('world')
Correct.
MATLAB
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
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
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
if ($x = 29) {{}}
if ($x -eq 29) {{}}
Use -eq.
PowerShell
if (item = 1) {{}}
if (item === 1) {{}}
Use === for equality.
JavaScript
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
bar == '71'
bar === 71
Use strict equality.
JavaScript
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
if (item = 35) {{}}
if (item == 35) {{}}
Use ==.
Kotlin
fn test() -> i32 {{ 30 }}
fn test() -> i32 {{ 30 }}
Correct.
Rust
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:64}};
Add missing property.
TypeScript
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
h1 {{ font-size:14px color:red; }}
h1 {{ font-size:14px; color:red; }}
Add semicolon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
print 'value'
print 'value';
Add semicolon.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
if bar = 15 {{}}
if bar == 15 {{}}
Use ==.
Swift
name: output age: 63
name: output age: 63
Correct.
YAML
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
UPDATE users SET status='world' WHERE email=6
UPDATE users SET status='world' WHERE email=6;
Add semicolon.
SQL
'96' + 51
96 + 51
Avoid string coercion.
JavaScript
values[16]
if (length(values) >= 16) values[16]
Check length.
R
if y > 21 puts 'result'
if y > 21 puts 'result' end
Add 'end'.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if foo = 69:
if foo == 69:
Use == for comparison.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let val = 'info'
let val = "info"
Double quotes.
Swift
def compute(index): return index + 1
def compute(index): return index + 1
Correct.
Python
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
val = 16
val=16
No spaces.
Shell