3 ms·
I actually agree with the author that nils are a massive pain in the arse most of the time, and that Go would be much better off without them. There is no prec
by ainar-g 4y ago
I actually agree with the author that nils are a massive pain in the arse most of the time, and that Go would be much better off without them.
There is no precise, mathematical answer to your question, since it's always contingent on many things, but one way to evaluate a “correctness” of a design choice is the old adage that a good interface is hard to misuse. If your code can handle a nil map okay, and not requiring a non-nil map brings significant ergonomics advantages, you may not need to check it. Otherwise, I personally would err on the side of caution and design an API that either doesn't give the user a choice (i.e. creates the map itself) or returns an error if they provide invalid data.