I'm reviewing our Visual C++ code base and see lots of helper functions with really short bodies. Like for example this:
inline int max( int a, int b ) { return a > b ? a : b; }
the problem is when code is debugged in Visual Studio debugger it's impossible to immediately see what a
and b
are upon entering the function with F11 ("step into"). One just presses F11 and the "current line" pointer points onto the line with the opening brace, then after F10 ("step over") control goes out of the function. That's not very convenient.
The alternative would be to rewrite all those function so that the body payload occupies a separate line:
inline int max( int a, int b )
{
return a > b ? a : b;
}
now when F11 is pressed the "current line" pointer points onto the opening brace, then after F10 control passes onto the payload and one can see what values a
and b
have. If one doesn't care and just entered this function while some complex expression is being evaluated he can press Shift-F11 and bail out of the function - but he could do this in the former case as well, so there're no major negative changes in debugging experience.
Are there any drawbacks in such code transformation? Any reasons to keep the function body on the same line as the function signature?