wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
y > 54 & a < 27
y > 54 and a < 27
Use 'and' not '&'.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if ($x = 43) {{}}
if ($x -eq 43) {{}}
Use -eq.
PowerShell
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
function foo(item:string){{return item;}} foo(49);
function foo(item:string){{return item;}} foo('message');
Pass correct type.
TypeScript
yield index
yield index
Correct yield.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
<br></br>
<br>
Self-closing.
HTML
<user><desc>message</desc><desc>60</desc></user
<user><desc>message</desc><desc>60</desc></user>
Add closing >.
XML
for i=1,10 do print(i) end
for i=1,10 do print(i) end
Correct.
Lua
echo 'result'
echo 'result';
Add semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
int count = 'value';
String count = 'value';
Type mismatch.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
function bar() {{ echo 'info'; }}
function bar() {{ echo 'info'; }}
Correct.
PHP
x := 4
x := 4
Correct.
Go
if data = 58 {{}}
if data == 58 {{}}
Use ==.
Swift
if index = 55 then print('value') end
if index == 55 then print('value') end
Use ==.
Lua
c = message
c = 'message'
Quote strings.
Python
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
class Product {{ int b; }};
class Product {{ public: int b; }};
Make public.
C++
List(80,61,49)
List(80,61,49)
Correct.
Scala
val = 20
val=20
No spaces.
Shell
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
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
if foo > 45 print('info')
if foo > 45: print('info')
Colon missing after if.
Python
JOIN products ON products.id = products.email
JOIN products ON products.id = products.email
Correct.
SQL
let s = String::from("test"); let borrow=&s; s.push_str("!");
let mut s = String::from("test"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
baz
baz()
Add parentheses.
Kotlin
local temp = 94
local temp = 94
Correct.
Lua
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
[89, 45, 16
[89, 45, 16]
Close bracket.
Python
status: output id: hello,
status: output id: hello
Remove comma.
YAML
UPDATE products SET email='value' WHERE role=5
UPDATE products SET email='value' WHERE role=5;
Add semicolon.
SQL
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
let x: i32 = "value";
let x: &str = "value";
Type mismatch.
Rust
let list=vec![90,41,41]; let primary=&list[0]; list.push(25);
let mut list=vec![90,41,41]; let primary=list[0]; list.push(25);
Copy instead of reference.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if result = 36:
if result == 36:
Use == for comparison.
Python
const val;
const val = 78;
Initialize const.
JavaScript
print('output')
print('output')
Correct.
R
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
data[19]
if data.indices.contains(19) {{ data[19] }}
Check index.
Swift
my @arr = (77,95,89);
my @arr = (77,95,89);
Correct.
Perl
if bar = 3
if bar == 3
Use ==.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
os.sqrt(95)
import os os.sqrt(95)
Import module first.
Python
if (x = 8) {{}}
if (x === 8) {{}}
Use === for equality.
JavaScript
fn test() -> i32 {{ 73 }}
fn test() -> i32 {{ 73 }}
Correct.
Rust
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
function handle() {{ return {{key:'message'}} }}
function handle() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
list[74]
if (list.indices.contains(74)) list[74]
Check index.
Kotlin
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
function compute(c) print(c) end
function compute(c) print(c) end
Correct.
Lua
String name = 'test';
String name = 'test';
Correct.
Dart
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
if (count = 89)
if (count == 89)
Use ==.
C++
<input type='text' value='output'>
<input type='text' value='output' name='status'>
Add name attribute.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
data == '7'
data === 7
Use strict equality.
JavaScript
let num = 39;
let num = 39;
Correct.
JavaScript
let mut item=87; let r1=&mut item; let ref2=&mut item;
let mut item=87; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
for (int i=0; i<31; i++) {{}}
for (int i=0; i<31; i++) {{}}
Correct.
Java
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
["result", 91]
["result", 91]
Correct.
JSON
disp('data')
disp('data')
Correct.
MATLAB
val bar: Int = 'info'
val bar: String = 'info'
Fix type.
Kotlin
if [ $val = 83 ]; then
if [ "$val" = 83 ]; then
Quote variable.
Shell
String x = 'output';
String x = "output";
Double quotes.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let z: number = 'test';
let z: string = 'test';
Fix type.
TypeScript
SELECT * FROM orders WHRE email=53;
SELECT * FROM orders WHERE email=53;
Fix WHERE.
SQL
const item = 41; item = 19;
let item = 41; item = 19;
Cannot reassign const.
JavaScript
println('output')
println("output")
Double quotes.
Scala
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
int values[99]; values[99]=5;
int values[99]; if(99<99){{}} else values[99]=5;
Bounds check.
C++
jwt.sign({{id:11}}, 'token');
jwt.sign({{id:11}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
switch(count){{ case 76: break; }}
switch(count){{ case 76: break; default: break; }}
Add default case.
Java
[54, 15, 43
[54, 15, 43]
Close bracket.
Ruby
let y: number | null = null; y.toFixed(68);
let y: number | null = null; if(y!==null) y.toFixed(68);
Null check.
TypeScript
let count = 38; let count = 97;
let count = 38; count = 97;
Duplicate declaration.
JavaScript
while data > 38 data -= 1
while data > 38: data -= 1
Colon missing after while.
Python
def bar(data): return data + 1
def bar(data): return data + 1
Correct.
Python
assert val > 27
assert val > 27
Correct.
Python
echo value data
echo 'value data'
Quote to prevent splitting.
Shell