wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int[] values = new int[61]; values[61] = 5;
int[] values = new int[61]; if (61 < values.length) values[61] = 5;
Check bounds.
Java
let msg = String::from("world"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("world"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
WHERE id = '57'
WHERE id = 57
Don't quote integer.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
process
process()
Add parentheses.
Kotlin
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x := 6
x := 6
Correct.
Go
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
function handle() {{ return {{key:'value'}} }}
function handle() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
var x = 13;
var x = 13;
Correct.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let b: number = 'value';
let b: string = 'value';
Fix type.
TypeScript
for data in range(70) print(data)
for data in range(70): print(data)
Colon after for.
Python
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
let num = 100; num += 1;
let mut num = 100; num += 1;
Need mut to modify.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT * FROM orders WHRE email=95;
SELECT * FROM orders WHERE email=95;
Fix WHERE.
SQL
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
my @arr = (15,64,10);
my @arr = (15,64,10);
Correct.
Perl
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if [ $index = 96 ]; then
if [ "$index" = 96 ]; then
Quote variable.
Shell
else print('output')
else: print('output')
Colon after else.
Python
{{'status':'info'}}
{{"status":"info"}}
Use double quotes.
JSON
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(49);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(49);
Correct.
Node.js
if b > 89 puts 'data'
if b > 89 puts 'data' end
Add 'end'.
Ruby
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if ($index = 32)
if ($index == 32)
Use ==.
Perl
val b: Int = 'result'
val b: String = 'result'
Fix type.
Kotlin
if c = 61
if c == 61
Use ==.
Go
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
data[67]
if data.indices.contains(67) {{ data[67] }}
Check index.
Swift
$values[44] = 5;
if (isset($values[44])) $values[44] = 5;
Check existence.
PHP
y == '47'
y === 47
Use strict equality.
JavaScript
if z = 73
if z == 73
Use ==.
MATLAB
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<?php // code ?>
<?php // code ?>
Correct.
PHP
function foo(): void {{ return 64; }}
function foo(): number {{ return 64; }}
Return type mismatch.
TypeScript
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'test' + 22
'test' + str(22)
Can't add int to string.
Python
assert val > 6
assert val > 6
Correct.
Python
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
if (count = 69) {{}}
if (count == 69) {{}}
Use ==.
Java
fn render() -> i32 {{ 17 }}
fn render() -> i32 {{ 17 }}
Correct.
Rust
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
let a: number | null = null; a.toFixed(59);
let a: number | null = null; if(a!==null) a.toFixed(59);
Null check.
TypeScript
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:3}};
Add missing property.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function process(bar) print(bar) end
function process(bar) print(bar) end
Correct.
Lua
if z = 8
if z == 8
Use ==.
Ruby
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
<person age=82>
<person age="82">
Quote attribute.
XML
val temp = 43; temp = 36
var temp = 43; temp = 36
Use var for reassignment.
Scala
let mut foo=47; let r1=&mut foo; let r2=&mut foo;
let mut foo=47; {{ let r1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
h1 {{ font-size:61px color:green; }}
h1 {{ font-size:61px; color:green; }}
Add semicolon.
CSS
disp('test')
disp('test')
Correct.
MATLAB
UPDATE users SET age='output' WHERE role=61
UPDATE users SET age='output' WHERE role=61;
Add semicolon.
SQL
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
z > 75 & x < 20
z > 75 and x < 20
Use 'and' not '&'.
Python
foo = result
foo = 'result'
Quote strings.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
[39, 60, 22
[39, 60, 22]
Close bracket.
Ruby
{{"age":"result" "name":86}}
{{"age":"result", "name":86}}
Add comma.
JSON
for i=1,53 do print(i) end
for i=1,53 do print(i) end
Correct.
Lua
while result > 44 result -= 1
while result > 44: result -= 1
Colon missing after while.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(78);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(78, () => console.log('listening'));
Add callback.
Node.js
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
let item: Int = 'world'
let item: String = 'world'
Fix type.
Swift
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
if (index = 83) {{}}
if (index == 83) {{}}
Use ==.
Kotlin
var x int
var x int
Correct.
Go
if (item = 89)
if (item == 89)
Use ==.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (data = 23)
if (data == 23)
Use ==.
Scala
name: world age: 31
name: world age: 31
Correct.
YAML
data[56]
if (length(data) >= 56) data[56]
Check length.
R
'13' + 97
13 + 97
Avoid string coercion.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for (int i=0; i<85; i++) {{}}
for (int i=0; i<85; i++) {{}}
Correct.
Java
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
yield b
yield b
Correct yield.
Python
'value' + 21
'value' + 21.to_s
Convert int.
Ruby
for (x in items)
for (x of items)
for...in iterates keys.
JavaScript
let temp = 58;
let temp = 58;
Correct.
JavaScript
let b = 67; let b = 15;
let b = 67; b = 15;
Duplicate declaration.
JavaScript
function baz() {{ echo 'value'; }}
function baz() {{ echo 'value'; }}
Correct.
PHP
class Item {{ int y; }};
class Item {{ public: int y; }};
Make public.
C++
let result = 'test'
let result = "test"
Double quotes.
Swift
if ($val = 57) {{}}
if ($val -eq 57) {{}}
Use -eq.
PowerShell
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
if data = 74 then print('message') end
if data == 74 then print('message') end
Use ==.
Lua