Timeline for Where did the notion of "one return only" come from?
Current License: CC BY-SA 3.0
19 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 10, 2020 at 14:58 | comment | added | gnasher729 | Call it function_ instead of borderline illegal _function. | |
| Jan 1, 2020 at 1:32 | comment | added | Tinmarino | In this case, you should use a decorator like @log_debug | |
| Jun 25, 2018 at 9:42 | comment | added | Max Barraclough | Wouldn't it be better to avoid using the possibly illegal identifier of _function for our 'inner function'? stackoverflow.com/a/228797 | |
| Jul 6, 2017 at 21:57 | history | edited | Deduplicator | CC BY-SA 3.0 | added syntax-highlighting |
| Jun 12, 2017 at 13:45 | comment | added | user541686 | You can't just refactor into _function though. (cc @nakh) How would you log intermediate variables if you needed to? You'd have to return a tuple or struct or something that returns all of them which would mean repeating their names several times. The nice thing about a single return is that it avoids code repetition, lets you identify where to insert extra code later, and gives you access to all the local variables you want to inspect/output, especially when debugging. | |
| Feb 16, 2016 at 20:40 | history | edited | Damian Yerrick | CC BY-SA 3.0 | s/debugging/logging/ per Piotr Perak's comment; incorporate opposing view from other comments |
| Dec 18, 2015 at 19:30 | comment | added | Koray Tugay | @JeffSahol Well you may never have a new functionality.. And refactoring should not be difficult if new functionality actually is implemented.. | |
| Jan 13, 2015 at 16:13 | comment | added | perreal | @spaaarky21, check this out: blog.awilkins.id.au/2011/10/c-source-to-source-translation.html | |
| Nov 26, 2014 at 20:16 | comment | added | spaaarky21 | @Peri Thank you. Printing is a primitive way of debugging but this is just ridiculous. If I had the reputation on this site, I'd love to downvote this answer. | |
| Dec 14, 2013 at 9:08 | comment | added | Piotr Perak | printing != debugging. That's not argument at all. | |
| Nov 21, 2011 at 21:56 | comment | added | Abyx | In some debuggers (MSVS) you can put breakpoint on last closing brace | |
| Nov 13, 2011 at 19:41 | comment | added | ruakh | Honestly, if I were maintaining that code, I'd rather have a sensibly-defined _function(), with returns at appropriate places, and a wrapper named function() that handles extraneous logging, than have a single function() with contorted logic to make all returns fit into a single exit-point just so I can insert an additional statement before that point. | |
| Nov 11, 2011 at 16:17 | history | made wiki | Post Made Community Wiki by Eugene - AmberPixels | ||
| Nov 10, 2011 at 16:43 | comment | added | JeffSahol | For a similar reason, it also makes it easier to extend (add to) the function, since your new functionality doesn't have to be inserted before each return. Say you needed to update a log with the result of the function call, for example. | |
| Nov 10, 2011 at 11:03 | comment | added | Skizz | I would also add that it makes debugging easier because you only ever need to set one breakpoint to catch all exits* from the function. I beleive that some IDEs let you put a breakpoint on the close brace of the function to do the same thing. (* unless you call exit) | |
| Nov 9, 2011 at 15:55 | history | edited | perreal | CC BY-SA 3.0 | edited body |
| Nov 9, 2011 at 15:45 | comment | added | user712092 | +1 good point. Printing debugging is useful to me and this is good idea for it. | |
| Nov 9, 2011 at 15:30 | history | edited | perreal | CC BY-SA 3.0 | added 249 characters in body |
| Nov 9, 2011 at 15:20 | history | answered | perreal | CC BY-SA 3.0 |