Deep nesting vs early returns

Jack Applegame japplegame at gmail.com
Thu Oct 4 07:45:14 UTC 2018


On Thursday, 4 October 2018 at 06:43:02 UTC, Gopan wrote:
> Certain people recommend that there be only one return 
> statement (usually at the end) from a function.  The said 
> advantage is that, in a maintenance code, if you later want to 
> do something before returning, you can add it just above the 
> return statement.
>  I have seen people enclosing the function logic inside a 
> while(1) merely to stick on to single return at the end.
>
> while(1)
> {
> 	...
> 	break; //otherwise return would come here.
> 	...
> 	break;
> }
>
> return ...;

In terms of code maintenance, multiple break statements have no 
difference from multiple return statements. Those people are just 
trying to deceive themselves.


More information about the Digitalmars-d mailing list