D is dead

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Aug 24 02:33:31 UTC 2018


On Thursday, August 23, 2018 3:31:41 PM MDT Walter Bright via Digitalmars-d 
wrote:
> On 8/23/2018 9:19 AM, Jonathan M Davis wrote:
> > D was designed to have RAII, and it does. It's just that the
> > implementation is buggy (which is obviously a serious problem), so
> > depending on what your program is doing, it's not going to work
> > correctly. It's not like we opted to not have RAII in D, and I'm sure
> > that it will be fixed at some point. So, while it can certainly be
> > argued that we've dropped the ball by not getting it fully fixed by
> > now, I don't really see how it could be termed a missed opportunity.
>
> As far as I know, the only known bug in RAII is
> https://issues.dlang.org/show_bug.cgi?id=14246 where constructors are not
> properly unwinding partially constructed objects.

Yeah. I've used RAII plenty in D without problems, but the fact remains that
certain uses of it are very broken right now thanks to the constructor
issue. I suspect that Shachar's as negative about this as he is in part
because having RAII go wrong with the kind of low-level stuff Weka does
would be a serious problem, whereas if you're not dealing with some sort of
resource management in the constructor, having it not unwind properly on
failure isn't likely to be a big deal (much as it's still not good), because
it's just going to leave the constructed object in a worse state, and it's
not going to be used anyway, because the constructor failed.

> My personal opinion is that constructors that throw are an execrable
> programming practice, and I've wanted to ban them. (Andrei, while
> sympathetic to the idea, felt that too many people relied on it.) I won't
> allow throwing constructors in dmd or any software I have authority over.

Wow. I'm surprised by this. I definitely agree with David on this one.
Without being able to throw from a constructor, you can't really have it
fail, and there are times when it needs to be able to fail. Not being able
to have throwing constructors basically means having to do two-part
initialization which I would have thought was almost universally considered
bad. I would consider constructors and exceptions to go absolutely
hand-in-hand and wouldn't expect a language without exceptions to have
constructors unless maybe it constructed all objects on the heap such that
the result could be null and could thus checked for failure afterwards.

> (Having throwing destructors is even worse, it's just madness. Although it
> is allowed in C++, it doesn't actually work.)

Yeah. We probably should have required that destructors be nothrow and force
destructor failures to be treated as Errors. I recall Herb Sutter wanting to
making default destructors in C++11 to be noexcept, but the committee
decided not to because of some stray code base that was doing something
insane with exceptions and destructors. We could probably still fix it in D
(particularly since I think that it is generally accepted that throwing from
destructors is a bad idea), but it would undoubtedly break code simply
because of functions being called which aren't nothrow but won't actually
throw - thus forcing stuff like

try
{
    ...
}
catch(Exception)
    assert(0);

I expect that you'd have a riot on your hands though if you actually tried
to push for getting rid of throwing constructors.

- Jonathan M Davis





More information about the Digitalmars-d mailing list