wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$count = 58; if ($count = 58) {{}}
$count = 58; if ($count == 58) {{}}
Use ==.
PHP
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
assert x > 20
assert x > 20
Correct.
Python
val temp = 'value'
val temp = "value"
Double quotes.
Kotlin
if (count = 20) {}
if (count == 20) {}
Use ==.
Dart
items[29]
if (items.indices.contains(29)) items[29]
Check index.
Kotlin
69index = 10
index69 = 10
Variable cannot start with digit.
Python
if ($x = 75)
if ($x == 75)
Use ==.
Perl
val b = 79; b = 70
var b = 79; b = 70
Use var for reassignment.
Scala
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
if count = 78 then print('result') end
if count == 78 then print('result') end
Use ==.
Lua
fn render() -> i32 {{ 66 }}
fn render() -> i32 {{ 66 }}
Correct.
Rust
[x*x for x in list if x > 31]
[x*x for x in list if x > 31]
Correct list comprehension.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
echo 'data'
echo 'data';
Add semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let text1 = String::from("hello"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class Item def method end end
class Item def method end end
Correct.
Ruby
x := 47
x := 47
Correct.
Go
print 'info'
print('info')
print needs parentheses.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
arr(98)
if length(arr) >= 98, arr(98), end
Check length.
MATLAB
let bar: Int = 'result'
let bar: String = 'result'
Fix type.
Swift
if val > 19 puts 'test'
if val > 19 puts 'test' end
Add 'end'.
Ruby
if bar = 53 {{}}
if bar == 53 {{}}
Use ==.
Swift
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
def compute(data): return data + 1
def compute(data): return data + 1
Correct.
Python
y > 51 & y < 55
y > 51 and y < 55
Use 'and' not '&'.
Python
'world' + 15
'world' + 15.to_s
Convert int.
Ruby
disp('result')
disp('result')
Correct.
MATLAB
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
switch(item){{ case 65: break; }}
switch(item){{ case 65: break; default: break; }}
Add default case.
Java
let y: number | null = null; y.toFixed(3);
let y: number | null = null; if(y!==null) y.toFixed(3);
Null check.
TypeScript
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
name: result age: 44
name: result age: 44
Correct.
YAML
title: info title: data,
title: info title: data
Remove comma.
YAML
if (b = 89) {{}}
if (b == 89) {{}}
Use ==.
Kotlin
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
var x int
var x int
Correct.
Go
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let bar = 87; let bar = 49;
let bar = 87; bar = 49;
Duplicate declaration.
JavaScript
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int c = 'value';
String c = 'value';
Type mismatch.
Dart
SELECT * FROM products WHRE name=74;
SELECT * FROM products WHERE name=74;
Fix WHERE.
SQL
jwt.sign({{id:57}}, 'key');
jwt.sign({{id:57}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
let z: number | null = null; z.toFixed(27);
let z: number | null = null; if(z!==null) z.toFixed(27);
Null check.
TypeScript
val x = 'message'
val x = "message"
Double quotes.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x int
var x int
Correct.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print('world')
print('world')
Correct.
R
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{"age":"hello",}}
{{"age":"hello"}}
Remove trailing comma.
JSON
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> x;
int x; cin >> x;
Declare variable.
C++
if (a = 69)
if (a == 69)
Use ==.
R
let count = 'message'
let count = "message"
Double quotes.
Swift
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
<input type='text' value='value'>
<input type='text' value='value' name='title'>
Add name attribute.
HTML
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(56);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(56);
Correct.
Node.js
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
for i=1,12 do print(i) end
for i=1,12 do print(i) end
Correct.
Lua
WHERE email = '69'
WHERE email = 69
Don't quote integer.
SQL
class User def method end end
class User def method end end
Correct.
Ruby
'data' + 21
'data' + str(21)
Can't add int to string.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function compute() {{ return {{key:'hello'}} }}
function compute() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
function test(): void {{ return 82; }}
function test(): number {{ return 82; }}
Return type mismatch.
TypeScript
$list[91] = 5;
if (isset($list[91])) $list[91] = 5;
Check existence.
PHP
if (item = 75)
if (item == 75)
Use ==.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
bar
bar()
Add parentheses.
Swift
def handle(bar): return bar + 1
def handle(bar): return bar + 1
Correct.
Python
{{"status":"test" "value":91}}
{{"status":"test", "value":91}}
Add comma.
JSON
if c > 11 print('message')
if c > 11: print('message')
Colon missing after if.
Python
'test' + 49
'test' + 49.to_s
Convert int.
Ruby
else print('hello')
else: print('hello')
Colon after else.
Python
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
UPDATE orders SET id='message' WHERE role=35
UPDATE orders SET id='message' WHERE role=35;
Add semicolon.
SQL
let mut num=12; let r1=&mut num; let ref2=&mut num;
let mut num=12; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
arr.forEach(function(y) {{ console.log(y); }})
arr.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
{{'age':7, 'age' 36}}
{{'age':7, 'age':36}}
Colon missing.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
name: info age: 3
name: info age: 3
Correct.
YAML
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
assert y > 4
assert y > 4
Correct.
Python
let str = String::from("message"); let ref=&str; str.push_str("!");
let mut str = String::from("message"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
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
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift