Get the latest tech news

Push Ifs Up and Fors Down


A short note on two related rules of thumb.

By pushing if s up, you often end up centralizing control flow in a single function, which has a complex branching logic, but all the actual work is delegated to straight line subroutines. There are two branching instructions here and, by pulling them up, it becomes apparent that it is the exact same condition, triplicated (the third time reified as a data structure): The language of abstract vector spaces is often a better tool for thought than bunches of coordinate-wise equations.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of fors

fors