Subjective applicable value
This particular part of the standards is a strong suggestion. It's known that some developers may strongly disagree with what is proposed here. If you don't mind the visual indication of an empty string with "" (double quotes) then feel free to ignore this section or implement the Null function not as a standard but as an option.
Empty strings should, when possible, not be used within calculation code where clarity may be improved by the use of a Null function. A blank custom function named "Null" should be created and can be used in place of an empty string "". Within solution code this increases code readability and distinguishes literal values and escaped text from empty values.
Less than one second
Is all it takes to create the Null function. Open File > Manage > Custom Functions..., click New..., type "Null", click OK and you're done. You don't even have to type the double set of quotes within the result area. Just a blank empty function named Null is all you need.
Example use of Null:
Case (
If ( PatternCount ( Table::fieldName ; Indent & Indent ) ≥ 1 ;
"Awesome use of indentation!";
Null
);
If ( PatternCount ( Table::fieldName ; Indent ) ≥ 1 ;
"Good code should be easy to read";
Null
);
Null
)
/*
Note the above function uses another custom function
which simply returns a tab character, named Indent,
in order to improve readability.
*/
The above code would normally look like this.
Case (
If ( PatternCount ( Table::fieldName ; " " & " " ) ≥ 1 ;
"Awesome use of indentation!";
""
);
If ( PatternCount ( Table::fieldName ; " " ) ≥ 1 ;
"Good code should be easy to read";
""
);
""
)
Here are some use comparisons. All variations are completely acceptable.
If ( IsEmpty ( Table::nameFirst ) ; "No first name" ; Table::nameFirst )
If ( Table::nameFirst = "" ; "No first name" ; Table::nameFirst )
If ( Table::nameFirst = Null ; "No first name" ; Table::nameFirst )
Here's a series of test cases for clarification - the subtle differences between Null, the reserved word False and "" (literal empty string):
Expression | Result | Notes |
---|---|---|
Null |
Result is empty. | |
GetAsBoolean ( Null ) |
0 | GetAsBoolean returns 0/1 for expression results. |
not Null |
1 | The boolean inverse of Null, or 1. |
Null = 0 |
0 | False: This is boolean false because it does not evaluate empty to reserved word False (0). |
GetAsBoolean ( Null ) = 0 |
1 | True: The explicit boolean interpretation of Null is 0. |
GetAsBoolean ( Null ) = False |
1 | True: A different adaptation - reserved words True and False are evaluated to the boolean 0/1 values, so 0 = 0. |
Null = False |
0 | False: This is the most interesting case of all. Null is technically empty and False evaluates to boolean 0, so they are not equal. |
Null = "" |
1 | True: The literal empty string "" evaluates the same as the empty return of Null. |
Use exception
Code within a custom function can and should use double quotes for empty values "". This decreases custom function dependencies on the "Null" function - making them more portable for copy/pasting.