5 ms·
> Naming a return, but then assigning nothing to it, will compile. This, I believe, comes down to Go having sane default values i.e. if you name a return of ty
by AsyncAwait 6y ago
> Naming a return, but then assigning nothing to it, will compile.
This, I believe, comes down to Go having sane default values i.e. if you name a return of type string and assign nothing to it, you'd get "", which is a valid string value and something you can check against.
But I agree it should at least be a lint warning.
- EdwardDiego 6y agoYeah, I didn't quite realise it actually initialised the variable when I first started using it. I mean, as far as footguns go, it's a pretty minor one, and over all, I quite enjoyed my Go experience, it was very easy as a Go beginner to write code that worked.