logoalt Hacker News

cmovqtoday at 7:34 AM4 repliesview on HN

Would defer be considered hidden control flow? I guess it’s not so hidden since it’s within the same function unlike destructors, exceptions, longjmp.


Replies

fuhsnntoday at 8:50 AM

It's one of the most commonly adopted feature among C successor languages (D, Zig, Odin, C3, Hare, Jai); given how opinionated some of them are on these topics, I think it's safe to say it's generally well regarded in PL communities.

show 2 replies
Someonetoday at 11:22 AM

It breaks the idea that statements get executed in the order they appear in the source code, but it ‘only’ moves and sometimes deduplicates (in functions with multiple exit points) statements, it doesn’t hide them.

Of course, that idea already isn’t correct in many languages; function arguments are evaluated before a function is called, operator precedence often breaks it, etc, but this moves entire statements, potentially by many lines.

kibwentoday at 1:35 PM

Yes, defer is absolutely a form of hidden control flow, even if it's less egregious than exceptions.

jrmgtoday at 3:01 PM

Always gives me COMEFROM vibes.