2009/11/13 german diago <
germa...@gmail.com>:
> I mean, when the memory is reserved, shouldn't this
> type be fully usable? I'm confused.
It is not the case in Go. An object of any type can be zero
initialized, but whether such a zero initialized object is in a valid
and useful state depends on the particular type.
An unfortunate consequence is that it is tempting to rely on zero
initialization for types like simple structs, which will break if the
types evolve into something more elaborate which needs nontrivial
initialization of some fields.
In general a type needs an explicit constructor function if it does
not want its clients to depend on the fact whether its zero
representation is a useful state. In case of a few builtin types the
magic make "function" serves as a constructor function.
The constructor function can return either an object or a pointer to
an object depending on whether the type is a copyable value type or a
type of objects with meaningful identity. Map[k]v is formally a value
type but the value is merely a pointer-like handle to a real map which
is not exposed directly, so copying the handle is valid but does not
copy the map itself.
(I hope I am right here, I have not really used Go.)
--
Marcin Kowalczyk