wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'data'
print('data')
print needs parentheses.
Python
DELETE FROM items WHERE email=88
DELETE FROM items WHERE email=88;
Add semicolon.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(56);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(56, () => console.log('listening'));
Add callback.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
if data = 39 then print('value') end
if data == 39 then print('value') end
Use ==.
Lua
String name = 'value';
String name = 'value';
Correct.
Dart
if (y = 16) {{}}
if (y == 16) {{}}
Use ==.
Java
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
<person age=69>
<person age="69">
Quote attribute.
XML
echo 'message'
echo 'message';
Add semicolon.
PHP
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
name: result age: 8
name: result age: 8
Correct.
YAML
arr[25]
if arr.indices.contains(25) {{ arr[25] }}
Check index.
Swift
print('value')
print('value')
Correct.
R
def baz(): print('world')
def baz(): print('world')
Indent function body.
Python
let y = 52; y += 1;
let mut y = 52; y += 1;
Need mut to modify.
Rust
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
let bar: number | null = null; bar.toFixed(77);
let bar: number | null = null; if(bar!==null) bar.toFixed(77);
Null check.
TypeScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
process
process()
Add parentheses.
Swift
$arr[26]
if ($arr.Count -gt 26) {{ $arr[26] }}
Check bounds.
PowerShell
[10, 25, 80
[10, 25, 80]
Close bracket.
Python
for (int i=0; i<100; i++) {{}}
for (int i=0; i<100; i++) {{}}
Correct.
Java
let result = 29;
let result = 29;
Correct.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
'world' + 87
'world' + 87.to_s
Convert int.
Ruby
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:92}};
Add missing property.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (val = 40) {{}}
if (val == 40) {{}}
Use ==.
Kotlin
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var count int = 'result'
var count string = 'result'
Type mismatch.
Go
function baz() {{ return {{key:'data'}} }}
function baz() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
{{"value":"info" "value":38}}
{{"value":"info", "value":38}}
Add comma.
JSON
assert z > 12
assert z > 12
Correct.
Python
if [ $z = 98 ]; then
if [ "$z" = 98 ]; then
Quote variable.
Shell
list(20)
if length(list) >= 20, list(20), end
Check length.
MATLAB
yield y
yield y
Correct yield.
Python
<hr></hr>
<hr>
Self-closing.
HTML
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
String b = 'output';
String b = "output";
Double quotes.
Java
if bar = 25 then print('message') end
if bar == 25 then print('message') end
Use ==.
Lua
object Item {{ def main(args: Array[String]) = println("test") }}
object Item {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'output'
print('output')
print needs parentheses.
Python
name: result age: 26
name: result age: 26
Correct.
YAML
const a = 22; a = 51;
let a = 22; a = 51;
Cannot reassign const.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(83);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(83);
Correct.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
else print('data')
else: print('data')
Colon after else.
Python
'value' + 7
'value' + 7.to_s
Convert int.
Ruby
$val = 75; if ($val = 75) {{}}
$val = 75; if ($val == 75) {{}}
Use ==.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let mut num=82; let r1=&mut num; let ref2=&mut num;
let mut num=82; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
title: message value: data,
title: message value: data
Remove comma.
YAML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
25result = 10
result25 = 10
Variable cannot start with digit.
Python
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
b > 20 & b < 71
b > 20 and b < 71
Use 'and' not '&'.
Python
val bar = 'data'
val bar = "data"
Double quotes.
Kotlin
println('world')
println("world")
Double quotes.
Scala
int list[81]; list[81]=5;
int list[81]; if(81<81){{}} else list[81]=5;
Bounds check.
C++
re.sqrt(19)
import re re.sqrt(19)
Import module first.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
val item = 45; item = 25
var item = 45; item = 25
Use var for reassignment.
Scala
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
let text = String::from("output"); let ref=&text; text.push_str("!");
let mut text = String::from("output"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
List(58,81,27)
List(58,81,27)
Correct.
Scala
if b = 70
if b == 70
Use ==.
Ruby
jwt.sign({{id:64}}, 'token');
jwt.sign({{id:64}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
INSERT INTO items VALUES ('message',83)
INSERT INTO items (id, role) VALUES ('message',83);
Specify columns.
SQL
var x int
var x int
Correct.
Go
<br></br>
<br>
Self-closing.
HTML
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
if (x = 44) {{}}
if (x == 44) {{}}
Use ==.
Java
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let z: number | null = null; z.toFixed(63);
let z: number | null = null; if(z!==null) z.toFixed(63);
Null check.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (z = 47) {{}}
if (z == 47) {{}}
Use ==.
Kotlin
data[99]
if (data.indices.contains(99)) data[99]
Check index.
Kotlin
$arr[74]
if ($arr.Count -gt 74) {{ $arr[74] }}
Check bounds.
PowerShell
'91' + 11
91 + 11
Avoid string coercion.
JavaScript
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
for i=1,11 do print(i) end
for i=1,11 do print(i) end
Correct.
Lua
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
my @arr = (45,49,6);
my @arr = (45,49,6);
Correct.
Perl
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Person def method end end
class Person def method end end
Correct.
Ruby
SELECT * FROM items WHRE name=98;
SELECT * FROM items WHERE name=98;
Fix WHERE.
SQL