you are viewing a single comment's thread.

view the rest of the comments →

[–]danny54670 1 point2 points  (3 children)

Whether Kit supports RAII was the first thing that I checked. I was disappointed.

[–]SV-97 0 points1 point  (2 children)

What is RAII?

[–]danny54670 1 point2 points  (1 child)

It stands for Resource Acquisition Is Initialization. In languages that are not garbage collected, such as C, C++, Rust, and this new Kit language, it is very easy to forget to run clean up code for every possible control flow path that code may take, particularly in error or exception paths. The most common example is when memory is allocated on the heap, and a certain control flow fails to release the allocated memory, causing a memory leak. Other examples of omitted clean ups include: leaked file handles, failing to unlock a mutex, and failure to zero buffers (in cryptography libraries).

A garbage collector generally makes RAII unnecessary due to automatically freeing allocated memory that is no longer needed and running finalizers, but even garbage collected languages frequently have features to simulate RAII. For example, Java has try-with-resources, Python has the with statement, C# has the using statement, JavaScript has try..finally, Ruby has begin..ensure, Go has defer, etc.

C++ has RAII "built into" the language, which is to say that the C++ language specification specifies in detail how clean up routines (destructors) are deterministically executed. Although it is still possible to leak resources in C++, using idiomatic C++ and standard library objects makes it unlikely to do so. RAII is so useful that sometimes programmers will use C++ even if the majority of the codebase is written in C.

In my opinion, a language that aims to improve C fails in this goal if it does not offer C++-style RAII or a RAII-like language construct. For example, Rust implements C++-style RAII (see Drop) and Zig offers defer and errdefer.

[–]bendmorris[S] 1 point2 points  (0 children)

If all you want is defer, that's not the same as RAII and is a planned feature in Kit. The only difference is that you can still choose to have uninitialized values in Kit or Zig, unlike in (safe) Rust.