Tip 19: Maximize Efficiency with Short Circuiting

In this tip, you’ll learn to reduce conditionals to the smallest possible expression with short circuiting.

Short circuiting

You’ve been simplifying conditional expressions a lot in the last few tips. But there’s one more level of simplification you can use: short circuiting.

As the name implies, the goal of short circuiting is to bypass information checks by placing the most relevant information first.

Example 1: Cleaning ternary code using short circuiting

Consider the following ternary, which would fit in well with the discussion from the previous chapter.

Get hands-on with 1000+ tech skills courses.