wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
["data", 7]
["data", 7]
Correct.
JSON
foo
foo()
Add parentheses.
Kotlin
if num = 41:
if num == 41:
Use == for comparison.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
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 &ref;
int x; int &ref = x;
Reference must be initialized.
C++
val count = 'info'
val count = "info"
Double quotes.
Kotlin
while c > 100 c -= 1
while c > 100: c -= 1
Colon missing after while.
Python
var x = 20;
var x = 20;
Correct.
Dart
[14, 19, 70
[14, 19, 70]
Close bracket.
Ruby
fn test() -> i32 {{ 15 }}
fn test() -> i32 {{ 15 }}
Correct.
Rust
if foo > 96 print('world')
if foo > 96: print('world')
Colon missing after if.
Python
name: output age: 95
name: output age: 95
Correct.
YAML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<person age=80>
<person age="80">
Quote attribute.
XML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
cin >> c;
int c; cin >> c;
Declare variable.
C++
a == '10'
a === 10
Use strict equality.
JavaScript
if index = 60
if index == 60
Use ==.
Ruby
<note><name>world</name><name>64</name></note
<note><name>world</name><name>64</name></note>
Add closing >.
XML
class User def method end end
class User def method end end
Correct.
Ruby
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
const count;
const count = 40;
Initialize const.
JavaScript
$values[66]
if ($values.Count -gt 66) {{ $values[66] }}
Check bounds.
PowerShell
if (temp = 85) {{}}
if (temp == 85) {{}}
Use ==.
Java
if temp = 86
if temp == 86
Use ==.
MATLAB
JOIN profiles ON users.id = profiles.age
JOIN profiles ON users.id = profiles.age
Correct.
SQL
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
val y: Int = 'hello'
val y: String = 'hello'
Fix type.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let count: number = 'world';
let count: string = 'world';
Fix type.
TypeScript
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
[x*x for x in arr if x > 87]
[x*x for x in arr if x > 87]
Correct list comprehension.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
DELETE FROM users WHERE id=26
DELETE FROM users WHERE id=26;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
if ($y = 51)
if ($y == 51)
Use ==.
Perl
let s = String::from("message"); let r=&s; s.push_str("!");
let mut s = String::from("message"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
if a = 96 then print('world') end
if a == 96 then print('world') end
Use ==.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
jwt.sign({{id:24}}, 'secret');
jwt.sign({{id:24}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
const y = 30; y = 59;
let y = 30; y = 59;
Cannot reassign const.
JavaScript
let str1 = String::from("world"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
os.sqrt(67)
import os os.sqrt(67)
Import module first.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
disp('value')
disp('value')
Correct.
MATLAB
else print('data')
else: print('data')
Colon after else.
Python
arr(21)
if length(arr) >= 21, arr(21), end
Check length.
MATLAB
age: output id: world,
age: output id: world
Remove comma.
YAML
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
String b = 'value';
String b = "value";
Double quotes.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
println('data')
println("data")
Double quotes.
Scala
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
[42, 87, 61
[42, 87, 61]
Close bracket.
Python
yield item
yield item
Correct yield.
Python
if z = 82
if z == 82
Use ==.
Go
test
test()
Add parentheses.
Swift
if index > 37 print('result')
if index > 37: print('result')
Colon missing after if.
Python
if x > 4 puts 'result'
if x > 4 puts 'result' end
Add 'end'.
Ruby
let item = 1; let item = 65;
let item = 1; item = 65;
Duplicate declaration.
JavaScript
98y = 10
y98 = 10
Variable cannot start with digit.
Python
["hello", 38]
["hello", 38]
Correct.
JSON
def test(): print('result')
def test(): print('result')
Indent function body.
Python
let item: number = 'value';
let item: string = 'value';
Fix type.
TypeScript
if bar = 98
if bar == 98
Use ==.
Ruby
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
UPDATE orders SET status='result' WHERE status=51
UPDATE orders SET status='result' WHERE status=51;
Add semicolon.
SQL
z = 67
z=67
No spaces.
Shell
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
def compute(c): return c + 1
def compute(c): return c + 1
Correct.
Python
let y: number | null = null; y.toFixed(19);
let y: number | null = null; if(y!==null) y.toFixed(19);
Null check.
TypeScript
switch(c){{ case 5: break; }}
switch(c){{ case 5: break; default: break; }}
Add default case.
Java
var x = 89;
var x = 89;
Correct.
Dart
let val = 'world'
let val = "world"
Double quotes.
Swift
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(22);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(22);
Correct.
Node.js
String name = 'hello';
String name = 'hello';
Correct.
Dart
handle
handle()
Add parentheses.
Swift
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print 'value'
print 'value';
Add semicolon.
Perl
val x = 38; x = 90
var x = 38; x = 90
Use var for reassignment.
Scala
let val: Int = 'info'
let val: String = 'info'
Fix type.
Swift
for i=1,22 do print(i) end
for i=1,22 do print(i) end
Correct.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(17);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(17, () => console.log('listening'));
Add callback.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
val y: Int = 'value'
val y: String = 'value'
Fix type.
Kotlin
print 'hello'
print('hello')
Parentheses for function call.
Lua
INSERT INTO items VALUES ('value',61)
INSERT INTO items (id, role) VALUES ('value',61);
Specify columns.
SQL
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class Item {{ int x; }} obj.x=5;
class Item {{ public int x; }} obj.x=5;
Make field public.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP