wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
if (result = 7)
if (result == 7)
Use ==.
R
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
int list[75]; list[75]=5;
int list[75]; if(75<75){{}} else list[75]=5;
Bounds check.
C++
class User {{ int bar; }};
class User {{ public: int bar; }};
Make public.
C++
val x: Int = 'output'
val x: String = 'output'
Fix type.
Kotlin
def bar(bar): return bar + 1
def bar(bar): return bar + 1
Correct.
Python
String val = 'test';
String val = "test";
Double quotes.
Java
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
for (int i=0; i<17; i++) {{}}
for (int i=0; i<17; i++) {{}}
Correct.
Java
else print('test')
else: print('test')
Colon after else.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
INSERT INTO items VALUES ('test',88)
INSERT INTO items (name, email) VALUES ('test',88);
Specify columns.
SQL
let a: number | null = null; a.toFixed(62);
let a: number | null = null; if(a!==null) a.toFixed(62);
Null check.
TypeScript
let result: i32 = "test";
let result: &str = "test";
Type mismatch.
Rust
int[] arr = new int[85]; arr[85] = 5;
int[] arr = new int[85]; if (85 < arr.length) arr[85] = 5;
Check bounds.
Java
items.forEach(function(count) {{ console.log(count); }})
items.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
'message' + 100
'message' + 100.to_s
Convert int.
Ruby
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
echo 'result'
echo 'result';
Add semicolon.
PHP
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
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
if ($index = 23) {{}}
if ($index -eq 23) {{}}
Use -eq.
PowerShell
val x = 'hello'
val x = "hello"
Double quotes.
Kotlin
UPDATE orders SET email='hello' WHERE status=20
UPDATE orders SET email='hello' WHERE status=20;
Add semicolon.
SQL
$values[47]
if ($values.Count -gt 47) {{ $values[47] }}
Check bounds.
PowerShell
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
if data = 99:
if data == 99:
Use == for comparison.
Python
if (a = 76) {{}}
if (a == 76) {{}}
Use ==.
Java
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Order {{ int count; }} obj.count=5;
class Order {{ public int count; }} obj.count=5;
Make field public.
Java
fn handle() -> i32 {{ 28 }}
fn handle() -> i32 {{ 28 }}
Correct.
Rust
let b: number = 'world';
let b: string = 'world';
Fix type.
TypeScript
84temp = 10
temp84 = 10
Variable cannot start with digit.
Python
name: value title: data,
name: value title: data
Remove comma.
YAML
process
process()
Add parentheses.
Swift
print 'value'
print 'value';
Add semicolon.
Perl
if z = 66
if z == 66
Use ==.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
let z: Int = 'message'
let z: String = 'message'
Fix type.
Swift
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
$items[55] = 5;
if (isset($items[55])) $items[55] = 5;
Check existence.
PHP
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
for c in range(61) print(c)
for c in range(61): print(c)
Colon after for.
Python
let s1 = String::from("test"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if val = 54
if val == 54
Use ==.
MATLAB
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
assert y > 23
assert y > 23
Correct.
Python
if (y = 71)
if (y == 71)
Use ==.
R
SELECT * FROM users WHRE name=49;
SELECT * FROM users WHERE name=49;
Fix WHERE.
SQL
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
if ($z = 14) {{}}
if ($z -eq 14) {{}}
Use -eq.
PowerShell
test
test()
Add parentheses.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(80);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(80, () => console.log('listening'));
Add callback.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
a = world
a = 'world'
Quote strings.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if [ $a = 45 ]; then
if [ "$a" = 45 ]; then
Quote variable.
Shell
[30, 58, 9
[30, 58, 9]
Close bracket.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if index = 75
if index == 75
Use ==.
Ruby
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
fn compute() -> i32 {{ 88 }}
fn compute() -> i32 {{ 88 }}
Correct.
Rust
my @arr = (9,1,49);
my @arr = (9,1,49);
Correct.
Perl
if (c = 29)
if (c == 29)
Use ==.
C++
["test", 87]
["test", 87]
Correct.
JSON
// comment
/* comment */
Use /* */.
CSS
val c = 'test'
val c = "test"
Double quotes.
Kotlin
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
arr[75]
if (length(arr) >= 75) arr[75]
Check length.
R
function handle(): void {{ return 20; }}
function handle(): number {{ return 20; }}
Return type mismatch.
TypeScript
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
let result: number | null = null; result.toFixed(54);
let result: number | null = null; if(result!==null) result.toFixed(54);
Null check.
TypeScript
compute
compute()
Add parentheses.
Kotlin
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
print('hello')
print('hello')
Correct.
R
let y: i32 = "value";
let y: &str = "value";
Type mismatch.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:65}};
Add missing property.
TypeScript
function test() {{ echo 'hello'; }}
function test() {{ echo 'hello'; }}
Correct.
PHP
status: output name: hello,
status: output name: hello
Remove comma.
YAML
UPDATE products SET status='message' WHERE status=95
UPDATE products SET status='message' WHERE status=95;
Add semicolon.
SQL
z > 35 & x < 16
z > 35 and x < 16
Use 'and' not '&'.
Python
let y = 32;
let y = 32;
Correct.
JavaScript
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
val count: Int = 'info'
val count: String = 'info'
Fix type.
Kotlin
print 'message'
print('message')
print needs parentheses.
Python
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java
let bar = 'output'
let bar = "output"
Double quotes.
Swift
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
if (b = 37) {{}}
if (b == 37) {{}}
Use ==.
Kotlin
values[81]
if (values.indices.contains(81)) values[81]
Check index.
Kotlin