Search

What the Quote?

"You had me at Do While"

Chris Toohey

"Help...my quicksort is in an infinte loop!"

Eric Romo

"i can has cheezburger?"

lolcat

« Creepy | Main| RAMtastic »

Parenthetical

Category domino lotusscript
Despite the longwindity of most of my blog posts, when it comes to code, I'm a big fan of brevity (as you may have occasionally noticed). Which is why I'm fond of the ternary operator in JavaScript:

(OptionEnabled === 'Yes') ? doSomething() : doSomethingElse();

That's just a shortwindy replacement for the following:

if (OptionEnabled === 'Yes') {
doSomething();
} else {
doSomethingElse();
}

Basically, you're asking if the parenthesized evaluation returns True (hence the question mark), specifying what should occur if it is (before the colon), and a fallback if it isn't (after the colon).

You can, of course, do similar evaluations in Notes Formula:

isEnabled := @If(OptionEnabled = "Yes"; @True; @False)

...can be abbreviated (admittedly, that's pretty concise to begin with) to:

isEnabled := (OptionEnabled = "Yes");

But did you know that even LotusScript supports that kind of brevity? Instead of:

If (docConfig.GetItemValue("OptionEnabled")(0) = "Yes") Then
Let isEnabled = True
Else
Let isEnabled = False
End If

...you can get the same result with the following:

Let isEnabled = (docConfig.GetItemValue("OptionEnabled")(0) = "Yes")

Actually, you don't even need the parentheses... the order of operations dictates that the evaluation to the right must complete first in order to complete the leftmost evaluation. But the parentheses make it more readable. Sadly, you can't do this:

(docConfig.GetItemValue("OptionEnabled")(0) = "Yes") ? Call doSomething() : Call doSomethingElse()

But it'd be cool if you could.......

Comments

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)