Thoughts from newcommer

Shachar Shemesh via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 17 04:14:47 PDT 2017


On Sunday, 16 April 2017 at 17:00:25 UTC, Jack Stouffer wrote:

> So we can say that D has buggy RAII. Claiming that D doesn't 
> have RAII is equally false.

To me, that's a basic misunderstanding of what RAII mean. RAII, 
to me, means you wrap your resource in a container, and then can 
just go ahead and forget about releasing it. As such, saying that 
D has RAII, but they only work most of the time means that the 
core functionality that RAII provides is simply not working.

There are other languages out there that have unreliable 
destructors. Java has them. Python has them. No one will use them.

D's destructors are in much better shape than either Java's or 
Python's, but let's take a simple survey: Does anyone here use 
RAII in D? Please step forward.

Please go over your scope(exit)s and tell me that 70% of them 
(and I'm being generous here, I'm guessing actual number is 
closer to 95%) are *not* release of resources acquired in the 
same scope. If they are, then you are in a position where RAII 
would have made your code cleaner and simpler, but you chose not 
to use it.

scope(exit) is a much cleaner solution than a finally clause, but 
not as clean as RAII. If the language supports RAII, how come 
people are not using it?

Shachar


More information about the Digitalmars-d mailing list