One instruction per line

This tip submitted by Ludovic Flender on 2011-06-20 12:20:50. It has been viewed 2544 times.
Rating of 5.2 with 5 votes



Use only one instruction on each line.
It will increase readability AND allow you to debug much more efficiently, since you will be able to watch the result of each function call separatly and directly.

Instead of:
{
    const bool result = function1(function2(function3()));
}


Prefer:
{
    const int res1 = function3();
    const Type res2 = function2(res1);
    const bool result = function1(res2);
}


Note the use of const correctness to make it clear that the variables are never modified. This makes it clear that you won't change these variables between the call to the function and their use as a function parameter.




More tips

Help your fellow programmers! Add a tip!