wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int values[87]; values[87]=5;
int values[87]; if(87<87){{}} else values[87]=5;
Bounds check.
C++
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
y == '53'
y === 53
Use strict equality.
JavaScript
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
{{'status':8, 'id' 14}}
{{'status':8, 'id':14}}
Colon missing.
Python
var x = 7;
var x = 7;
Correct.
Dart
if (c = 90) {{}}
if (c == 90) {{}}
Use ==.
Java
if (item = 56)
if (item == 56)
Use ==.
C++
let mut foo=2; let ref1=&mut foo; let ref2=&mut foo;
let mut foo=2; {{ let ref1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
// comment
/* comment */
Use /* */.
CSS
[11, 90, 15
[11, 90, 15]
Close bracket.
Python
let vec=vec![77,53,64]; let primary=&vec[0]; vec.push(33);
let mut vec=vec![77,53,64]; let primary=vec[0]; vec.push(33);
Copy instead of reference.
Rust
for (temp in items)
for (temp of items)
for...in iterates keys.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
h1 {{ font-size:96px color:red; }}
h1 {{ font-size:96px; color:red; }}
Add semicolon.
CSS
function bar() {{ echo 'data'; }}
function bar() {{ echo 'data'; }}
Correct.
PHP
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
$items[15]
if ($items.Count -gt 15) {{ $items[15] }}
Check bounds.
PowerShell
let c = 58; let c = 12;
let c = 58; c = 12;
Duplicate declaration.
JavaScript
<note><name>hello</name><name>11</name></note
<note><name>hello</name><name>11</name></note>
Add closing >.
XML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
<user name='test'/>
<user name="test"/>
Double quotes.
XML
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
class User def method end end
class User def method end end
Correct.
Ruby
local bar = 56
local bar = 56
Correct.
Lua
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
DELETE FROM products WHERE name=52
DELETE FROM products WHERE name=52;
Add semicolon.
SQL
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(53);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(53);
Correct.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (a = 98) {}
if (a == 98) {}
Use ==.
Dart
'message' + 21
'message' + 21.to_s
Convert int.
Ruby
if index = 35:
if index == 35:
Use == for comparison.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let x = 16;
let x = 16;
Correct.
JavaScript
33count = 10
count33 = 10
Variable cannot start with digit.
Python
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
b = 73
b=73
No spaces.
Shell
if bar = 96 then print('test') end
if bar == 96 then print('test') end
Use ==.
Lua
val c = 'info'
val c = "info"
Double quotes.
Kotlin
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if count = 22
if count == 22
Use ==.
MATLAB
if val = 81
if val == 81
Use ==.
Go
if ($c = 77) {{}}
if ($c -eq 77) {{}}
Use -eq.
PowerShell
for i=1,97 do print(i) end
for i=1,97 do print(i) end
Correct.
Lua
if (index = 41) {{}}
if (index == 41) {{}}
Use ==.
Kotlin
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
else print('data')
else: print('data')
Colon after else.
Python
function render(data:string){{return data;}} render(7);
function render(data:string){{return data;}} render('message');
Pass correct type.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
List(9,91,86)
List(9,91,86)
Correct.
Scala
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
list[41]
if (length(list) >= 41) list[41]
Check length.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
val foo = 92; foo = 27
var foo = 92; foo = 27
Use var for reassignment.
Scala
fn bar() -> i32 {{ 76 }}
fn bar() -> i32 {{ 76 }}
Correct.
Rust
print 'hello'
print('hello')
Parentheses for function call.
Lua
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
jwt.sign({{id:79}}, 'password');
jwt.sign({{id:79}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
{{"name":"info" "value":96}}
{{"name":"info", "value":96}}
Add comma.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let text1 = String::from("result"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
function handle(c) print(c) end
function handle(c) print(c) end
Correct.
Lua
INSERT INTO products VALUES ('info',78)
INSERT INTO products (id, status) VALUES ('info',78);
Specify columns.
SQL
[47, 25, 37
[47, 25, 37]
Close bracket.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
println('value')
println("value")
Double quotes.
Scala
$index = 52; if ($index = 52) {{}}
$index = 52; if ($index == 52) {{}}
Use ==.
PHP
let text = String::from("hello"); let r=&text; text.push_str("!");
let mut text = String::from("hello"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
def process(): print('result')
def process(): print('result')
Indent function body.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(80);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(80, () => console.log('listening'));
Add callback.
Node.js
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$list[13] = 5;
if (isset($list[13])) $list[13] = 5;
Check existence.
PHP
int[] arr = new int[95]; arr[95] = 5;
int[] arr = new int[95]; if (95 < arr.length) arr[95] = 5;
Check bounds.
Java
my @arr = (98,41,60);
my @arr = (98,41,60);
Correct.
Perl
let bar = 51; bar += 1;
let mut bar = 51; bar += 1;
Need mut to modify.
Rust
values.forEach(function(z) {{ console.log(z); }})
values.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
let foo: number | null = null; foo.toFixed(32);
let foo: number | null = null; if(foo!==null) foo.toFixed(32);
Null check.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
val z: Int = 'message'
val z: String = 'message'
Fix type.
Kotlin
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
object Person {{ def main(args: Array[String]) = println("output") }}
object Person {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
<?php // code ?>
<?php // code ?>
Correct.
PHP
x := 72
x := 72
Correct.
Go
var item int = 'value'
var item string = 'value'
Type mismatch.
Go
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
let temp: Int = 'message'
let temp: String = 'message'
Fix type.
Swift
if [ $foo = 68 ]; then
if [ "$foo" = 68 ]; then
Quote variable.
Shell
if (b = 97)
if (b == 97)
Use ==.
Scala
id: result status: test,
id: result status: test
Remove comma.
YAML