Static struct initialization syntax behavior & it being disabled upon adding a constructor
HuskyNator
HuskyNator at protonmail.ch
Mon Apr 18 10:26:16 UTC 2022
On Monday, 18 April 2022 at 03:21:30 UTC, H. S. Teoh wrote:
> Structs in D ought to be treated like "glorified ints", as
> Andrei puts it. If you need complex ctors and complex methods,
> that's a sign you should be using a class instead.
I prefer not to use classes, as the code would now move towards
using references, which is the exact reason I'm using structs.
I ended up creating a constructor for my needs and disabling the
default constructor. I'm mostly just surprised the static syntax
is turned off by adding one. I still don't see the reason behind
it. Why have it but disable it?
I ironically almost always need the exact same constructor with
the identical arguments though: Initialize the matrix to the
identity matrix. Why not introduce the empty self-defined
constructor as a separate thing from the .init value?
On a sidenote, I'm surprised D did not choose 0 as the default
floating value. Doesn't almost every language do this? I
understand the thinking behind it, but when the type one uses in
a template influences the behavior of the code, that seems like a
pretty big red flag to me. (Any non-floating type defaults to 0,
but using floats/doubles suddenly introduces NaN, surely I'm not
the only one that sees a problem with this 😅) Especially when
it's basically a standard 0 is used for this. Sorry for the rant.
More information about the Digitalmars-d-learn
mailing list