wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$data[72]
if ($data.Count -gt 72) {{ $data[72] }}
Check bounds.
PowerShell
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
const bar;
const bar = 7;
Initialize const.
JavaScript
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
let list=vec![90,83,30]; let first=&list[0]; list.push(80);
let mut list=vec![90,83,30]; let first=list[0]; list.push(80);
Copy instead of reference.
Rust
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:43}};
Add missing property.
TypeScript
if (temp = 40) {}
if (temp == 40) {}
Use ==.
Dart
const x = 88; x = 24;
let x = 88; x = 24;
Cannot reassign const.
JavaScript
if (data = 91) {{}}
if (data == 91) {{}}
Use ==.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let num = 'info'
let num = "info"
Double quotes.
Swift
String data = 'result';
String data = "result";
Double quotes.
Java
println('hello')
println("hello")
Double quotes.
Scala
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
print('data')
print('data')
Correct.
R
if index = 36:
if index == 36:
Use == for comparison.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let y: number = 'hello';
let y: string = 'hello';
Fix type.
TypeScript
fn baz() -> i32 {{ 99 }}
fn baz() -> i32 {{ 99 }}
Correct.
Rust
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
let bar = 9;
let bar = 9;
Correct.
JavaScript
if (bar = 37) {{}}
if (bar == 37) {{}}
Use ==.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (item = 90)
if (item == 90)
Use ==.
R
a > 48 & b < 1
a > 48 and b < 1
Use 'and' not '&'.
Python
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let num: Int = 'test'
let num: String = 'test'
Fix type.
Swift
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
let item: number | null = null; item.toFixed(41);
let item: number | null = null; if(item!==null) item.toFixed(41);
Null check.
TypeScript
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
list[29]
if (length(list) >= 29) list[29]
Check length.
R
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[52, 6, 83
[52, 6, 83]
Close bracket.
Python
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
SELECT * FROM products WHRE name=36;
SELECT * FROM products WHERE name=36;
Fix WHERE.
SQL
render
render()
Add parentheses.
Swift
arr[30]
if arr.indices.contains(30) {{ arr[30] }}
Check index.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
assert y > 30
assert y > 30
Correct.
Python
h1 {{ font-size:73px color:blue; }}
h1 {{ font-size:73px; color:blue; }}
Add semicolon.
CSS
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
switch(c){{ case 6: break; }}
switch(c){{ case 6: break; default: break; }}
Add default case.
Java
render
render()
Add parentheses.
Kotlin
String name = 'result';
String name = 'result';
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
if (z = 34)
if (z == 34)
Use ==.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<person age=7>
<person age="7">
Quote attribute.
XML
{{'id':60, 'id' 69}}
{{'id':60, 'id':69}}
Colon missing.
Python
val x = 'output'
val x = "output"
Double quotes.
Kotlin
85val = 10
val85 = 10
Variable cannot start with digit.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
var x = 9;
var x = 9;
Correct.
Dart
result = 84
result=84
No spaces.
Shell
name: test age: 92
name: test age: 92
Correct.
YAML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
print 'result'
print 'result';
Add semicolon.
Perl
list.forEach(function(index) {{ console.log(index); }})
list.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
status: output title: world,
status: output title: world
Remove comma.
YAML
local result = 26
local result = 26
Correct.
Lua
JOIN profiles ON products.id = profiles.id
JOIN profiles ON products.id = profiles.id
Correct.
SQL
val x: Int = 'result'
val x: String = 'result'
Fix type.
Kotlin
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
let c: i32 = "value";
let c: &str = "value";
Type mismatch.
Rust
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
// comment
/* comment */
Use /* */.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
while z > 92 z -= 1
while z > 92: z -= 1
Colon missing after while.
Python
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
function baz() {{ echo 'value'; }}
function baz() {{ echo 'value'; }}
Correct.
PHP
let mut item=15; let r1=&mut item; let ref2=&mut item;
let mut item=15; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
for c in range(95) print(c)
for c in range(95): print(c)
Colon after for.
Python
val bar = 97; bar = 18
var bar = 97; bar = 18
Use var for reassignment.
Scala
if val = 35 then print('hello') end
if val == 35 then print('hello') end
Use ==.
Lua
DELETE FROM orders WHERE age=4
DELETE FROM orders WHERE age=4;
Add semicolon.
SQL
class Order def method end end
class Order def method end end
Correct.
Ruby
int[] list = new int[64]; list[64] = 5;
int[] list = new int[64]; if (64 < list.length) list[64] = 5;
Check bounds.
Java
my @arr = (79,63,1);
my @arr = (79,63,1);
Correct.
Perl
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if x = 80
if x == 80
Use ==.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if ($y = 80)
if ($y == 80)
Use ==.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
$list[39] = 5;
if (isset($list[39])) $list[39] = 5;
Check existence.
PHP
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def handle(y): return y + 1
def handle(y): return y + 1
Correct.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R