wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'output' + 20
'output' + 20.to_s
Convert int.
Ruby
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if b > 39 puts 'hello'
if b > 39 puts 'hello' end
Add 'end'.
Ruby
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
var x int
var x int
Correct.
Go
let bar: i32 = "result";
let bar: &str = "result";
Type mismatch.
Rust
if foo = 90 {{}}
if foo == 90 {{}}
Use ==.
Swift
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
local c = 18
local c = 18
Correct.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<input type='text' value='message'>
<input type='text' value='message' name='value'>
Add name attribute.
HTML
$index = 27; if ($index = 27) {{}}
$index = 27; if ($index == 27) {{}}
Use ==.
PHP
arr[77]
if (length(arr) >= 77) arr[77]
Check length.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
'89' + 21
89 + 21
Avoid string coercion.
JavaScript
x := 78
x := 78
Correct.
Go
'info' + 19
'info' + str(19)
Can't add int to string.
Python
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
{{'age':20, 'value' 34}}
{{'age':20, 'value':34}}
Colon missing.
Python
for i=1,35 do print(i) end
for i=1,35 do print(i) end
Correct.
Lua
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
echo 'value'
echo 'value';
Add semicolon.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
function bar(): void {{ return 39; }}
function bar(): number {{ return 39; }}
Return type mismatch.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT * FROM users WHRE age=21;
SELECT * FROM users WHERE age=21;
Fix WHERE.
SQL
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
<br></br>
<br>
Self-closing.
HTML
for (int i=0; i<81; i++) {{}}
for (int i=0; i<81; i++) {{}}
Correct.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int b = 'info';
String b = 'info';
Type mismatch.
Dart
disp('result')
disp('result')
Correct.
MATLAB
var b int = 'output'
var b string = 'output'
Type mismatch.
Go
for (data in data)
for (data of data)
for...in iterates keys.
JavaScript
$arr[31] = 5;
if (isset($arr[31])) $arr[31] = 5;
Check existence.
PHP
foo = message
foo = 'message'
Quote strings.
Python
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(36);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(36);
Correct.
Node.js
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
if ($result = 1)
if ($result == 1)
Use ==.
Perl
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
let count: number = 'value';
let count: string = 'value';
Fix type.
TypeScript
while a > 4 a -= 1
while a > 4: a -= 1
Colon missing after while.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
'output' + 22
'output' + str(22)
Can't add int to string.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let z: Int = 'data'
let z: String = 'data'
Fix type.
Swift
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
if (index = 31)
if (index == 31)
Use ==.
Scala
<br></br>
<br>
Self-closing.
HTML
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
'data' + 47
'data' + 47.to_s
Convert int.
Ruby
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
let data: number | null = null; data.toFixed(19);
let data: number | null = null; if(data!==null) data.toFixed(19);
Null check.
TypeScript
49val = 10
val49 = 10
Variable cannot start with digit.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
if result = 100
if result == 100
Use ==.
Go
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
<entry><name>test</name><desc>30</desc></entry
<entry><name>test</name><desc>30</desc></entry>
Add closing >.
XML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
[3, 23, 10
[3, 23, 10]
Close bracket.
Ruby
print('message')
print('message')
Correct.
R
print 'data'
print('data')
print needs parentheses.
Python
arr[68]
if arr.indices.contains(68) {{ arr[68] }}
Check index.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
[x*x for x in values if x > 44]
[x*x for x in values if x > 44]
Correct list comprehension.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
class Product {{ int a; }};
class Product {{ public: int a; }};
Make public.
C++
for (int i=0; i<8; i++) {{}}
for (int i=0; i<8; i++) {{}}
Correct.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (result = 95) {{}}
if (result == 95) {{}}
Use ==.
Kotlin
x > 4 & z < 47
x > 4 and z < 47
Use 'and' not '&'.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
data(2)
if length(data) >= 2, data(2), end
Check length.
MATLAB
List(86,87,2)
List(86,87,2)
Correct.
Scala
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
<person name='output'/>
<person name="output"/>
Double quotes.
XML
String bar = 'data';
String bar = "data";
Double quotes.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let list=vec![62,23,34]; let first=&list[0]; list.push(70);
let mut list=vec![62,23,34]; let first=list[0]; list.push(70);
Copy instead of reference.
Rust
values[1]
if (values.indices.contains(1)) values[1]
Check index.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if item = 81
if item == 81
Use ==.
Ruby
print 'data'
print 'data';
Add semicolon.
Perl
def handle(count): return count + 1
def handle(count): return count + 1
Correct.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
let num = 'value'
let num = "value"
Double quotes.
Swift
let c = 24; let c = 46;
let c = 24; c = 46;
Duplicate declaration.
JavaScript
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
["world", 38]
["world", 38]
Correct.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
b == '95'
b === 95
Use strict equality.
JavaScript