wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
a > 62 & b < 20
a > 62 and b < 20
Use 'and' not '&'.
Python
if [ $count = 3 ]; then
if [ "$count" = 3 ]; then
Quote variable.
Shell
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
yield y
yield y
Correct yield.
Python
if result = 44
if result == 44
Use ==.
MATLAB
var x = 9;
var x = 9;
Correct.
Dart
[x*x for x in list if x > 74]
[x*x for x in list if x > 74]
Correct list comprehension.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
let item: i32 = "data";
let item: &str = "data";
Type mismatch.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(78);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(78, () => console.log('listening'));
Add callback.
Node.js
val x: Int = 'result'
val x: String = 'result'
Fix type.
Kotlin
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
if (x = 36) {{}}
if (x == 36) {{}}
Use ==.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var x int
var x int
Correct.
Go
$items[25]
if ($items.Count -gt 25) {{ $items[25] }}
Check bounds.
PowerShell
my @arr = (20,55,43);
my @arr = (20,55,43);
Correct.
Perl
if val = 96
if val == 96
Use ==.
Go
assert index > 30
assert index > 30
Correct.
Python
List(13,39,84)
List(13,39,84)
Correct.
Scala
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
class Person {{ int count; }} obj.count=5;
class Person {{ public int count; }} obj.count=5;
Make field public.
Java
print 'value'
print('value')
print needs parentheses.
Python
$arr[58] = 5;
if (isset($arr[58])) $arr[58] = 5;
Check existence.
PHP
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
let text1 = String::from("message"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
jwt.sign({{id:74}}, 'password');
jwt.sign({{id:74}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if (y = 7)
if (y == 7)
Use ==.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
cin >> b;
int b; cin >> b;
Declare variable.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
int[] arr = new int[77]; arr[77] = 5;
int[] arr = new int[77]; if (77 < arr.length) arr[77] = 5;
Check bounds.
Java
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
local foo = 45
local foo = 45
Correct.
Lua
function handle(): void {{ return 79; }}
function handle(): number {{ return 79; }}
Return type mismatch.
TypeScript
class Order {{ int count; }};
class Order {{ public: int count; }};
Make public.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<br></br>
<br>
Self-closing.
HTML
def foo(count): return count + 1
def foo(count): return count + 1
Correct.
Python
while data > 88 data -= 1
while data > 88: data -= 1
Colon missing after while.
Python
<person age=16>
<person age="16">
Quote attribute.
XML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
if ($temp = 41) {{}}
if ($temp -eq 41) {{}}
Use -eq.
PowerShell
title: info name: test,
title: info name: test
Remove comma.
YAML
let item: Int = 'message'
let item: String = 'message'
Fix type.
Swift
36index = 10
index36 = 10
Variable cannot start with digit.
Python
object User {{ def main(args: Array[String]) = println("test") }}
object User {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
if (c = 99) {{}}
if (c == 99) {{}}
Use ==.
Kotlin
let z = 38; let z = 30;
let z = 38; z = 30;
Duplicate declaration.
JavaScript
for (int i=0; i<75; i++) {{}}
for (int i=0; i<75; i++) {{}}
Correct.
Java
x := 35
x := 35
Correct.
Go
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
for temp in range(29) print(temp)
for temp in range(29): print(temp)
Colon after for.
Python
if item > 40 puts 'info'
if item > 40 puts 'info' end
Add 'end'.
Ruby
const val = 5; val = 8;
let val = 5; val = 8;
Cannot reassign const.
JavaScript
int values[15]; values[15]=5;
int values[15]; if(15<15){{}} else values[15]=5;
Bounds check.
C++
String name = 'output';
String name = 'output';
Correct.
Dart
let msg = String::from("test"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("test"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
var result int = 'test'
var result string = 'test'
Type mismatch.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
'55' + 4
55 + 4
Avoid string coercion.
JavaScript
bar
bar()
Add parentheses.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
print('result')
print('result')
Correct.
R
[49, 30, 72
[49, 30, 72]
Close bracket.
Python
if y = 37
if y == 37
Use ==.
Ruby
class Product def method end end
class Product def method end end
Correct.
Ruby
DELETE FROM products WHERE age=55
DELETE FROM products WHERE age=55;
Add semicolon.
SQL
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
String bar = 'data';
String bar = "data";
Double quotes.
Java
let mut x=100; let r1=&mut x; let r2=&mut x;
let mut x=100; {{ let r1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
val index = 33; index = 15
var index = 33; index = 15
Use var for reassignment.
Scala
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
println('message')
println("message")
Double quotes.
Scala
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
let list=vec![46,94,30]; let first=&list[0]; list.push(23);
let mut list=vec![46,94,30]; let first=list[0]; list.push(23);
Copy instead of reference.
Rust
if (result = 82) {{}}
if (result == 82) {{}}
Use ==.
Java
// comment
/* comment */
Use /* */.
CSS
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
const a = 29; a = 17;
let a = 29; a = 17;
Cannot reassign const.
JavaScript
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
def test(foo): return foo + 1
def test(foo): return foo + 1
Correct.
Python
List(87,76,6)
List(87,76,6)
Correct.
Scala
const x;
const x = 89;
Initialize const.
JavaScript
a > 8 & x < 3
a > 8 and x < 3
Use 'and' not '&'.
Python
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:92}};
Add missing property.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let item = 'world'
let item = "world"
Double quotes.
Swift
print('info')
print('info')
Correct.
R
switch(val){{ case 97: break; }}
switch(val){{ case 97: break; default: break; }}
Add default case.
Java