Don't name packages common nouns
brandur.org
brandur.org
I still don't understand why they aren't in a package, or better yet why they didn't just make math.Min and math.Max generic?
Shadowing is better than the very questionable decisions made by whoever wrote Windows.h...
#include <Windows.h>
#define NOMINMAX // comment out to break
#include <algorithm>
auto main() -> int
{
return std::min(42, 1337); // may break
}I don't know Go, but my first thought would go to lol no generics. Now that they do have generics I guess they could do it, but backwards compatibility may require them to use other names than `math.Min` and `math.Max`.
(Note: Go did have some generic built-in constructs from the start, and could have included `min` and `max`, similar to how OCaml did it. At the same time, you don't want too many primitives in your language if you can help it.)
I am guessing that using a different operator (e.g. rate::NewLimiter()) was deemed inelegant, but it would have avoided a whole set of problems.
It's funny how when I was using Go, I couldn't wait until it got generics (which was only a matter of time despite the party line). When it finally got them, I was versed enough in the edges and nature of the language/ecosystem that I didn't really care anymore and moved on. I am glad that Go rose to popularity because it brought to light opinions that weren't all that popular: memory layouts matter and error values (rather than exceptions). I still prefer a sound type system over nil/zero values though.
> It's helpful if everyone using the package can use the same name to refer to its contents, which implies that the package name should be good: short, concise, evocative. By convention, packages are given lower case, single-word names; there should be no need for underscores or mixedCaps.
https://go.dev/doc/effective_go#names
Maybe the convention of single-letter variable names was meant to play nicely with this too (again, agree with it or not).
Can’t say I really care about this issue that much, it’s occasionally a slight nuisance, but show me a programming language that doesn’t have the occasional slight nuisance.
An explicit scope resolution operator would be a better solution than forcing package name changes, as called out by another commenter. Maybe that was left out to keep it simple? If anyone knows of a Go blog post about the decision to omit this feature I’d be curious to see it!
What kind of rate? Time or volume or...something else entirely? Otherwise, the variable will be scoped within a function and go doesn't really promote global variables as a best practice.
logx, errorx, typex, metricx...
They read just like "s" so it reads like the plural of their word, but conflicts are much rarer (there's plenty of "types" packages).
It also tells me which package is mine or third-party immediately.
I agree, I don't think the default for a package should be a footgun. Or in the words of Michael Bolton "why should I change? He’s the one who sucks.”
from sklearn.feature_extraction.text import TfidfVectorizer
tfidf = TfidfVectorizer()
we were told to change it to from sklearn.feature_extraction import text
tfidf = text.TfidfVectorizer()
to be compliant. Guess what variable name everyone used to store document text in every file.Until this article, I always blamed this on the decision to blindly import modules instead of... well... whatever makes sense. Now I'm realizing if we all avoid common names for packages then this whole class of issue goes away.
If your solutions depends on others to "do the right thing", it often isn't a viable solution.
However, how you import something in your own files, is something you most likely control.
Someone probably encountered a problem with having a mishmash of ways people do imports and thus began the policy. It's the type of policy where someone heaved a great big sigh and said, "this is why we can't have nice things."
Having a internal policy about how to import something wouldn't be relying on others to do the right thing.
I've done it before. It's the type of thing where you'll find out immediately if you screwed up somewhere but modern IDEs usually do a pretty good job at such things (the free version of PyCharm will do it real fast and then you never have to open it again if it's not your thing).
The issue also just goes away if you just do it yourself with pretty much no effort:
from sklearn.feature_extraction import text as feat_text
tfidf = feat_text.TfidfVectorizer()Alias the package name or change your variable name.
Or don't use the package at all if the name upsets you that much.
Namespacing in languages such as Rust (modules) are probably most favourable to me, i.e. f64::min/max ~ u64::min/max or a hypothetical crypto::rand() math::rand().
Not to say it invalidates the whole article or anything, but in what world would "ratelimit" never be used as a variable name? That still feels like a fairly reasonable name for a variable if we're ignoring the camel-case requirement.
tasa - Spanish
uku - Hawaiian
sats - Danish
...or just be clever and call it something like 'irate' (the Apple version? haha).