lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 23.11.2015 um 22:46 schröbte Coda Highland:
On Mon, Nov 23, 2015 at 1:25 PM, Philipp Janda <siffiejoe@gmx.net> wrote:

That's nonsense. Many static languages don't have RAII.
Joking aside, so far I have not found a better tool for generic resource
management than RAII. Advantages of RAII over finally/using/with: You need
only one language feature (destructors) instead of two (finalizers and
finally), so the language is less complex/bloated (see C++!). And more
importantly you only write your resource management code once and not
multiple times scattered around in your source code.

That's a fallacious claim. You DO need two language features to
implement RAII -- destructors and deterministic cleanup. Destructors
with nondeterministic cleanup is exactly what Lua has right now with
the __gc metamethod.

If you want to count deterministic cleanup you also have to count the garbage collector, so it's two features compared to three.


Saying that C++ is less complex/bloated is also a pretty flimsy claim,
considering that the typical criticism of C++ is that it's
overengineered and complicated, and that the typical praise of Lua is
its minimalism.

The C++ part was a joke (obviously, I thought). I'm aware that C++ is considered complex and bloated (and rightly so). But RAII is not the problem there (that part was meant seriously).


And as for where resource management goes, C++ code involves writing
resource management ALL OVER THE PLACE. You have to pay attention to
scoping and you have to either manually free heap-allocated memory or
explicitly use a container that does it for you. That's a far cry from
keeping the code centralized.

Manually free'ing heap-allocated memory is *not* RAII. To get the benefits you actually have to use it. C++ doesn't force you to use RAII (and it probably shouldn't -- it's too low-level for that), so you might be right about resource management in C++ code, but I still think I'm right about resource management with RAII.


And I say these things from the perspective of a C++ lover! C++ is my
favorite language and until recently I wrote the majority of my code
in it.

/s/ Adam


Philipp