3 ms·
I had taken for granted that RAII was a good and useful pattern, from my dabbling in rust and what I've overheard in C++. So I was surprised and interested that
by losvedir 6y ago
I had taken for granted that RAII was a good and useful pattern, from my dabbling in rust and what I've overheard in C++. So I was surprised and interested that Zig rejects that, in favor of a `defer` construct somewhat a la Go to free resources. I'm not sure I agree, but it shows that "advances" in PL design aren't universally agreed as such.
I guess what I'm getting at is I agree with the article that it's great that programming languages develop new ideas and constructs, but it's not always obvious which ones are "winners". How do you even really judge that? The quantity and quality of software in the language? Polls of developers?
- tsss 6y agoThere are still people who disagree that the world is round and a very very large portion of the populace is religious when it's abundantly clear that religion is bullshit. Go is an outlier with a huge media machine behind it and it will disappear back into the abyss as soon as Google stops pushing it with no contributions to programming language research at large.
- bluGill 6y agoThere isn't a good answer. RAII is a great thing that I use all the time. However it requires deterministic destruction which in turn means some form of reference counting garbage collection. Garbage collection research has found non-reference counting garbage collection has a lot of advantages. So as a language designer you need to choose, better garbage collection at the expensive of non-deterministic destruction, or worse garbage collection but you get RAII. There isn't a clear winner. For about 80% of all garbage this doesn't matter because it turns out the reference count is always one until it goes to zero so you don't need to track it, and in turn this means the better garbage collection algorithms I mentioned above are not better in this case. However this rule of thumb comes from C++ where training (based on real performance needs of the type of code you might write in C++) keeps people from doing the types of operations that would increment the reference count. Which is to say even if Java could figure which cases can use this rule (this appears like variant of the halting problem to me), they would probably discover that the number there is enough less as to not make it worth adding. Worse, in C++ there is a tiny number of data structures with circular references that you cannot use reference counting to deal with. Thus as a C++ programmer will sometimes have to write some other garbage collector for the edge cases, and these don't get RAII deterministic destruction. Note that I didn't state the advantages of better garbage collectors. I am not an expert here, so I'm leaving it as an exercise to the reader. Just know that there are advantages to them that make them a great choice for some problems despite losing RAII! If you are designing a language you should probably look into this early. (I was going to say a hybrid is the worst of both worlds - but maybe I'm wrong so I'll let you figure that out)