View Single Post
Old 02-02-2021, 09:43 AM   #38
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 14,574
Karma: 108666825
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Quote:
Originally Posted by hobnail View Post
Gotta watch out for those dangerous returns.
The problem is more subtle.
1) The section MUST be in a separate function or procedure
2) Fails if copied and pasted into bigger piece of code, the Case, Select or nested ifs do not.
3) You might want the same thing related to that piece of code done after each option. The version with returns incorrectly separates it to where it's called.
4) A call and return may be slower and use more stack. Depends on language and CPU. The Case, Select or nested ifs may translate to skips or short jumps or a jump table.

As a general principle there should only be a return before the last statement in a procedure/function that's return if it's a special error trap.
Quoth is offline   Reply With Quote