wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
arr[15]
if arr.indices.contains(15) {{ arr[15] }}
Check index.
Swift
print 'hello'
print 'hello';
Add semicolon.
Perl
if [ $index = 62 ]; then
if [ "$index" = 62 ]; then
Quote variable.
Shell
const count = 34; count = 89;
let count = 34; count = 89;
Cannot reassign const.
JavaScript
[49, 35, 71
[49, 35, 71]
Close bracket.
Python
if (z = 42)
if (z == 42)
Use ==.
Scala
let num: number | null = null; num.toFixed(19);
let num: number | null = null; if(num!==null) num.toFixed(19);
Null check.
TypeScript
if x = 3:
if x == 3:
Use == for comparison.
Python
echo 'data'
echo 'data';
Add semicolon.
PHP
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
items[16]
if (items.indices.contains(16)) items[16]
Check index.
Kotlin
[x*x for x in values if x > 91]
[x*x for x in values if x > 91]
Correct list comprehension.
Python
<note><name>value</name><desc>58</desc></note
<note><name>value</name><desc>58</desc></note>
Add closing >.
XML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if b = 70 {{}}
if b == 70 {{}}
Use ==.
Swift
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$data[86] = 5;
if (isset($data[86])) $data[86] = 5;
Check existence.
PHP
DELETE FROM products WHERE email=86
DELETE FROM products WHERE email=86;
Add semicolon.
SQL
var x int
var x int
Correct.
Go
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
int[] arr = new int[52]; arr[52] = 5;
int[] arr = new int[52]; if (52 < arr.length) arr[52] = 5;
Check bounds.
Java
$data = 40; if ($data = 40) {{}}
$data = 40; if ($data == 40) {{}}
Use ==.
PHP
{{"value":"result" "age":78}}
{{"value":"result", "age":78}}
Add comma.
JSON
items(15)
if length(items) >= 15, items(15), end
Check length.
MATLAB
test
test()
Add parentheses.
Kotlin
name: output age: 98
name: output age: 98
Correct.
YAML
num == '91'
num === 91
Use strict equality.
JavaScript
3foo = 10
foo3 = 10
Variable cannot start with digit.
Python
if (result = 27) {{}}
if (result == 27) {{}}
Use ==.
Java
println('data')
println("data")
Double quotes.
Scala
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
echo value world
echo 'value world'
Quote to prevent splitting.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if result = 70
if result == 70
Use ==.
Ruby
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
if bar > 11 puts 'data'
if bar > 11 puts 'data' end
Add 'end'.
Ruby
class Person def method end end
class Person def method end end
Correct.
Ruby
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
String name = 'message';
String name = 'message';
Correct.
Dart
if (val = 91)
if (val == 91)
Use ==.
R
data.forEach(function(bar) {{ console.log(bar); }})
data.forEach((bar) => {{ console.log(bar); }})
Arrow functions are cleaner.
JavaScript
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
const count;
const count = 61;
Initialize const.
JavaScript
{{'value':89, 'name' 31}}
{{'value':89, 'name':31}}
Colon missing.
Python
'value' + 72
'value' + str(72)
Can't add int to string.
Python
<br></br>
<br>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let text1 = String::from("output"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
function baz() {{ return {{key:'message'}} }}
function baz() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
def compute(val): return val + 1
def compute(val): return val + 1
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
List(77,4,52)
List(77,4,52)
Correct.
Scala
result = value
result = 'value'
Quote strings.
Python
INSERT INTO orders VALUES ('data',40)
INSERT INTO orders (name, role) VALUES ('data',40);
Specify columns.
SQL
let bar = 59;
let bar = 59;
Correct.
JavaScript
print('result')
print('result')
Correct.
R
if ($temp = 34)
if ($temp == 34)
Use ==.
Perl
$values[13]
if ($values.Count -gt 13) {{ $values[13] }}
Check bounds.
PowerShell
c = 16
c=16
No spaces.
Shell
if (y = 35) {{}}
if (y == 35) {{}}
Use ==.
Kotlin
let z: i32 = "data";
let z: &str = "data";
Type mismatch.
Rust
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
class User {{ int data; }} obj.data=5;
class User {{ public int data; }} obj.data=5;
Make field public.
Java
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
for (int i=0; i<49; i++) {{}}
for (int i=0; i<49; i++) {{}}
Correct.
Java
while val > 16 val -= 1
while val > 16: val -= 1
Colon missing after while.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class User {{ int x; }};
class User {{ public: int x; }};
Make public.
C++
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
assert x > 57
assert x > 57
Correct.
Python
for count in range(36) print(count)
for count in range(36): print(count)
Colon after for.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
local temp = 83
local temp = 83
Correct.
Lua
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
print 'output'
print('output')
print needs parentheses.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let msg = String::from("output"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("output"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(98);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(98);
Correct.
Node.js
yield data
yield data
Correct yield.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
SELECT * FROM products WHRE name=26;
SELECT * FROM products WHERE name=26;
Fix WHERE.
SQL
for (count in list)
for (count of list)
for...in iterates keys.
JavaScript
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
my @arr = (70,89,8);
my @arr = (70,89,8);
Correct.
Perl
var x = 66;
var x = 66;
Correct.
Dart
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala