magically a static member on init?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Nov 16 19:27:50 UTC 2020


On Sun, Nov 15, 2020 at 10:06:55AM +0000, Martin via Digitalmars-d-learn wrote:
> On Sunday, 15 November 2020 at 00:29:41 UTC, H. S. Teoh wrote:
> > if you don't like the semantics, don't use it; always allocate the
> > field in the class ctor instead.
> 
> Hi, i neither like it nor dislike it - it just caught me by surprise
> because i was under the impression that if i create a new instance
> then all members get initialized according to the declared optional
> default value.
> 
> I can see how this is a feature - but it is also of kind "expert
> knowledge" and i would argue that "expert knowladge" is a designs arch
> enemy.

Oh, I don't disagree; I think it's a bad design choice, and I don't
think I'd ever use this construct personally.  But it's there, and if
you use it, then you just have to be aware of the gotchas. :-)


T

-- 
Insanity is doing the same thing over and over again and expecting different results.


More information about the Digitalmars-d-learn mailing list