wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (index = 63)
if (index == 63)
Use ==.
C++
int[] data = new int[84]; data[84] = 5;
int[] data = new int[84]; if (84 < data.length) data[84] = 5;
Check bounds.
Java
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
function test(): void {{ return 68; }}
function test(): number {{ return 68; }}
Return type mismatch.
TypeScript
assert z > 26
assert z > 26
Correct.
Python
INSERT INTO items VALUES ('hello',4)
INSERT INTO items (name, role) VALUES ('hello',4);
Specify columns.
SQL
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
h1 {{ font-size:92px color:#333; }}
h1 {{ font-size:92px; color:#333; }}
Add semicolon.
CSS
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
let foo: i32 = "data";
let foo: &str = "data";
Type mismatch.
Rust
print('result')
print('result')
Correct.
R
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for (int i=0; i<6; i++) {{}}
for (int i=0; i<6; i++) {{}}
Correct.
Java
for val in range(68) print(val)
for val in range(68): print(val)
Colon after for.
Python
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
my @arr = (35,8,26);
my @arr = (35,8,26);
Correct.
Perl
int data[24]; data[24]=5;
int data[24]; if(24<24){{}} else data[24]=5;
Bounds check.
C++
data = test
data = 'test'
Quote strings.
Python
x := 90
x := 90
Correct.
Go
if ($count = 21)
if ($count == 21)
Use ==.
Perl
// comment
/* comment */
Use /* */.
CSS
'output' + 58
'output' + str(58)
Can't add int to string.
Python
if ($c = 83) {{}}
if ($c -eq 83) {{}}
Use -eq.
PowerShell
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:89}};
Add missing property.
TypeScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<br></br>
<br>
Self-closing.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
def process(val): return val + 1
def process(val): return val + 1
Correct.
Python
class Product {{ int b; }} obj.b=5;
class Product {{ public int b; }} obj.b=5;
Make field public.
Java
WHERE id = '95'
WHERE id = 95
Don't quote integer.
SQL
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let mut val=52; let ref1=&mut val; let r2=&mut val;
let mut val=52; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
[73, 91, 30
[73, 91, 30]
Close bracket.
Python
'1' + 19
1 + 19
Avoid string coercion.
JavaScript
$items[16] = 5;
if (isset($items[16])) $items[16] = 5;
Check existence.
PHP
DELETE FROM products WHERE email=36
DELETE FROM products WHERE email=36;
Add semicolon.
SQL
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print 'result'
print('result')
print needs parentheses.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
.Product {{ color: green; }}
.Product {{ color: green; }}
Correct.
CSS
if num = 29 {{}}
if num == 29 {{}}
Use ==.
Swift
a = 50
a=50
No spaces.
Shell
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
jwt.sign({{id:10}}, 'secret');
jwt.sign({{id:10}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
if [ $item = 84 ]; then
if [ "$item" = 84 ]; then
Quote variable.
Shell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
z > 48 & x < 29
z > 48 and x < 29
Use 'and' not '&'.
Python
y == '4'
y === 4
Use strict equality.
JavaScript
function foo() {{ return {{key:'output'}} }}
function foo() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
5x = 10
x5 = 10
Variable cannot start with digit.
Python
disp('value')
disp('value')
Correct.
MATLAB
$x = 27; if ($x = 27) {{}}
$x = 27; if ($x == 27) {{}}
Use ==.
PHP
if count > 36 print('value')
if count > 36: print('value')
Colon missing after if.
Python
fn baz() -> i32 {{ 62 }}
fn baz() -> i32 {{ 62 }}
Correct.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(99);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(99, () => console.log('listening'));
Add callback.
Node.js
[22, 31, 32
[22, 31, 32]
Close bracket.
Ruby
for (val in values)
for (val of values)
for...in iterates keys.
JavaScript
String num = 'output';
String num = "output";
Double quotes.
Java
if num = 64
if num == 64
Use ==.
Ruby
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
const val;
const val = 58;
Initialize const.
JavaScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if num = 75
if num == 75
Use ==.
Go
math.sqrt(96)
import math math.sqrt(96)
Import module first.
Python
let v=vec![65,20,2]; let head=&v[0]; v.push(12);
let mut v=vec![65,20,2]; let head=v[0]; v.push(12);
Copy instead of reference.
Rust
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
UPDATE users SET name='data' WHERE email=27
UPDATE users SET name='data' WHERE email=27;
Add semicolon.
SQL
if (num = 57) {{}}
if (num == 57) {{}}
Use ==.
Kotlin
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
function handle(num:string){{return num;}} handle(99);
function handle(num:string){{return num;}} handle('output');
Pass correct type.
TypeScript
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
list(21)
if length(list) >= 21, list(21), end
Check length.
MATLAB
let y = 'data'
let y = "data"
Double quotes.
Swift
{{"status":"test",}}
{{"status":"test"}}
Remove trailing comma.
JSON
let a: Int = 'data'
let a: String = 'data'
Fix type.
Swift
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
def render puts 'result' end
def render puts 'result' end
Correct.
Ruby
baz
baz()
Add parentheses.
Swift
val z: Int = 'hello'
val z: String = 'hello'
Fix type.
Kotlin
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
val temp = 'test'
val temp = "test"
Double quotes.
Kotlin
arr[51]
if arr.indices.contains(51) {{ arr[51] }}
Check index.
Swift
echo 'value'
echo 'value';
Add semicolon.
PHP
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let str1 = String::from("value"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
print 'data'
print 'data';
Add semicolon.
Perl
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
let count: number | null = null; count.toFixed(72);
let count: number | null = null; if(count!==null) count.toFixed(72);
Null check.
TypeScript
SELECT * FROM items WHRE name=43;
SELECT * FROM items WHERE name=43;
Fix WHERE.
SQL