|
|
|
|
|
by cerales
4926 days ago
|
|
> Why is there this special function that construct these three random types? I don’t know. It's reasonable for someone to be confused about this; my rationale is that these three types are basically where go allows "magic": all of them support special syntaxes (the range operator, optional multi-value context when looking up a map, the select operator on channels), so they have a magic initialiser, ignoring Go's usual "declaration is initialisation" rule. As others have said, it's not too bad a special case in the context of the language. The problem I have with it is that it introduces the possibility of run-time errors that in a language this advanced and generally so well-designed should probably be compiled-time errors: panics when you assign to keys in nil maps or deadlocks when you send to a channel you forgot to initialise are both errors of a class that the language generally doesn't have. |
|