Get the latest tech news

Don't name packages common nouns


Avoiding naming Go packages after common nouns like <code>rate</code> or <code>server</code> so that they don&rsquo;t clash with variable names, and how to find a more fitting name for them instead.

ratelimit.Limiter doesn’t roll off the tongue in quite the same way, but the tiny cosmetic loss is vastly outweighed by the usability benefit. If you were about to call a package by a simple noun like “client” or “log” and are having trouble coming up with a good alternative, stop what you were about to do and just add a single letter prefix in front that’s keyed to your project name (e.g. “p” = “Crunchy Platform”): Go purists will absolutely hate this, but it’s infinitely better than ending up with a package named after a simple noun.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of packages

packages

Photo of common nouns

common nouns

Related news:

News photo

FreeBSD 14.1-RC1 Adds More Packages To The DVD Images - Including The Sway Compositor

News photo

Three Packages Targeting Linux with Crypto Miners Found in Python's 'PyPi' Repository

News photo

Gmail is making it easier to track packages in time for the holidays