‹ BackHN Continuity

Thread

Small programming tricks

681 points · 294 comments · signa11

  1. winternewt · · focus · HN ↗
    Only a few of these are actual programming tricks. The problem with sharing them is that they'll typically seem obvious to you, since you know them. It's difficult to know what is actually unknown to other people, and if you share stuff everybody knows you risk coming off as arrogant.

    Here's one that I think more people should know: avoid branches. If I can do the same thing without an if statement and even a logical expression, the code typically both becomes easier to understand for people and easier to run for the CPU.

    1. metabagel · · focus · HN ↗
      In what context can you avoid branches?
      1. eikenberry · · focus · HN ↗
        Early returns is one method.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.