« Develop custom functions more effectively using a simple test unit | Main | Assert Equals(): a custom function to test other custom functions »

“Constant” custom functions to save time and write clearer code

Using some values in FileMaker formulas and scripts isn't very convenient because they are difficult to type or not clearly visible. The samples of these are spaces and tab characters, special symbols like "¶" and an empty value. A possible solution is to use “constant” custom functions instead. Here's a description of four: NULL, TAB, CR and SPACE.

Technorati tags: , , , .

Sometimes it may be difficult to tell a tab character from a space:

This field & " " & That field

What is in quotes? Not quite evident, especially when you're reading the code when you had been doing other stuff for a few weeks. A clearer code would be more helpful:

This field & TAB & That field

The TAB here is a constant custom function. A “constant” custom function is a function that takes no parameters and always returns the same result. The TAB returns a tab character, of course. Note that a function with no parameters require no parentheses so the code looks pretty.

Such a function can also save you some time when you have to enter tabs or other difficult-to-type characters often. A good example of such a character is the "¶" symbol in Windows. I love using the CR function instead.

Similar thing happens with an empty value, most often when you want to empty a field. A couple of quotes sometimes looks too subtle; a loud and clear NULL (my favorite) is way better.

I even use SPACE sometimes when I want to amplify there must be a space somewhere.

Test unit tests

Assert Equals( NULL, "" ) &
Assert Equals( TAB, " " ) & // use tab character here
Assert Equals( CR, "¶" ) &
Assert Equals( SPACE, " " )

What is a test unit?

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/510343/3292090

Listed below are links to weblogs that reference “Constant” custom functions to save time and write clearer code:

Comments

Hi

Looks good! Keep up the great work. It very impressive. Thanks!


G'night
















Post a comment

If you have a TypeKey or TypePad account, please Sign In