DEV Community

Discussion on: Keeping your code clean by sweeping out "if" statements

Collapse
 
elonderin profile image
elonderin • Edited

+1 I much prefer this type of declarative coding and have been using it for some time. However, I found that not all fellow devs share that sentiment and esp. Junior devs have a problem understanding this style.

Personally, I prefer using this over if/else even for small maps and start to refactor other if/else cascades when they go beyond 5 or 6 values. To me it 's just too easy to botch up things when there are too many ifs. In one project I fixed several bugs that way b/c typos have crept into the copy/pasted boolean expression pattern over time and in one case the same if expression was duplicated and a change to the code only made it to the last else-if only to never get executed...