wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$a = 13; if ($a = 13) {{}}
$a = 13; if ($a == 13) {{}}
Use ==.
PHP
if ($index = 94)
if ($index == 94)
Use ==.
Perl
let text1 = String::from("data"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
String z = 'test';
String z = "test";
Double quotes.
Java
compute
compute()
Add parentheses.
Kotlin
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print('message')
print('message')
Correct.
R
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
JOIN profiles ON orders.id = profiles.name
JOIN profiles ON orders.id = profiles.name
Correct.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
switch(x){{ case 67: break; }}
switch(x){{ case 67: break; default: break; }}
Add default case.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
["world", 63]
["world", 63]
Correct.
JSON
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let list=vec![33,34,13]; let first=&list[0]; list.push(83);
let mut list=vec![33,34,13]; let first=list[0]; list.push(83);
Copy instead of reference.
Rust
if (x = 65)
if (x == 65)
Use ==.
C++
def compute(count): return count + 1
def compute(count): return count + 1
Correct.
Python
var b int = 'test'
var b string = 'test'
Type mismatch.
Go
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
data[12]
if (length(data) >= 12) data[12]
Check length.
R
values.forEach(function(x) {{ console.log(x); }})
values.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
compute
compute()
Add parentheses.
Swift
if ($count = 23) {{}}
if ($count -eq 23) {{}}
Use -eq.
PowerShell
class User {{ int index; }};
class User {{ public: int index; }};
Make public.
C++
items(67)
if length(items) >= 67, items(67), end
Check length.
MATLAB
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (result = 50)
if (result == 50)
Use ==.
R
echo 'test'
echo 'test';
Add semicolon.
PHP
if (y = 41) {{}}
if (y == 41) {{}}
Use ==.
Kotlin
$list[74]
if ($list.Count -gt 74) {{ $list[74] }}
Check bounds.
PowerShell
data == '11'
data === 11
Use strict equality.
JavaScript
DELETE FROM products WHERE age=47
DELETE FROM products WHERE age=47;
Add semicolon.
SQL
UPDATE orders SET name='hello' WHERE status=82
UPDATE orders SET name='hello' WHERE status=82;
Add semicolon.
SQL
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
if index > 78 puts 'world'
if index > 78 puts 'world' end
Add 'end'.
Ruby
name: result age: 21
name: result age: 21
Correct.
YAML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let a = 93;
let a = 93;
Correct.
JavaScript
let foo: i32 = "message";
let foo: &str = "message";
Type mismatch.
Rust
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
let s = String::from("output"); let borrow=&s; s.push_str("!");
let mut s = String::from("output"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
class Product {{ int num; }} obj.num=5;
class Product {{ public int num; }} obj.num=5;
Make field public.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
local a = 83
local a = 83
Correct.
Lua
data[24]
if (length(data) >= 24) data[24]
Check length.
R
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
h1 {{ font-size:47px color:#333; }}
h1 {{ font-size:47px; color:#333; }}
Add semicolon.
CSS
[x*x for x in list if x > 93]
[x*x for x in list if x > 93]
Correct list comprehension.
Python
item = test
item = 'test'
Quote strings.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
INSERT INTO users VALUES ('test',51)
INSERT INTO users (id, email) VALUES ('test',51);
Specify columns.
SQL
for b in range(41) print(b)
for b in range(41): print(b)
Colon after for.
Python
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(50);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(50);
Correct.
Node.js
let a: i32 = "data";
let a: &str = "data";
Type mismatch.
Rust
if (data = 3)
if (data == 3)
Use ==.
R
[21, 98, 34
[21, 98, 34]
Close bracket.
Python
a > 19 & y < 100
a > 19 and y < 100
Use 'and' not '&'.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
class Person {{ int c; }};
class Person {{ public: int c; }};
Make public.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
[83, 38, 5
[83, 38, 5]
Close bracket.
Ruby
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
if ($a = 74) {{}}
if ($a -eq 74) {{}}
Use -eq.
PowerShell
const y;
const y = 100;
Initialize const.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var x int
var x int
Correct.
Go
if (z = 35) {{}}
if (z === 35) {{}}
Use === for equality.
JavaScript
jwt.sign({{id:98}}, 'secret');
jwt.sign({{id:98}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
fn compute() -> i32 {{ 2 }}
fn compute() -> i32 {{ 2 }}
Correct.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
val foo = 'world'
val foo = "world"
Double quotes.
Kotlin
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
function handle(): void {{ return 42; }}
function handle(): number {{ return 42; }}
Return type mismatch.
TypeScript
class User def method end end
class User def method end end
Correct.
Ruby
<p>info <b>world</p></b>
<p>info <b>world</b></p>
Nest properly.
HTML
println('info')
println("info")
Double quotes.
Scala
function bar() {{ echo 'result'; }}
function bar() {{ echo 'result'; }}
Correct.
PHP
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
WHERE age = '83'
WHERE age = 83
Don't quote integer.
SQL
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for (temp in list)
for (temp of list)
for...in iterates keys.
JavaScript
if temp = 100
if temp == 100
Use ==.
Ruby
if c = 43
if c == 43
Use ==.
MATLAB
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
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
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
if val > 85 print('message')
if val > 85: print('message')
Colon missing after if.
Python