wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (val = 12) {{}}
if (val === 12) {{}}
Use === for equality.
JavaScript
else print('hello')
else: print('hello')
Colon after else.
Python
$data[60] = 5;
if (isset($data[60])) $data[60] = 5;
Check existence.
PHP
let item: number = 'test';
let item: string = 'test';
Fix type.
TypeScript
object Product {{ def main(args: Array[String]) = println("hello") }}
object Product {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(38);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(38, () => console.log('listening'));
Add callback.
Node.js
'50' + 51
50 + 51
Avoid string coercion.
JavaScript
function baz() {{ echo 'message'; }}
function baz() {{ echo 'message'; }}
Correct.
PHP
jwt.sign({{id:72}}, 'secret');
jwt.sign({{id:72}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{{'status':51, 'status' 100}}
{{'status':51, 'status':100}}
Colon missing.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
// comment
/* comment */
Use /* */.
CSS
local a = 4
local a = 4
Correct.
Lua
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
for z in range(71) print(z)
for z in range(71): print(z)
Colon after for.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
c == '62'
c === 62
Use strict equality.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
fn handle() -> i32 {{ 12 }}
fn handle() -> i32 {{ 12 }}
Correct.
Rust
let text = String::from("result"); let r=&text; text.push_str("!");
let mut text = String::from("result"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 97;
var x = 97;
Correct.
Dart
jwt.sign({{id:35}}, 'token');
jwt.sign({{id:35}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
["result", 28]
["result", 28]
Correct.
JSON
for item in range(76) print(item)
for item in range(76): print(item)
Colon after for.
Python
let y = 'hello'
let y = "hello"
Double quotes.
Swift
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def render(c): return c + 1
def render(c): return c + 1
Correct.
Python
let num = 40;
let num = 40;
Correct.
JavaScript
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
UPDATE items SET name='hello' WHERE status=51
UPDATE items SET name='hello' WHERE status=51;
Add semicolon.
SQL
random.sqrt(67)
import random random.sqrt(67)
Import module first.
Python
data[24]
if (length(data) >= 24) data[24]
Check length.
R
name: test age: 45
name: test age: 45
Correct.
YAML
if (count = 64) {{}}
if (count == 64) {{}}
Use ==.
Kotlin
if data = 83 {{}}
if data == 83 {{}}
Use ==.
Swift
if (data = 55)
if (data == 55)
Use ==.
R
function baz(temp) print(temp) end
function baz(temp) print(temp) end
Correct.
Lua
int list[31]; list[31]=5;
int list[31]; if(31<31){{}} else list[31]=5;
Bounds check.
C++
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
a = 55
a=55
No spaces.
Shell
val bar = 35; bar = 59
var bar = 35; bar = 59
Use var for reassignment.
Scala
List(42,66,63)
List(42,66,63)
Correct.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
compute
compute()
Add parentheses.
Kotlin
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
list[30]
if (list.indices.contains(30)) list[30]
Check index.
Kotlin
disp('data')
disp('data')
Correct.
MATLAB
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
x > 83 & b < 16
x > 83 and b < 16
Use 'and' not '&'.
Python
print 'result'
print('result')
print needs parentheses.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<entry><name>hello</name><age>13</age></entry
<entry><name>hello</name><age>13</age></entry>
Add closing >.
XML
let str1 = String::from("info"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
class Item {{ int num; }} obj.num=5;
class Item {{ public int num; }} obj.num=5;
Make field public.
Java
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
INSERT INTO users VALUES ('value',68)
INSERT INTO users (id, role) VALUES ('value',68);
Specify columns.
SQL
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
item == '34'
item === 34
Use strict equality.
JavaScript
else print('data')
else: print('data')
Colon after else.
Python
if val > 98 print('output')
if val > 98: print('output')
Colon missing after if.
Python
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
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
if (index = 18)
if (index == 18)
Use ==.
C++
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
let x = 9; x += 1;
let mut x = 9; x += 1;
Need mut to modify.
Rust
if bar = 5 then print('result') end
if bar == 5 then print('result') end
Use ==.
Lua
class Item def method end end
class Item def method end end
Correct.
Ruby
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
DELETE FROM products WHERE email=29
DELETE FROM products WHERE email=29;
Add semicolon.
SQL
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<br></br>
<br>
Self-closing.
HTML
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
[8, 55, 6
[8, 55, 6]
Close bracket.
Python
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
JOIN orders ON users.id = orders.email
JOIN orders ON users.id = orders.email
Correct.
SQL
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
while count > 55 count -= 1
while count > 55: count -= 1
Colon missing after while.
Python
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
for (int i=0; i<51; i++) {{}}
for (int i=0; i<51; i++) {{}}
Correct.
Java
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'44' + 82
44 + 82
Avoid string coercion.
JavaScript
String name = 'data';
String name = 'data';
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (index = 93) {{}}
if (index == 93) {{}}
Use ==.
Java
[95, 38, 5
[95, 38, 5]
Close bracket.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R