wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if ($b = 21)
if ($b == 21)
Use ==.
Perl
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
if item = 59 then print('output') end
if item == 59 then print('output') end
Use ==.
Lua
print('output')
print('output')
Correct.
R
disp('info')
disp('info')
Correct.
MATLAB
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
'message' + 14
'message' + 14.to_s
Convert int.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$arr[45]
if ($arr.Count -gt 45) {{ $arr[45] }}
Check bounds.
PowerShell
if c = 2 {{}}
if c == 2 {{}}
Use ==.
Swift
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
values.forEach(function(num) {{ console.log(num); }})
values.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
if ($index = 40) {{}}
if ($index -eq 40) {{}}
Use -eq.
PowerShell
let index: number | null = null; index.toFixed(29);
let index: number | null = null; if(index!==null) index.toFixed(29);
Null check.
TypeScript
if (y = 44)
if (y == 44)
Use ==.
C++
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
def test(foo): return foo + 1
def test(foo): return foo + 1
Correct.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
[92, 45, 59
[92, 45, 59]
Close bracket.
Python
local temp = 83
local temp = 83
Correct.
Lua
<person age=55>
<person age="55">
Quote attribute.
XML
for (b in values)
for (b of values)
for...in iterates keys.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
arr[33]
if (length(arr) >= 33) arr[33]
Check length.
R
let v=vec![39,53,57]; let primary=&v[0]; v.push(42);
let mut v=vec![39,53,57]; let primary=v[0]; v.push(42);
Copy instead of reference.
Rust
DELETE FROM orders WHERE id=99
DELETE FROM orders WHERE id=99;
Add semicolon.
SQL
let index = 'info'
let index = "info"
Double quotes.
Swift
if val = 18
if val == 18
Use ==.
MATLAB
'message' + 81
'message' + str(81)
Can't add int to string.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='title'>
Add name attribute.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<person><age>info</age><name>87</name></person
<person><age>info</age><name>87</name></person>
Add closing >.
XML
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
int arr[91]; arr[91]=5;
int arr[91]; if(91<91){{}} else arr[91]=5;
Bounds check.
C++
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class Order def method end end
class Order def method end end
Correct.
Ruby
val temp = 'result'
val temp = "result"
Double quotes.
Kotlin
disp('value')
disp('value')
Correct.
MATLAB
fn process() -> i32 {{ 99 }}
fn process() -> i32 {{ 99 }}
Correct.
Rust
foo
foo()
Add parentheses.
Kotlin
UPDATE orders SET status='hello' WHERE role=100
UPDATE orders SET status='hello' WHERE role=100;
Add semicolon.
SQL
$y = 4; if ($y = 4) {{}}
$y = 4; if ($y == 4) {{}}
Use ==.
PHP
function foo() {{ echo 'message'; }}
function foo() {{ echo 'message'; }}
Correct.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
print 'result'
print('result')
print needs parentheses.
Python
function foo(val:string){{return val;}} foo(44);
function foo(val:string){{return val;}} foo('result');
Pass correct type.
TypeScript
let val: i32 = "info";
let val: &str = "info";
Type mismatch.
Rust
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
{{'age':33, 'title' 53}}
{{'age':33, 'title':53}}
Colon missing.
Python
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
{{"age":"test" "value":69}}
{{"age":"test", "value":69}}
Add comma.
JSON
let a = 24; a += 1;
let mut a = 24; a += 1;
Need mut to modify.
Rust
function process() {{ return {{key:'hello'}} }}
function process() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
const result;
const result = 7;
Initialize const.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
val data: Int = 'result'
val data: String = 'result'
Fix type.
Kotlin
if foo = 21 {{}}
if foo == 21 {{}}
Use ==.
Swift
function foo(): void {{ return 37; }}
function foo(): number {{ return 37; }}
Return type mismatch.
TypeScript
bar == '31'
bar === 31
Use strict equality.
JavaScript
// comment
/* comment */
Use /* */.
CSS
for (a in list)
for (a of list)
for...in iterates keys.
JavaScript
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if (temp = 45)
if (temp == 45)
Use ==.
R
age: value age: world,
age: value age: world
Remove comma.
YAML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
print 'output'
print 'output';
Add semicolon.
Perl
if temp = 69
if temp == 69
Use ==.
Ruby
values[31]
if values.indices.contains(31) {{ values[31] }}
Check index.
Swift
yield val
yield val
Correct yield.
Python
[x*x for x in arr if x > 3]
[x*x for x in arr if x > 3]
Correct list comprehension.
Python
if y = 50
if y == 50
Use ==.
Go
if a = 16:
if a == 16:
Use == for comparison.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x int = 'data'
var x string = 'data'
Type mismatch.
Go
jwt.sign({{id:90}}, 'token');
jwt.sign({{id:90}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
handle
handle()
Add parentheses.
Swift
if (data = 7) {{}}
if (data == 7) {{}}
Use ==.
Java
<input type='text' value='output'>
<input type='text' value='output' name='title'>
Add name attribute.
HTML
JOIN products ON products.id = products.email
JOIN products ON products.id = products.email
Correct.
SQL
assert index > 51
assert index > 51
Correct.
Python