Skip to content

Commit 3f729f9

Browse files
authored
docs(conditionals): added preference for positive boolean expressions and reduced strength of ternary recommendation.
1 parent 2950c3b commit 3f729f9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docs/conditionals.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Conditionals
22

33
## Default Values
4-
Use [ternary operator](http://lua-users.org/wiki/TernaryOperator) 'or' Instead of nil checks for performance and readability optimization.
4+
Consider [ternary operator](http://lua-users.org/wiki/TernaryOperator) 'or' instead of nil checks to improve readability.
55
```lua title="BAD"
66
if name then
77
return name
@@ -25,3 +25,20 @@ end
2525
```lua title="GOOD"
2626
return name == "mark" or name == "stacy"
2727
```
28+
29+
## Prefer positive boolean expressions
30+
This makes the code easier to read.
31+
```lua title="BAD"
32+
if not isHappy then
33+
return "sad"
34+
else
35+
return "happy"
36+
end
37+
```
38+
```lua title="GOOD"
39+
if isHappy then
40+
return "happy"
41+
else
42+
return "sad"
43+
end
44+
```

0 commit comments

Comments
 (0)