Synopsis: | Don't return a function at an unexpected location |
Language: | C# |
Severity Level: | 9 |
Category: | Control flow |
Description: |
Minimize the number of returns in each routine. It's harder to understand a routine if, reading it at the bottom, you're unaware of the possibility that it returned somewhere above. Use a return when it enhances readability. In certain routines, once you know the answer, you want to return it to the calling routine immediately. If the routine is defined in such a way that it doesn't require any cleanup, not returning immediately means that you have to write more code. |
Literature References: |
StackOverflow |