News for hackers. Stuff that matters.
Re:Why Not Just Do Simple C++ RAII in C? by hgs3 on Wednesday May 22, 2024 @04:26PM (#40446012)
> Please don’t ruin C.

Exactly this. C++ folks should not approach C like a "C++ lite". I appreciate the authors candid take on the subject.

As for defer, there is some existing precedent like GCC and Clang's __attribute__((cleanup)), but - at least for me - a simple "goto cleanup;" is usually sufficient. If I understand N3199 [1] correctly, which is the authors proposal for introducing defer in C, then "defer" would be entirely a compile-time construct. Essentially just a code transformation to inject the necessary cleanup at the right spots. If you're going to introduce defer to C then that does seem like the "best" approach IMO.

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3199.htm

Re:Why Not Just Do Simple C++ RAII in C? by smallstepforman on Thursday May 23, 2024 @03:42AM (#40451709)
We C++ devs haved moved away from C decades ago, and frankly dont even think of it any more, and will never go back. Its a relic of its time, like DOS, Amiga etc. RAII is a big feature we can no longer live without. The type system and overloading is fantastic. And std::vector is a magnificant feature. A language without these features is a relic for us C++ devs.

And yes, I also agree that C++ has WTF insanity, like 17 or so initialisation quirks, exceptions in general (primarily to address failures in constructers, surely there must be a better way, also OOM / bad_alloc is a relic from the past), and unspecified sizes for default built in types (thats C heritage).

Re:Why Not Just Do Simple C++ RAII in C? by uecker on Thursday May 23, 2024 @06:41PM (#40460754)
I moved from C++ back to C and found that I am much more productive not worrying about a lot of things. But it takes a while to figure out how to do things in C because almost nothing comes out-of-the-box.