Guard Pattern #225
JohnnyUndercover
started this conversation in
BC Patterns
Replies: 1 comment
-
I really like this pattern. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to add this pattern to the guidelines because it makes the code much more readable.
There is already something similar under the "Best Practices" topic called "if not then exit", but I don't think it is the same because it is only targeted at tables and therefore only for a specific guard.
Why use Guards?
If you don't use guards, your code is likely to suffer from a large number of indentation and if-else relationships that prevent you from reading the code effortlessly from top to bottom. Because of the high number of intents and if-else statements, you have to jump through the code while keeping track of your current indentation level. This makes reading such a code mentally exhausting.
How does it look
Bad Code:
Good Code:
Example 1
Bad Code
Example 2
Bad Code
Good Code
Beta Was this translation helpful? Give feedback.
All reactions