News for hackers. Stuff that matters.
Re:Let’s stop copying C (2016) by jorangreef on Wednesday January 23, 2019 @08:54AM (#18978076)
Take a look at Zig's "defer" and "errdefer":

https://ziglang.org/documentation/master/#defer

Re:Let’s stop copying C (2016) by edflsafoiewq on Wednesday January 23, 2019 @02:02PM (#18981458)
They are not comparable to RAII, see my comment above. Even the fact it has to bifurcate into defer and errdefer suggests that it lacks the generality to replace a totalizing resource management solution.
Re:Let’s stop copying C (2016) by notacoward on Wednesday January 23, 2019 @03:05PM (#18982220)
No, they're not the same as your beloved RAII, but this isn't an object-oriented language so it doesn't have destructors. For the third time, what better solution do you propose for a non-OO language?
Re:Let’s stop copying C (2016) by gmueckl on Wednesday January 23, 2019 @11:54AM (#18979934)
This seems equivalent to scope(exit)/scope(success)/scope(failure) in D. The drawback of this construct is that you need to repeat 2 or 3 lines of code each time you need safe cleanup or a commit/abort type of construct. This can become pretty repetitive pretty fast.
Re:Let’s stop copying C (2016) by Paul_Diraq on Wednesday January 23, 2019 @07:12PM (#18984663)
I wish D had copied pythons with statement (without the scope escape) and not used the with statement for destructuring.

The nicest thing: you can throw in the exit method without the runtime falling over itself.

Re:Let’s stop copying C (2016) by gmueckl on Wednesday January 23, 2019 @11:13PM (#18985909)
I totally missed that Python has this. This seems like the saner sibling of C#'s using/IDisposable construct.

You can do a kind of RAII in D when you use structs instead of classes because these are stack allocated and have a suitable lifetime.