It seems to me that one statement per line was the recommendation of Code Complete , which stated that such code was easier to understand. To make each expression do one and only one, so it is very easy to see very quickly at a glance what is happening in the code.
I personally like to have return types in variables to make it easier to check (or even change) in the debugger.
One answer indicated that there was a difference in the generated code. I sincerely doubt that with an optimizing compiler.
The drawback prior to C ++ 11 for multiple lines is that you need to know the return type for the variable declaration. For example, if the return is changed from bool to int, then depending on the types you use, you may have a truncated value in a local variable (which can lead to a malfunction). If compiling with C ++ 11 enabled, this can be solved using the auto keyword, as in:
auto AwesomeResult = SomeBoolReturningFunc() ; if ( AwesomeResult ) {
Stroustrup C ++ 4th edition recommends putting the variable declaration in the if statement itself, for example:
if ( auto AwesomeResult = SomeBoolReturningFunc() ) {
His argument is that this limits the scope of the variable as much as possible. Regardless of whether it is more readable (or debugged) is a challenge to the solution.
source share