Elson TC
Jun 19, 2022

Some bad examples here…

Solution #1 has bugs and that’s exactly why you shouldnt be doing complex conditions with AND and OR operators. They do not exist as a if replacement.

!!! You need parentheses dude!

The problem is not if statements, is logic complexity.

If logic around something is so complex you need a series of conditions check, your code may be too complex or confusing.

Solution #2

Switches are perfect solution here. If you dont like them, that solution could be split into dedicated mapped functions.

Trying to eliminate if statements (branchless programming) is often a good thing but you step into some complex programming style which requires more crazy unreadable solutions which are often not worthy. Believe me 😊

Simplify and split logic will do a lot more for you.

P.s: Ill be dropping a post on this next for anyone interested in more workarounds

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Elson TC
Elson TC

Written by Elson TC

Software Engineer sharing knowledge, experience, and perspective from an employee and personal point of view.

No responses yet

Write a response