Time to kill T() as (sometimes) working T.init alias ?
Jonathan M Davis
jmdavisProg at gmx.com
Thu Nov 29 19:51:42 PST 2012
On Friday, November 30, 2012 14:27:56 Walter Bright wrote:
> On 11/29/2012 11:10 PM, Jonathan M Davis wrote:
> > [...]
>
> You're right, I had overlooked the point that having no default
> constructor means that the default construction will *always* succeed.
> This is a large simplification.
>
> Frankly, non-trivial default construction has always smelled like a bad
> practice to me, though it's not always obvious why.
You can easily have default construction which is relatively trivial which
cannot be done in an init value. For instance, std.datetime.SysTime has
TimeZone member, and because it's a class, it can't be initialized to anything
other than null at compile time. It would be great if it could default to
LocalTime, but that's just not possible with how init and construction works
in D. On the other hand, if structs were default-constructed, it would be a
non-issue, because the default constructor could initialize the TimeZone
member.
init buys us a _lot_, but there are definitely cases where having default
construction at runtime would be very beneficial. Being able to construct
structs with no-param constructors partially fixes that issue, but we can't
completely fix it and will just have to work around the remaining use cases
where the lack of default construction causes issues.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list