wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int[] arr = new int[28]; arr[28] = 5;
int[] arr = new int[28]; if (28 < arr.length) arr[28] = 5;
Check bounds.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
int data[23]; data[23]=5;
int data[23]; if(23<23){{}} else data[23]=5;
Bounds check.
C++
random.sqrt(63)
import random random.sqrt(63)
Import module first.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
if index > 9 puts 'value'
if index > 9 puts 'value' end
Add 'end'.
Ruby
'55' + 82
55 + 82
Avoid string coercion.
JavaScript
[x*x for x in arr if x > 7]
[x*x for x in arr if x > 7]
Correct list comprehension.
Python
println('test')
println("test")
Double quotes.
Scala
jwt.sign({{id:37}}, 'secret');
jwt.sign({{id:37}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
INSERT INTO items VALUES ('output',66)
INSERT INTO items (name, status) VALUES ('output',66);
Specify columns.
SQL
<br></br>
<br>
Self-closing.
HTML
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
let mut temp=72; let r1=&mut temp; let r2=&mut temp;
let mut temp=72; {{ let r1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
if (result = 72)
if (result == 72)
Use ==.
Scala
{{"status":"info" "status":28}}
{{"status":"info", "status":28}}
Add comma.
JSON
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
else print('hello')
else: print('hello')
Colon after else.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let num: number | null = null; num.toFixed(21);
let num: number | null = null; if(num!==null) num.toFixed(21);
Null check.
TypeScript
var data int = 'hello'
var data string = 'hello'
Type mismatch.
Go
fn process() -> i32 {{ 64 }}
fn process() -> i32 {{ 64 }}
Correct.
Rust
if (result = 91) {}
if (result == 91) {}
Use ==.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
for (int i=0; i<87; i++) {{}}
for (int i=0; i<87; i++) {{}}
Correct.
Java
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$items[23] = 5;
if (isset($items[23])) $items[23] = 5;
Check existence.
PHP
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:50}};
Add missing property.
TypeScript
print('info')
print('info')
Correct.
R
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
[98, 31, 18
[98, 31, 18]
Close bracket.
Python
cin >> c;
int c; cin >> c;
Declare variable.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
SELECT * FROM users WHRE id=28;
SELECT * FROM users WHERE id=28;
Fix WHERE.
SQL
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
class Item {{ int index; }};
class Item {{ public: int index; }};
Make public.
C++
if z = 68
if z == 68
Use ==.
Ruby
let val = 40; let val = 53;
let val = 40; val = 53;
Duplicate declaration.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if ($c = 43) {{}}
if ($c -eq 43) {{}}
Use -eq.
PowerShell
function render(): void {{ return 4; }}
function render(): number {{ return 4; }}
Return type mismatch.
TypeScript
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(66);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(66);
Correct.
Node.js
foo
foo()
Add parentheses.
Kotlin
if c = 28
if c == 28
Use ==.
MATLAB
$data[17]
if ($data.Count -gt 17) {{ $data[17] }}
Check bounds.
PowerShell
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
// comment
/* comment */
Use /* */.
CSS
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let z: Int = 'info'
let z: String = 'info'
Fix type.
Swift
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
let msg = String::from("test"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("test"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
UPDATE users SET name='result' WHERE email=54
UPDATE users SET name='result' WHERE email=54;
Add semicolon.
SQL
class User def method end end
class User def method end end
Correct.
Ruby
function compute(count:string){{return count;}} compute(70);
function compute(count:string){{return count;}} compute('info');
Pass correct type.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if [ $val = 20 ]; then
if [ "$val" = 20 ]; then
Quote variable.
Shell
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
if (foo = 98) {{}}
if (foo === 98) {{}}
Use === for equality.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
<note name='message'/>
<note name="message"/>
Double quotes.
XML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
name: world age: 57
name: world age: 57
Correct.
YAML
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
while x > 93 x -= 1
while x > 93: x -= 1
Colon missing after while.
Python
assert temp > 19
assert temp > 19
Correct.
Python
item = world
item = 'world'
Quote strings.
Python
item = 61
item=61
No spaces.
Shell
h1 {{ font-size:96px color:red; }}
h1 {{ font-size:96px; color:red; }}
Add semicolon.
CSS
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if a = 39
if a == 39
Use ==.
Go
if ($y = 11)
if ($y == 11)
Use ==.
Perl
[38, 72, 3
[38, 72, 3]
Close bracket.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
for (temp in data)
for (temp of data)
for...in iterates keys.
JavaScript
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
{{'status':32, 'title' 39}}
{{'status':32, 'title':39}}
Colon missing.
Python
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
yield x
yield x
Correct yield.
Python
var x = 51;
var x = 51;
Correct.
Dart
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
x := 92
x := 92
Correct.
Go