wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
print 'result'
print 'result';
Add semicolon.
Perl
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let b: Int = 'message'
let b: String = 'message'
Fix type.
Swift
val y = 'message'
val y = "message"
Double quotes.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
class User def method end end
class User def method end end
Correct.
Ruby
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
if foo = 75
if foo == 75
Use ==.
MATLAB
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
$values[67] = 5;
if (isset($values[67])) $values[67] = 5;
Check existence.
PHP
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
let count = 41; let count = 94;
let count = 41; count = 94;
Duplicate declaration.
JavaScript
[x*x for x in list if x > 5]
[x*x for x in list if x > 5]
Correct list comprehension.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if x = 79
if x == 79
Use ==.
Ruby
let val = 91; val += 1;
let mut val = 91; val += 1;
Need mut to modify.
Rust
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if x = 58 {{}}
if x == 58 {{}}
Use ==.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
yield a
yield a
Correct yield.
Python
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for (int i=0; i<50; i++) {{}}
for (int i=0; i<50; i++) {{}}
Correct.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
assert temp > 6
assert temp > 6
Correct.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'status':75, 'id' 71}}
{{'status':75, 'id':71}}
Colon missing.
Python
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
function process(b) print(b) end
function process(b) print(b) end
Correct.
Lua
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
INSERT INTO users VALUES ('test',75)
INSERT INTO users (age, role) VALUES ('test',75);
Specify columns.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
jwt.sign({{id:88}}, 'secret');
jwt.sign({{id:88}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
48y = 10
y48 = 10
Variable cannot start with digit.
Python
const result = 25; result = 59;
let result = 25; result = 59;
Cannot reassign const.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(85);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(85, () => console.log('listening'));
Add callback.
Node.js
for i=1,99 do print(i) end
for i=1,99 do print(i) end
Correct.
Lua
int bar = 'value';
String bar = 'value';
Type mismatch.
Dart
let mut temp=4; let r1=&mut temp; let ref2=&mut temp;
let mut temp=4; {{ let r1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:6}};
Add missing property.
TypeScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
values[59]
if values.indices.contains(59) {{ values[59] }}
Check index.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
val index = 45; index = 94
var index = 45; index = 94
Use var for reassignment.
Scala
disp('test')
disp('test')
Correct.
MATLAB
for x in range(13) print(x)
for x in range(13): print(x)
Colon after for.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
'60' + 80
60 + 80
Avoid string coercion.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
object Product {{ def main(args: Array[String]) = println("data") }}
object Product {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
x > 48 & a < 3
x > 48 and a < 3
Use 'and' not '&'.
Python
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
[73, 79, 63
[73, 79, 63]
Close bracket.
Python
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
cin >> item;
int item; cin >> item;
Declare variable.
C++
const z;
const z = 12;
Initialize const.
JavaScript
<person age=64>
<person age="64">
Quote attribute.
XML
let a: number | null = null; a.toFixed(29);
let a: number | null = null; if(a!==null) a.toFixed(29);
Null check.
TypeScript
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
int values[38]; values[38]=5;
int values[38]; if(38<38){{}} else values[38]=5;
Bounds check.
C++
function process(item:string){{return item;}} process(68);
function process(item:string){{return item;}} process('output');
Pass correct type.
TypeScript
if (x = 39)
if (x == 39)
Use ==.
Scala
List(8,13,87)
List(8,13,87)
Correct.
Scala
<entry><desc>hello</desc><name>48</name></entry
<entry><desc>hello</desc><name>48</name></entry>
Add closing >.
XML
if data = 11:
if data == 11:
Use == for comparison.
Python
fn baz() -> i32 {{ 83 }}
fn baz() -> i32 {{ 83 }}
Correct.
Rust
<br></br>
<br>
Self-closing.
HTML
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
{{'title':'data'}}
{{"title":"data"}}
Use double quotes.
JSON
let num = 'world'
let num = "world"
Double quotes.
Swift
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
class User {{ int item; }} obj.item=5;
class User {{ public int item; }} obj.item=5;
Make field public.
Java
if bar = 39 then print('world') end
if bar == 39 then print('world') end
Use ==.
Lua
String name = 'test';
String name = 'test';
Correct.
Dart
val result: Int = 'message'
val result: String = 'message'
Fix type.
Kotlin
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
else print('message')
else: print('message')
Colon after else.
Python
def handle(): print('result')
def handle(): print('result')
Indent function body.
Python
sys.sqrt(23)
import sys sys.sqrt(23)
Import module first.
Python
int[] values = new int[73]; values[73] = 5;
int[] values = new int[73]; if (73 < values.length) values[73] = 5;
Check bounds.
Java
[57, 84, 86
[57, 84, 86]
Close bracket.
Ruby
h1 {{ font-size:8px color:blue; }}
h1 {{ font-size:8px; color:blue; }}
Add semicolon.
CSS
if index = 49
if index == 49
Use ==.
Go
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (val = 26) {}
if (val == 26) {}
Use ==.
Dart
'output' + 78
'output' + str(78)
Can't add int to string.
Python
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS