非常奇怪:您在谈论可读性时,没有人提及代码中注释的用法:
if (somecomplicated_function() || // let me explain what this function does
someother_function()) // this function does something else
...
最重要的是,我总是在函数前添加一些注释,包括函数本身,输入和输出的注释,有时还会举一个示例,如下所示:
/*---------------------------*/
/*! interpolates between values
* @param[in] X_axis : contains X-values
* @param[in] Y_axis : contains Y-values
* @param[in] value : X-value, input to the interpolation process
* @return[out] : the interpolated value
* @example : interpolate([2,0],[3,2],2.4) -> 0.8
*/
int interpolate(std::vector<int>& X_axis, std::vector<int>& Y_axis, int value)
显然,用于注释的格式可能取决于您的开发环境(Visual Studio,Eclipse下的JavaDoc等)。
就SCE而言,我假设您的意思是:
bool b1;
b1 = somecomplicated_function(); // let me explain what this function does
bool b2 = false;
if (!b1) { // SCE : if first function call is already true,
// no need to spend resources executing second function.
b2 = someother_function(); // this function does something else
}
if (b1 || b2) {
...
}