I would like to have an if-then-else shorthand syntax like in java with a little bit of python spice.
You all know the following syntax: condition ? expression1 : expression2
I do not stick to this exact syntax, especially because the colon is currently a reserved operator, but there are enough characters left to find a self-explanatory implementation.
It will return the result of expression1 if the condition is true otherwise the result of expression2. It is important to execute only the neccessary expression, why it is not possible to use a selfmade function, because all given parameters will be executed before calling the function.
Python has a bool() function which will return true or false according to well defined rules and you can pass frankly anything to it.
As a combination of both parts and adopted to lotusscript you could wirte much shorter and more readible code when it comes to complex conditions based on different kind of values.
Lotusscript Data Type |
bool() = false |
bool() = true |
Boolean |
false / 0 |
true / -1 |
Integer, Long, Single, Double, Currency |
0 |
any other number |
String |
length() = 0 |
length() > 0 |
List (any kind) |
one or more elements |
no elements |
Object reference or user defined class |
set to an instance |
Nothing |
User defined data type |
always true |
-- |
Variant |
if empty otherwise depending on value |
if value equals true |
Array |
uninitialized
depending on value for single dimension single value
|
more dimensions and or values
depending on value for single dimension single value
|
If you want to increase a value of a number field by 1 and you are not sure if the fieldvalue is allready a number or empty, which means an empty string, you have to some checks based on datatype or converted values to determin if it is save to add another number. Every programmer may have it's own way of donig it. But how nice would it be to use something like this:
Dim currentValue As Variant
currentValue = doc.GetItemValue("Numberfield")(0)
currentValue ? doc.ReplaceItemValue("Numberfield",currentValue + 1) : doc.ReplaceItemValue("Numberfield",1)
' or something like this, if you are not sure if doc is nothing or not
Dim doc As NotesDocument
doc ? doc.remove(true)
And there is a lot more everyone would befint from, like the missing function the check if a list has an element.