4 ms·
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.
by cmovq 8mo ago
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.
- fuhsnn 8mo agoIt'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.
- Ygg2 8mo agoWhat I always hated about defer is that you can simply forget or place it in the wrong position. Destructors or linear types (must-use-once types) are a much better solution.
- ZoomZoomZoom 8mo agoIn Nim too, although, the author doesn't like it much.
- Someone 8mo agoIt 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.
- kibwen 8mo agoYes, defer is absolutely a form of hidden control flow, even if it's less egregious than exceptions.
- jrmg 8mo agoAlways gives me COMEFROM vibes.