DEV Community

Discussion on: Code Tip: Avoid unnecessary else statements

dvddpl profile image
Davide de Paolis

totally agree. less code to read, less indentation, less complexity. I am not a fan of multiple returns because they could easily be overlooked - especially "if block has a fair amount of code" as stated in other comments. But, if method is big and has a fair amount of code maybe it makes sense to split it into smaller bits and have the main method just deal with the necessary logic and return as soon as possibile.

Returning as soon as possible also means easier debugging because you dont have to go through the entire method to be sure your temporary variable is being modified by some other if-else down the chain.