Live data from Hacker News

A Defer Mechanism for C

gustedt.wordpress.com

1–10 of 248 posts

Re: A Defer Mechanism for C

#2
Despite being convenient,I have the feeling that it might be a bad idea.

One of the key interest of C compared to more recent languages is that everything is explicit. With a finger you can follow the code as it runs and know exactly what is going on and when exactly.

At the opposite, there is c++ that does a lot of things automagically. And it is often hard to understand why you suddenly get a segfault out of blue, just because a destructor was randomly called at the wrong time.

Re: A Defer Mechanism for C

#3
I’ve always considered “defer” an inelegant kludge in comparison to RAII for automatic cleanup of resources. It’s surprising that the C standards committee is considering adding that to the language. Then again, nearly none of the syntactic C features post-C89 have been very compelling or widely adopted.

Re: A Defer Mechanism for C

#6
post #2

Despite being convenient,I have the feeling that it might be a bad idea. One of the key interest of C compared to more recent languages is that everything is explicit. With a finger you can follow the code as it runs and know exactly what is going on and when exactly. At the opposite, there is c++ that does a lot of things automagically. And it is often hard to understand why you suddenly get a segfault out of blue,…

>One of the key interest of C compared to more recent languages is that everything is explicit.

There's nothing implicit about defer.

Re: A Defer Mechanism for C

#8
A nice alternative is to wrap malloc and give it a context argument. Then free via the context. This is really the same idea but doesn’t need any extra stuff in the language

Or you know... free the things you need to free and move on with your life

Re: A Defer Mechanism for C

#9
post #2

Despite being convenient,I have the feeling that it might be a bad idea. One of the key interest of C compared to more recent languages is that everything is explicit. With a finger you can follow the code as it runs and know exactly what is going on and when exactly. At the opposite, there is c++ that does a lot of things automagically. And it is often hard to understand why you suddenly get a segfault out of blue,…

Destructors are not called randomly.

Re: A Defer Mechanism for C

#10

I’ve always considered “defer” an inelegant kludge in comparison to RAII for automatic cleanup of resources. It’s surprising that the C standards committee is considering adding that to the language. Then again, nearly none of the syntactic C features post-C89 have been very compelling or widely adopted.

Defer is more explicit than RAII, so a better fit for the very explicit C languag
Post reply on HN