News for hackers. Stuff that matters.
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by cmrdporcupine on Thursday July 15, 2021 @10:27PM (#27852478)
100%. And another problem with defer is that it only works in function scope, not block scope. This bit me in a piece of Go I had to refactor into multiple functions recently when all I wanted to do was a few lines change around a 'for' loop. The code review ended up being more substantial and it made the code less readable than just being able to sprinkle in some additional defers.

With the C++ destructor RAII pattern I can use it at any lexical scope I need it at, which is super handy.

Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by Jtsummers on Thursday July 15, 2021 @10:33PM (#27852499)
Zig's defers, at least, are block scoped. So they are executed at the end of whatever block they're created in, in contrast to Go's version of defer which is function scoped only.
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by naikrovek on Thursday July 15, 2021 @11:47PM (#27852870)
RAII is very obviously a bad idea, and I'm shocked that more people can't see this. it's "fine" until it isn't, and when it bites you, it crushes your arm. you are unlikely to ever forget this after it happens. it's like driving a car fast while blindfolded; you will crash, and it will hurt, it's just a matter of when.
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by pcwalton on Friday July 16, 2021 @12:07AM (#27852963)
Care to explain why? In Rust RAII works very well, and the common failure mode of RAII--use-after-free--is statically prevented by the borrow check.
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by cmrdporcupine on Friday July 16, 2021 @10:45AM (#27856753)
Use-after-free is definitely the major footgun portion of RAII in C++ (in my experience) but seems to me like the same issue would be present in any non-GC'd language that offers a 'deferral' mechanism, asynchronous or not (unless it has ownership/borrow management like Rust as you point out).
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by marton78 on Friday July 16, 2021 @02:06AM (#27853444)
Your claims would benefit from you substantiating them.
Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by naikrovek on Friday July 16, 2021 @03:49PM (#27860468)
until you experience the problems yourself, you won't believe me, anyway, no matter what evidence I provide.

it is way too easy to critique an approach that led to a problem that hasn't happened to you, and is described to you by someone else.

Re:Zig, Skia, Clojure, Geometry and the Japanese TV Show: IC... by kitd on Friday July 16, 2021 @02:31AM (#27853539)
You can create "block-scope" with an immediately-called function.