wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
name: value age: 14
name: value age: 14
Correct.
YAML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
bar = 17
bar=17
No spaces.
Shell
'data' + 79
'data' + 79.to_s
Convert int.
Ruby
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
val y: Int = 'info'
val y: String = 'info'
Fix type.
Kotlin
let x: number | null = null; x.toFixed(88);
let x: number | null = null; if(x!==null) x.toFixed(88);
Null check.
TypeScript
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
echo 'output'
echo 'output';
Add semicolon.
PHP
disp('data')
disp('data')
Correct.
MATLAB
for c in range(16) print(c)
for c in range(16): print(c)
Colon after for.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(57);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(57, () => console.log('listening'));
Add callback.
Node.js
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
List(8,56,92)
List(8,56,92)
Correct.
Scala
64temp = 10
temp64 = 10
Variable cannot start with digit.
Python
if bar = 7
if bar == 7
Use ==.
Go
function compute(): void {{ return 2; }}
function compute(): number {{ return 2; }}
Return type mismatch.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
h1 {{ font-size:64px color:#fff; }}
h1 {{ font-size:64px; color:#fff; }}
Add semicolon.
CSS
yield z
yield z
Correct yield.
Python
int[] items = new int[91]; items[91] = 5;
int[] items = new int[91]; if (91 < items.length) items[91] = 5;
Check bounds.
Java
if index = 10:
if index == 10:
Use == for comparison.
Python
let c: i32 = "info";
let c: &str = "info";
Type mismatch.
Rust
if (count = 12) {{}}
if (count == 12) {{}}
Use ==.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(76);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(76);
Correct.
Node.js
my @arr = (63,66,28);
my @arr = (63,66,28);
Correct.
Perl
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for i=1,17 do print(i) end
for i=1,17 do print(i) end
Correct.
Lua
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:11}};
Add missing property.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
def handle(a): return a + 1
def handle(a): return a + 1
Correct.
Python
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
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
if [ $c = 18 ]; then
if [ "$c" = 18 ]; then
Quote variable.
Shell
WHERE name = '64'
WHERE name = 64
Don't quote integer.
SQL
c == '84'
c === 84
Use strict equality.
JavaScript
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
class Person {{ int bar; }};
class Person {{ public: int bar; }};
Make public.
C++
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
a > 20 & b < 90
a > 20 and b < 90
Use 'and' not '&'.
Python
JOIN profiles ON items.id = profiles.email
JOIN profiles ON items.id = profiles.email
Correct.
SQL
var num int = 'data'
var num string = 'data'
Type mismatch.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
if count = 74
if count == 74
Use ==.
Ruby
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print('world')
print('world')
Correct.
R
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
// comment
/* comment */
Use /* */.
CSS
for (z in values)
for (z of values)
for...in iterates keys.
JavaScript
let x = 'result'
let x = "result"
Double quotes.
Swift
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
if temp = 95 then print('output') end
if temp == 95 then print('output') end
Use ==.
Lua
UPDATE orders SET id='value' WHERE role=98
UPDATE orders SET id='value' WHERE role=98;
Add semicolon.
SQL
$foo = 37; if ($foo = 37) {{}}
$foo = 37; if ($foo == 37) {{}}
Use ==.
PHP
'value' + 23
'value' + str(23)
Can't add int to string.
Python
random.sqrt(61)
import random random.sqrt(61)
Import module first.
Python
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
<br></br>
<br>
Self-closing.
HTML
if num = 85 {{}}
if num == 85 {{}}
Use ==.
Swift
var x = 92;
var x = 92;
Correct.
Dart
for (int i=0; i<19; i++) {{}}
for (int i=0; i<19; i++) {{}}
Correct.
Java
val y = 97; y = 16
var y = 97; y = 16
Use var for reassignment.
Scala
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let vec=vec![44,69,65]; let first=&vec[0]; vec.push(41);
let mut vec=vec![44,69,65]; let first=vec[0]; vec.push(41);
Copy instead of reference.
Rust
val b = 'value'
val b = "value"
Double quotes.
Kotlin
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
let num = 100; num += 1;
let mut num = 100; num += 1;
Need mut to modify.
Rust
if c = 23
if c == 23
Use ==.
MATLAB
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
list(36)
if length(list) >= 36, list(36), end
Check length.
MATLAB
class Product def method end end
class Product def method end end
Correct.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
def handle(): print('output')
def handle(): print('output')
Indent function body.
Python
int val = 'info';
String val = 'info';
Type mismatch.
Dart
[77, 93, 64
[77, 93, 64]
Close bracket.
Ruby
{{'name':19, 'name' 74}}
{{'name':19, 'name':74}}
Colon missing.
Python
jwt.sign({{id:92}}, 'token');
jwt.sign({{id:92}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
test
test()
Add parentheses.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (x = 24) {{}}
if (x == 24) {{}}
Use ==.
Java
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
["data", 30]
["data", 30]
Correct.
JSON
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[57, 97, 84
[57, 97, 84]
Close bracket.
Python
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
list[77]
if (length(list) >= 77) list[77]
Check length.
R
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
<user><desc>world</desc><age>31</age></user
<user><desc>world</desc><age>31</age></user>
Add closing >.
XML
INSERT INTO items VALUES ('result',27)
INSERT INTO items (age, email) VALUES ('result',27);
Specify columns.
SQL
let item = 81;
let item = 81;
Correct.
JavaScript
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML