I hate class destructors with a burning passion

Walter Bright newshound2 at digitalmars.com
Wed Jun 9 02:37:34 UTC 2021


On 6/6/2021 4:54 AM, Mathias LANG wrote:
 > https://github.com/dlang/druntime/pull/3476/files

Frankly, the whole jazz with assert() went way off the rails. Assert should go 
directly to Jail, it should not pass Go or collect $200. All these layers it 
goes through is just madness.

Allocating via the GC is in assert is just ridiculous, as the program is going 
to exit shortly anyway. There won't ever be a need to run a collection on it. 
Just malloc away and fuggeddabootet.

These sorts of things are why I added the checkaction switch to bypass it and 
just do the simple, direct stuff.

---

Throwing constructors is one of those things that makes a program very hard to 
reason about. I've debated with Andrei about requiring that constructors be 
nothrow. My advice is make them nothrow, i.e. design them so they cannot fail. 
There's not a single throwing constructor in DMD, and it's going to stay that 
way :-)

---

A destructor should never try to remove a GC allocated member. The GC may have 
already removed it! As with constructors, design destructors so they cannot 
fail. You'll have a lot less heartache that way.

---

This is not to argue that we don't need to fix the bugs. Thanks, Mathias, for 
the fixes you've created! It's appreciated.


More information about the Digitalmars-d mailing list