-
Notifications
You must be signed in to change notification settings - Fork 12
No Ifs JS
kimschles edited this page Jan 18, 2019
·
1 revision
Kyle Coberly -- Node.js Meetup, January 17, 2019
- Define cyclomatic complexity
- Recall 3 ways to avoid
ifs
- Discuss 3 ways to make an
if
statement better
- The number of independent paths that are possible in code
- Loops do not add cyclomatic complexity
- Conditionals add a cc because they provide at least two possible paths
-
if
,else
,else if
case
catch
&&
- a ternary
- You have to write more test cases (probably reduces test coverage)
- More possible points of failure
- Harder to extend
- Harder to read
- Functional chains
- best used for data transformations
- Dictionary Lookup
- a good replacement for switch statements
- Dynamic Dispatch
- variable behavior
- to replace a switch statement that accepts different data types (?)
- Combine conditionals AKA flatten nested ifs
- Wrap blocks in functions
- Return a ternary