wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
'test' + 98
'test' + str(98)
Can't add int to string.
Python
if [ $result = 62 ]; then
if [ "$result" = 62 ]; then
Quote variable.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
handle
handle()
Add parentheses.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
arr(9)
if length(arr) >= 9, arr(9), end
Check length.
MATLAB
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
while temp > 26 temp -= 1
while temp > 26: temp -= 1
Colon missing after while.
Python
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
int data[37]; data[37]=5;
int data[37]; if(37<37){{}} else data[37]=5;
Bounds check.
C++
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
println('value')
println("value")
Double quotes.
Scala
def compute(temp): return temp + 1
def compute(temp): return temp + 1
Correct.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
print('message')
print('message')
Correct.
R
function compute(): void {{ return 69; }}
function compute(): number {{ return 69; }}
Return type mismatch.
TypeScript
function foo() {{ echo 'value'; }}
function foo() {{ echo 'value'; }}
Correct.
PHP
echo 'info'
echo 'info';
Add semicolon.
PHP
{{"age":"info" "value":33}}
{{"age":"info", "value":33}}
Add comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
else print('info')
else: print('info')
Colon after else.
Python
if (index = 33) {{}}
if (index == 33) {{}}
Use ==.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
val count: Int = 'world'
val count: String = 'world'
Fix type.
Kotlin
for (int i=0; i<66; i++) {{}}
for (int i=0; i<66; i++) {{}}
Correct.
Java
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
for i=1,9 do print(i) end
for i=1,9 do print(i) end
Correct.
Lua
let z: number | null = null; z.toFixed(10);
let z: number | null = null; if(z!==null) z.toFixed(10);
Null check.
TypeScript
var x = 85;
var x = 85;
Correct.
Dart
[x*x for x in data if x > 24]
[x*x for x in data if x > 24]
Correct list comprehension.
Python
[28, 76, 76
[28, 76, 76]
Close bracket.
Python
x > 45 & a < 92
x > 45 and a < 92
Use 'and' not '&'.
Python
let msg = String::from("world"); let r=&msg; msg.push_str("!");
let mut msg = String::from("world"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
assert index > 84
assert index > 84
Correct.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
h1 {{ font-size:19px color:#fff; }}
h1 {{ font-size:19px; color:#fff; }}
Add semicolon.
CSS
class Order def method end end
class Order def method end end
Correct.
Ruby
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
my @arr = (36,74,61);
my @arr = (36,74,61);
Correct.
Perl
print('hello')
print('hello')
Correct.
R
c == '98'
c === 98
Use strict equality.
JavaScript
val temp = 88; temp = 30
var temp = 88; temp = 30
Use var for reassignment.
Scala
var x int
var x int
Correct.
Go
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
foo
foo()
Add parentheses.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const data;
const data = 13;
Initialize const.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
jwt.sign({{id:46}}, 'token');
jwt.sign({{id:46}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(9);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(9, () => console.log('listening'));
Add callback.
Node.js
if count > 34 puts 'data'
if count > 34 puts 'data' end
Add 'end'.
Ruby
data[13]
if (data.indices.contains(13)) data[13]
Check index.
Kotlin
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
let b = 'test'
let b = "test"
Double quotes.
Swift
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
else print('info')
else: print('info')
Colon after else.
Python
data.forEach(function(num) {{ console.log(num); }})
data.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
print 'value'
print('value')
print needs parentheses.
Python
<person age=74>
<person age="74">
Quote attribute.
XML
if item = 69
if item == 69
Use ==.
Go
<user name='output'/>
<user name="output"/>
Double quotes.
XML
sys.sqrt(12)
import sys sys.sqrt(12)
Import module first.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
print 'hello'
print 'hello';
Add semicolon.
Perl
local z = 4
local z = 4
Correct.
Lua
{{"age":"value" "status":32}}
{{"age":"value", "status":32}}
Add comma.
JSON
bar
bar()
Add parentheses.
Swift
if y = 27:
if y == 27:
Use == for comparison.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
fn render() -> i32 {{ 82 }}
fn render() -> i32 {{ 82 }}
Correct.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
// comment
/* comment */
Use /* */.
CSS
status: value id: hello,
status: value id: hello
Remove comma.
YAML
WHERE age = '78'
WHERE age = 78
Don't quote integer.
SQL
let index: Int = 'value'
let index: String = 'value'
Fix type.
Swift
let b: i32 = "world";
let b: &str = "world";
Type mismatch.
Rust
$list[73] = 5;
if (isset($list[73])) $list[73] = 5;
Check existence.
PHP
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
List(42,68,48)
List(42,68,48)
Correct.
Scala
if (b = 18) {}
if (b == 18) {}
Use ==.
Dart
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int x = 'test';
String x = 'test';
Type mismatch.
Dart