Not really a question of how-do-I...
-
Hmmm... is this dumb or brilliant?
if ((logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused) &&
e.KeyCode == Keys.Up)
{as opposed to:
if (( (logicalTabs && tabs_General1.cbException.Focused) ||
(!logicalTabs && tabs_General1.cbJobStatus.Focused) ) &&
e.KeyCode == Keys.Up)
{I can't decide now. :~ Readability contrasting with good practice?
-
Hmmm... is this dumb or brilliant?
if ((logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused) &&
e.KeyCode == Keys.Up)
{as opposed to:
if (( (logicalTabs && tabs_General1.cbException.Focused) ||
(!logicalTabs && tabs_General1.cbJobStatus.Focused) ) &&
e.KeyCode == Keys.Up)
{I can't decide now. :~ Readability contrasting with good practice?
The second one is a lot easier to read - you have to stop and think about the first one.
The only instant messaging I do involves my middle finger.
-
Hmmm... is this dumb or brilliant?
if ((logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused) &&
e.KeyCode == Keys.Up)
{as opposed to:
if (( (logicalTabs && tabs_General1.cbException.Focused) ||
(!logicalTabs && tabs_General1.cbJobStatus.Focused) ) &&
e.KeyCode == Keys.Up)
{I can't decide now. :~ Readability contrasting with good practice?
I prefer the first method, but for readability would split it into two separate statements by using an extra variable:
bool focused = logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused;
if (focused && e.KeyCode == Keys.Up)
{ -
Hmmm... is this dumb or brilliant?
if ((logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused) &&
e.KeyCode == Keys.Up)
{as opposed to:
if (( (logicalTabs && tabs_General1.cbException.Focused) ||
(!logicalTabs && tabs_General1.cbJobStatus.Focused) ) &&
e.KeyCode == Keys.Up)
{I can't decide now. :~ Readability contrasting with good practice?
if (e.KeyCode == Keys.Up)
{
bool focused = logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused;
if(focused )
{
// Your Logic
}
}I think it would be also a choice... :)
Life is all about share and care... public class Life : ICareable,IShareable { // implements yours... }
-
I prefer the first method, but for readability would split it into two separate statements by using an extra variable:
bool focused = logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused;
if (focused && e.KeyCode == Keys.Up)
{ -
Hmmm... is this dumb or brilliant?
if ((logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused) &&
e.KeyCode == Keys.Up)
{as opposed to:
if (( (logicalTabs && tabs_General1.cbException.Focused) ||
(!logicalTabs && tabs_General1.cbJobStatus.Focused) ) &&
e.KeyCode == Keys.Up)
{I can't decide now. :~ Readability contrasting with good practice?
The first is nasty. Embedding one ternary expression in a second or an if results in hard to read code. I'd say it's a tossup between the second and putting the ternary in a temp. Mostly that comes down to if the temp has any intrinsic meaning on its own (regardless of if it's used in a second place).
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
Hmmm... is this dumb or brilliant?
if ((logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused) &&
e.KeyCode == Keys.Up)
{as opposed to:
if (( (logicalTabs && tabs_General1.cbException.Focused) ||
(!logicalTabs && tabs_General1.cbJobStatus.Focused) ) &&
e.KeyCode == Keys.Up)
{I can't decide now. :~ Readability contrasting with good practice?
-
Hmmm... is this dumb or brilliant?
if ((logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused) &&
e.KeyCode == Keys.Up)
{as opposed to:
if (( (logicalTabs && tabs_General1.cbException.Focused) ||
(!logicalTabs && tabs_General1.cbJobStatus.Focused) ) &&
e.KeyCode == Keys.Up)
{I can't decide now. :~ Readability contrasting with good practice?
Only use a ternary where you can't use an
if
; why the elephant would you ever use one in anif
? :wtf: -
Hmmm... is this dumb or brilliant?
if ((logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused) &&
e.KeyCode == Keys.Up)
{as opposed to:
if (( (logicalTabs && tabs_General1.cbException.Focused) ||
(!logicalTabs && tabs_General1.cbJobStatus.Focused) ) &&
e.KeyCode == Keys.Up)
{I can't decide now. :~ Readability contrasting with good practice?
Maybe it's just my brain but the ternary expression is clearer for me :) That being the case I'd never write it this way in code. Complex conditions would most likely be moved into variables like someone has answered already, i.e.:
bool tabsAreLogical = logicalTabs ? tabs_General1.cbException.Focused : tabs_General1.cbJobStatus.Focused;
if(tabsAreLogical && e.KeyCode == Keys.Up) {
}
This makes it easier to read/change later, as well as making the condition reusable later in code.
-
Only use a ternary where you can't use an
if
; why the elephant would you ever use one in anif
? :wtf:Doing so is very iffy.
Keep Clam And Proofread -- √(-1) 23 ∑ π... And it was delicious.