News for hackers. Stuff that matters.
Re:Golang landmines by jmgao on Sunday September 18, 2016 @12:58AM (#12524000)
> In your hypothetical example in Go you would pick one of the set values (e.g. "1") as a "zero value".

> The alternative of not having a "zero value" is to have variables with undefined values, and we know from C/C++ that it's extremely bad idea.

Selecting a "zero value" that also happens to have actual meaning is insane.

The real alternative to not having a zero value is to require all variables to be initialized with some value. If you can't, then the variable should be an optional type wrapping the type you want. Pointers/references have something similar (you can have a valid pointer, or you can have null), but optional types are generally applicable to any type, and pulling a value out of an Option generally requires you to check for the null-equivalent or explicitly say "I know what I'm doing, assume it contains something" (unlike null pointers/references, which you can blindly dereference).

There are no comments on this comment yet.