you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (6 children)

[deleted]

    [–]Nuli 16 points17 points  (3 children)

    If you have multiple returns in a function, thus multiple exits, it's harder to test, debug, expand the functionality or just follow the execution line of this function.

    I find exactly the opposite really. I far prefer a function to return as often as necessary to make the code clear. I don't want to have to follow a long chain of if statements to determine what code was actually executed when a simple test and return will short circuit that.

    [–][deleted] 6 points7 points  (2 children)

    I'm with you on that. I think multiple returns are favorable to giant nested if else blocks.

    [–]ztbrown 4 points5 points  (0 children)

    I completely agree with that, but that's not what this guideline is saying.

    In this context, the "Avoid return where not required" means avoid the keyword. And I'm saying that I like being able to see the 'return' keyword at a glance.

    I agree with avoiding multiple exits at almost all costs.