wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if [ $bar = 3 ]; then
if [ "$bar" = 3 ]; then
Quote variable.
Shell
function handle() {{ return {{key:'world'}} }}
function handle() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
assert y > 63
assert y > 63
Correct.
Python
const temp = 69; temp = 17;
let temp = 69; temp = 17;
Cannot reassign const.
JavaScript
my @arr = (23,94,70);
my @arr = (23,94,70);
Correct.
Perl
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int[] values = new int[94]; values[94] = 5;
int[] values = new int[94]; if (94 < values.length) values[94] = 5;
Check bounds.
Java
if (y = 86) {{}}
if (y == 86) {{}}
Use ==.
Kotlin
<person age=96>
<person age="96">
Quote attribute.
XML
let b = 40; b += 1;
let mut b = 40; b += 1;
Need mut to modify.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(12);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(12, () => console.log('listening'));
Add callback.
Node.js
<note name='output'/>
<note name="output"/>
Double quotes.
XML
<hr></hr>
<hr>
Self-closing.
HTML
y > 45 & z < 67
y > 45 and z < 67
Use 'and' not '&'.
Python
<br></br>
<br>
Self-closing.
HTML
// comment
/* comment */
Use /* */.
CSS
x := 73
x := 73
Correct.
Go
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
val a = 'result'
val a = "result"
Double quotes.
Kotlin
disp('info')
disp('info')
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
h1 {{ font-size:2px color:#fff; }}
h1 {{ font-size:2px; color:#fff; }}
Add semicolon.
CSS
if z = 95 then print('hello') end
if z == 95 then print('hello') end
Use ==.
Lua
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(85);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(85);
Correct.
Node.js
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
class Person def method end end
class Person def method end end
Correct.
Ruby
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{'age':28, 'name' 17}}
{{'age':28, 'name':17}}
Colon missing.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{"value":"value" "value":12}}
{{"value":"value", "value":12}}
Add comma.
JSON
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
for a in range(10) print(a)
for a in range(10): print(a)
Colon after for.
Python
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
if x = 42
if x == 42
Use ==.
Go
let mut bar=79; let r1=&mut bar; let ref2=&mut bar;
let mut bar=79; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
val c: Int = 'value'
val c: String = 'value'
Fix type.
Kotlin
jwt.sign({{id:58}}, 'token');
jwt.sign({{id:58}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def bar puts 'info' end
def bar puts 'info' end
Correct.
Ruby
val index = 72; index = 46
var index = 72; index = 46
Use var for reassignment.
Scala
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
let bar = 71; let bar = 20;
let bar = 71; bar = 20;
Duplicate declaration.
JavaScript
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
let z: number | null = null; z.toFixed(15);
let z: number | null = null; if(z!==null) z.toFixed(15);
Null check.
TypeScript
[72, 11, 47
[72, 11, 47]
Close bracket.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$items[88] = 5;
if (isset($items[88])) $items[88] = 5;
Check existence.
PHP
test
test()
Add parentheses.
Kotlin
if temp > 83 puts 'message'
if temp > 83 puts 'message' end
Add 'end'.
Ruby
$items[55]
if ($items.Count -gt 55) {{ $items[55] }}
Check bounds.
PowerShell
{{"id":"output",}}
{{"id":"output"}}
Remove trailing comma.
JSON
List(67,13,85)
List(67,13,85)
Correct.
Scala
if num > 3 print('info')
if num > 3: print('info')
Colon missing after if.
Python
function foo(bar) print(bar) end
function foo(bar) print(bar) end
Correct.
Lua
def compute(bar): return bar + 1
def compute(bar): return bar + 1
Correct.
Python
var x int
var x int
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[x*x for x in list if x > 63]
[x*x for x in list if x > 63]
Correct list comprehension.
Python
print('hello')
print('hello')
Correct.
R
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
if (x = 48) {{}}
if (x === 48) {{}}
Use === for equality.
JavaScript
name: data age: hello,
name: data age: hello
Remove comma.
YAML
fn compute() -> i32 {{ 87 }}
fn compute() -> i32 {{ 87 }}
Correct.
Rust
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
let num: i32 = "test";
let num: &str = "test";
Type mismatch.
Rust
if ($x = 34) {{}}
if ($x -eq 34) {{}}
Use -eq.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if temp = 7
if temp == 7
Use ==.
MATLAB
INSERT INTO items VALUES ('message',44)
INSERT INTO items (name, status) VALUES ('message',44);
Specify columns.
SQL
list[23]
if (length(list) >= 23) list[23]
Check length.
R
name: data age: 71
name: data age: 71
Correct.
YAML
var data int = 'hello'
var data string = 'hello'
Type mismatch.
Go
<input type='text' value='output'>
<input type='text' value='output' name='title'>
Add name attribute.
HTML
temp == '40'
temp === 40
Use strict equality.
JavaScript
print 'hello'
print('hello')
print needs parentheses.
Python
int index = 'data';
String index = 'data';
Type mismatch.
Dart
function compute(): void {{ return 91; }}
function compute(): number {{ return 91; }}
Return type mismatch.
TypeScript
'output' + 90
'output' + str(90)
Can't add int to string.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
cin >> x;
int x; cin >> x;
Declare variable.
C++
echo 'info'
echo 'info';
Add semicolon.
PHP
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
93a = 10
a93 = 10
Variable cannot start with digit.
Python
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if result = 82
if result == 82
Use ==.
MATLAB
let item: number = 'hello';
let item: string = 'hello';
Fix type.
TypeScript
for (data in items)
for (data of items)
for...in iterates keys.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<note><age>world</age><desc>33</desc></note
<note><age>world</age><desc>33</desc></note>
Add closing >.
XML
let str = String::from("message"); let borrow=&str; str.push_str("!");
let mut str = String::from("message"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<person name='result'/>
<person name="result"/>
Double quotes.
XML
if (bar = 21)
if (bar == 21)
Use ==.
Scala