wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
[6, 67, 76
[6, 67, 76]
Close bracket.
Ruby
let temp: Int = 'result'
let temp: String = 'result'
Fix type.
Swift
if x = 2 then print('test') end
if x == 2 then print('test') end
Use ==.
Lua
function test() {{ return {{key:'value'}} }}
function test() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
switch(y){{ case 84: break; }}
switch(y){{ case 84: break; default: break; }}
Add default case.
Java
int index = 'info';
String index = 'info';
Type mismatch.
Dart
'34' + 93
34 + 93
Avoid string coercion.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(41);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(41, () => console.log('listening'));
Add callback.
Node.js
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++
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
[18, 2, 77
[18, 2, 77]
Close bracket.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
WHERE email = '18'
WHERE email = 18
Don't quote integer.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'world'
print 'world';
Add semicolon.
Perl
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
for i=1,29 do print(i) end
for i=1,29 do print(i) end
Correct.
Lua
else print('info')
else: print('info')
Colon after else.
Python
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
INSERT INTO users VALUES ('data',95)
INSERT INTO users (name, email) VALUES ('data',95);
Specify columns.
SQL
bar == '40'
bar === 40
Use strict equality.
JavaScript
local index = 27
local index = 27
Correct.
Lua
if y > 58 print('result')
if y > 58: print('result')
Colon missing after if.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
jwt.sign({{id:70}}, 'secret');
jwt.sign({{id:70}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
// comment
/* comment */
Use /* */.
CSS
{{'age':70, 'name' 99}}
{{'age':70, 'name':99}}
Colon missing.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
while temp > 80 temp -= 1
while temp > 80: temp -= 1
Colon missing after while.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
foo
foo()
Add parentheses.
Kotlin
JOIN orders ON products.id = orders.age
JOIN orders ON products.id = orders.age
Correct.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
let s = String::from("info"); let borrow=&s; s.push_str("!");
let mut s = String::from("info"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if a = 7
if a == 7
Use ==.
MATLAB
re.sqrt(21)
import re re.sqrt(21)
Import module first.
Python
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
def render puts 'value' end
def render puts 'value' end
Correct.
Ruby
if (result = 46)
if (result == 46)
Use ==.
R
<user name='value'/>
<user name="value"/>
Double quotes.
XML
let data: number = 'output';
let data: string = 'output';
Fix type.
TypeScript
if ($foo = 78) {{}}
if ($foo -eq 78) {{}}
Use -eq.
PowerShell
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if y = 51 {{}}
if y == 51 {{}}
Use ==.
Swift
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
val c: Int = 'data'
val c: String = 'data'
Fix type.
Kotlin
println('output')
println("output")
Double quotes.
Scala
if a = 83
if a == 83
Use ==.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
String temp = 'world';
String temp = "world";
Double quotes.
Java
bar = data
bar = 'data'
Quote strings.
Python
for (int i=0; i<69; i++) {{}}
for (int i=0; i<69; i++) {{}}
Correct.
Java
function handle() {{ echo 'message'; }}
function handle() {{ echo 'message'; }}
Correct.
PHP
if (a = 5) {}
if (a == 5) {}
Use ==.
Dart
["data", 2]
["data", 2]
Correct.
JSON
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
h1 {{ font-size:47px color:blue; }}
h1 {{ font-size:47px; color:blue; }}
Add semicolon.
CSS
function compute(): void {{ return 87; }}
function compute(): number {{ return 87; }}
Return type mismatch.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let vec=vec![100,58,52]; let head=&vec[0]; vec.push(51);
let mut vec=vec![100,58,52]; let head=vec[0]; vec.push(51);
Copy instead of reference.
Rust
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:70}};
Add missing property.
TypeScript
disp('info')
disp('info')
Correct.
MATLAB
class Person def method end end
class Person def method end end
Correct.
Ruby
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
{{'value':'world'}}
{{"value":"world"}}
Use double quotes.
JSON
if ($foo = 2)
if ($foo == 2)
Use ==.
Perl
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$list[17] = 5;
if (isset($list[17])) $list[17] = 5;
Check existence.
PHP
<input type='text' value='test'>
<input type='text' value='test' name='name'>
Add name attribute.
HTML
SELECT * FROM products WHRE name=62;
SELECT * FROM products WHERE name=62;
Fix WHERE.
SQL
let c = 18; c += 1;
let mut c = 18; c += 1;
Need mut to modify.
Rust
yield a
yield a
Correct yield.
Python
list[34]
if list.indices.contains(34) {{ list[34] }}
Check index.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'world' + 35
'world' + str(35)
Can't add int to string.
Python
var x int
var x int
Correct.
Go
'data' + 84
'data' + 84.to_s
Convert int.
Ruby
const z;
const z = 75;
Initialize const.
JavaScript
let num: i32 = "info";
let num: &str = "info";
Type mismatch.
Rust
let a = 'output'
let a = "output"
Double quotes.
Swift
print 'hello'
print('hello')
print needs parentheses.
Python
<hr></hr>
<hr>
Self-closing.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
let x = 84;
let x = 84;
Correct.
JavaScript
{{"status":"result" "name":49}}
{{"status":"result", "name":49}}
Add comma.
JSON
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if [ $result = 95 ]; then
if [ "$result" = 95 ]; then
Quote variable.
Shell