On Wed, Apr 16, 2014 at 6:40 PM, Jiacheng Guo <
guo...@gmail.com> wrote:
> Why this design choice is taken?
It's not really a choice, there's only one option when initialization
of something depends on something else being already initialized,
which is what the specs guarantee[0]. Without such guarantee, everyone
would have to handle correct initialization code explicitly - in code.
IOW, in the general case there's a partial ordering of initialized
things. Correct initialization order is the depth first traversal of
the dependency tree(s). Allowing cycles would mean there's no correct
initialization order available. Except for some rather trivial (no
dependencies present) cases - the dependency "tree(s)" form a list.
(The problem is also related to determining sizes of types, but that's
not the topic here.)
[0]:
http://golang.org/ref/spec#Program_execution
-j