This is acceptable:
Let ( ~someVar = FunctionalArea » Tablename::fieldName ; If ( ~someVar = "Active"; True; False ) )
This, however, may be more readable.
Let ( ~someVar = FunctionalArea » Tablename::fieldName ;
If ( ~someVar = "Active"; True; False )
)
Preferred:
Let (
[
~privateVariable = List ( "one" ; "two" ; "three" );
$localVariable = Substitute ( ~privateVariable ; [ ¶ ; "," ] );
$$GLOBAL.FIRSTVALUE = GetValue ( ~privateVariable ; 1 )
];
"Your Let function result is " & $localVariable
)
But also acceptable.
Let (
[
~privateVariable = List ( "one" ; "two" ; "three" );
$localVariable = Substitute ( ~privateVariable ; [ ¶ ; "," ] );
$$GLOBAL.FIRSTVALUE = GetValue ( ~privateVariable ; 1 )
];
"Your Let function result is " & $localVariable
)
And, here's an example where the opening bracket is combined with the opening parenthesis. Which requires less indentation.
Let ( [
// Notes about variables below.
~privateVariable = List ( "one" ; "two" ; "three" );
$localVariable = Substitute ( ~privateVariable ; [ ¶ ; "," ] );
/*
Use extra lines and embedded block comments
if more information is needed to describe
what is going on with the calculation logic!
*/
$$globalVariableTopValue = GetValue ( ~privateVariable ; 1 )
];
"Your Let function result is " & $localVariable
)
Code | Quality |
---|---|
]; |
good |
endOfFunction ) ]; |
bad |
Code | Quality |
---|---|
~someVariable |
good |
someVariable |
bad |
Don't like ~ ?
There are some cases where various languages make typing the tilde difficult. To the extent possible, you can use a shortcut or expansion software to map the tilde character to another keyboard sequence. Alternatively, if you choose to use a different character for locally scoped variables, stay consistent and try not to compete with other syntactic differentiators.
Here's a bad example where the word "prefix" is used both as a variable and is also a field name. Also note, we never use a space within variable names such as "full name".
Let ( [
prefix = "Modified by: ";
full name = People::First Name & " " & People::Last Name;
date = Get ( CurrentDate )
];
If ( not IsEmpty ( Full Name ) ;
prefix & People::prefix & full name & " on " & date
)
)
Did you also catch that Claris/FileMaker doesn't distinguish between "full name" and "Full Name". Make sure and stay case consistent! Here's a proper example.
Let ( [
~prefix = "Modified by: ";
~nameFirst = People::nameFirst;
~nameLast = People::nameLast;
~fullName = If ( not IsEmpty ( ~nameFirst & ~nameLast ) ;
~nameFirst & " " & ~nameLast
);
~date = Get ( CurrentDate )
];
If ( not IsEmpty ( ~fullName ) ;
~prefix & People::prefix & ~fullName & " on " & ~date
)
)
Alternate characters?
What's left to use if you don't want to use the tilde (~)? Well you could use the Number Sign (#) also known as the hash or pound symbol or you could try using the Percent Sign (%) or, some other unicode character. But, these standards suggest tilde (~). The @ symbol is not suggested because it's commonly used in documentation (e.g. @todo Fix this code). Some developers opt for a preceding underscore (_), and, while visually functional, is used in other ways within these standards.
Examples:
Let ( [
#prefix = "Modified by: ";
#nameFirst = People::nameFirst;
#nameLast = People::nameLast;
#fullName = If ( not IsEmpty ( #nameFirst & #nameLast ) ;
#nameFirst & " " & #nameLast
);
#date = Get ( CurrentDate )
];
If ( not IsEmpty ( #fullName ) ;
#prefix & People::prefix & #fullName & " on " & #date
)
)
Let ( [
%prefix = "Modified by: ";
%nameFirst = People::nameFirst;
%nameLast = People::nameLast;
%fullName = If ( not IsEmpty ( %nameFirst & %nameLast ) ;
%nameFirst & " " & %nameLast
);
%date = Get ( CurrentDate )
];
If ( not IsEmpty ( %fullName ) ;
%prefix & People::prefix & %fullName & " on " & %date
)
)
$hasReturns
~isTrailing
$containsSpaces
not ~containsEmailAddress
~shortenedFullName
$wasTimestamped