更多关于化妆品(if-statements) [英] More on the cosmetics (if-statements)
问题描述
您更喜欢哪个:
/ * A * /
int k = 402;
if(k == 40){
std :: cout<< 40 \ n;
}其他{
std :: cout<< 不是40 \ n;
}
/ * B * /
if(k == 40)std :: cout << 40 \ n;
其他std :: cout<< Not 40 \ n;
我知道这取决于品味,但我只是很好奇,并希望听到你的专业人士和'con''
s。
Which would you prefer:
/* A */
int k = 402;
if ( k == 40) {
std::cout << "40\n";
} else {
std::cout << "Not 40\n";
}
/* B */
if ( k == 40) std::cout << "40\n";
else std::cout << "Not 40\n";
I know it depends on taste but I am just curious and would like to hear
your pro''s and con''s.
推荐答案
桌面aécrit:
desktop a écrit :
您更喜欢哪种:
/ * A * /
int k = 402;
if(k == 40){
std :: cout<< 40 \ n;
}其他{
std :: cout<< 不是40 \ n;
}
/ * B * /
if(k == 40) std :: cout<< 40 \ n;
其他std :: cout<< Not 40 \ n;
我知道这取决于品味,但我只是很好奇,想听听你的专业人士。和骗子。
Which would you prefer:
/* A */
int k = 402;
if ( k == 40) {
std::cout << "40\n";
} else {
std::cout << "Not 40\n";
}
/* B */
if ( k == 40) std::cout << "40\n";
else std::cout << "Not 40\n";
I know it depends on taste but I am just curious and would like to hear
your pro''s and con''s.
/ * C * /
// ...
const int magic_k = 402;
// ...
const int special_k = 40;
// k是......
int k = magic_k;
//
if(special_k == k)
{
std :: cout< ;< 40 \ n;
}
其他
{
std :: cout<< ; 不是40 \ n;
}
至于命题B,它在内部规范中被明确禁止
最后两个compagny我去过。
Michael
/* C */
// ...
const int magic_k = 402;
// ...
const int special_k = 40;
//k is ...
int k = magic_k;
//
if ( special_k == k )
{
std::cout << "40\n";
}
else
{
std::cout << "Not 40\n";
}
As for proposition B, it was explicitely forbidden in internal norm in
the last two compagny I''ve been.
Michael
5月31日下午3:13,桌面< ; ... ... @ sss.comwrote:
On May 31, 3:13 pm, desktop <f...@sss.comwrote:
您更喜欢哪种:
/ * A * /
std :: cout< 40 \ n;
}其他{
std :: cout<< 不是40 \ n;
}
/ * B * /
if(k == 40) std :: cout<< 40 \ n;
其他std :: cout<< Not 40 \ nn;
我知道这取决于品味,但我只是很好奇,想听听你的专业人士的b $ b和骗子。
Which would you prefer:
/* A */
int k = 402;
if ( k == 40) {
std::cout << "40\n";
} else {
std::cout << "Not 40\n";
}
/* B */
if ( k == 40) std::cout << "40\n";
else std::cout << "Not 40\n";
I know it depends on taste but I am just curious and would like to hear
your pro''s and con''s.
为了维护和后来的纠正/改进''A''更好;
更好;它可以防止因后期编辑而产生的算法错误并且
forggeting braces。
for the sake of maintanance and later correction/improvement ''A'' is
better ;it prevents algorithmic errors due to later editing and
forggeting braces.
desktop写道:
desktop wrote :
你更喜欢哪个:
/ * A * /
int k = 402;
if(k == 40){
std :: cout<< 40 \ n;
}其他{
std :: cout<< 不是40 \ n;
}
/ * B * /
if(k == 40) std :: cout<< 40 \ n;
其他std :: cout<< Not 40 \ n;
我知道这取决于品味,但我很好奇,想听听你的
pro''和骗子。
Which would you prefer:
/* A */
int k = 402;
if ( k == 40) {
std::cout << "40\n";
} else {
std::cout << "Not 40\n";
}
/* B */
if ( k == 40) std::cout << "40\n";
else std::cout << "Not 40\n";
I know it depends on taste but I am just curious and would like to hear your
pro''s and con''s.
/ * C * /
if(k == 40)
std :: cout< < 40 \ n;
其他
std :: cout<< Not 40 \ n;;
我想在单独的行上使用括号,但是对于复合语句
只有一个内部产生太多混乱的声明,所以我不会为那些人使用大括号。
亲:它看起来更干净(至少对我来说)
Con:在扩展语句时你必须添加大括号,这可以忘记
- 西尔维斯特
/* C */
if (k == 40)
std::cout << "40\n";
else
std::cout << "Not 40\n";
I''d like to have braces on separate lines, but for compound statements
with only a single inner statement that produces too much clutter, so I
won''t use braces for those.
Pro: it looks cleaner (to me at least)
Con: you''ll have to add the braces when extending the statements, which
can be forgotten
- Sylvester
这篇关于更多关于化妆品(if-statements)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!