I was populating a listbox from a database today, and the compiler complained about an Nil object exception in my Shipment object - a date field. All fine, I began looking for a nice null coalescing operator; specifically something like VB.Net’s IIF.
Xojo doesn’t have that but I found that Xojo’s “If” operator is ternary. I never noticed that in the IDE and I’m super impressed.
Rather than doing something “long” like
If shipment.Received Is Nil Then
Me.Cell(Me.LastIndex, 11) = ""
Else
Me.Cell(Me.LastIndex, 11) = shipment.Received.SQLDate.ToText
End If
You can just do this; I find it much cleaner (which I realize is an opinion):
Me.Cell(Me.LastIndex, 11) = If (shipment.Received Is Nil, "", shipment.Received.SQLDate.ToText)
I recently discovered this as well and I’m chagrined to know how long I overlooked it. Now my problem is that I forget to use it because I’m so used to it not being there…