4 ms·
I sincerely hope that most people are not dealing with functions of that length, such that error handling is lost at the bottom of hundreds of lines of code. W
by michaelteter 3y ago
I sincerely hope that most people are not dealing with functions of that length, such that error handling is lost at the bottom of hundreds of lines of code.
Whether you do return-early or nested if-else, there's little reason for having such lengthy functions. Dealing with THAT should be the priority, not the nesting vs return-early.
- eyelidlessness 3y agoYour logic has to flow somewhere. I prefer shorter functions too, but sometimes the actual “unit” is just not so concise without breaking it up in confusing ways. Handling edge cases first makes that much more digestible, IME.
- runarberg 3y agoForcefully breaking up your logic in places where it doesn’t make sense is an antipattern IMO, and makes it very easy to write spaghetti. I’ve inherited codebases with this overemphasis on very short functions and what I saw were very specific utility functions in dozens of different modules, all over the codebase, often with funky names, surrounded by dead code, and never a clear path to and from it. Sometimes a single function that spans even a couple of hundred lines, is preferable.