3 ms·
> That adds a lot of boilerplate though. In practice, it doesn't. (The compiler inlines the code.) I know because I'm pretty picky about this sort of thing - i
by WalterBright 9y ago
> That adds a lot of boilerplate though.
In practice, it doesn't. (The compiler inlines the code.) I know because I'm pretty picky about this sort of thing - it was why I was using goto in the first place.
> RAII
RAII can work, but it's a bit clunky compared to a nested function call. Additionally, if the code being factored is not necessarily the same on all paths, that doesn't fit well with RAII.
- simias 9y agoBoilerplate in term of characters typed, not resulting code size. Adding a bunch of function declarations adds a significant amount of noise IMO. >RAII can work, but it's a bit clunky compared to a nested function call. Additionally, if the code being factored is not necessarily the same on all paths, that doesn't fit well with RAII. I think I'd need to see an example of what you're talking about then because I don't quite understand how your method works exactly.
- vardump 9y agoBoilerplate doesn't mean (binary) bloat.
- WalterBright 9y agoRather than debate, here's an example of replacing goto's with a nested function: https://github.com/dlang/dmd/pull/6656/files https://github.com/dlang/dmd/pull/6656/files
- vardump 9y agoI guess it's a matter of taste, but I often (not always) prefer less return statements in a function with gotos to error handling/cleanup code. Especially in kernel mode drivers.
- WalterBright 9y agoCheck the asm code generated by your compiler - it may optimize multiple returns into one.
- vardump 9y agoNot performance or code size I'm concerned, it's mainly about correctness. Stuff like input validation and releasing a spinlock in kernel code.