Saya lebih suka Opsi A
bool a, b, c;
if( a && b && c )
{
//This is neat & readable
}
Jika Anda memiliki variabel / kondisi metode yang sangat panjang, Anda dapat memutus barisnya saja
if( VeryLongConditionMethod(a) &&
VeryLongConditionMethod(b) &&
VeryLongConditionMethod(c))
{
//This is still readable
}
Jika lebih rumit lagi, saya akan mempertimbangkan untuk melakukan metode kondisi secara terpisah di luar pernyataan if
bool aa = FirstVeryLongConditionMethod(a) && SecondVeryLongConditionMethod(a);
bool bb = FirstVeryLongConditionMethod(b) && SecondVeryLongConditionMethod(b);
bool cc = FirstVeryLongConditionMethod(c) && SecondVeryLongConditionMethod(c);
if( aa && bb && cc)
{
//This is again neat & readable
//although you probably need to sanity check your method names ;)
}
IMHO Satu-satunya alasan untuk opsi 'B' adalah jika Anda memiliki elsefungsi terpisah untuk dijalankan untuk setiap kondisi.
misalnya
if( a )
{
if( b )
{
}
else
{
//Do Something Else B
}
}
else
{
//Do Something Else A
}