Unlike many other programming languages, FileMaker uses the semicolon as a separator between parameters to a function. In many cases this will appear as line endings within code. While FileMaker does not use terminating line endings, it can appear as such. The following guidelines are provided in order to increase the readability and interpretation of FileMaker code.
- Use Hard Tabs: Calculation code should use hard tabs (not spaces) for better readability within the calculation dialog box.
When editing code within the calc dialog box you can use Option-Tab (Mac) or Control-Tab (Win) to insert tabs.
- Maintain spaces between function names and function parameters. This accommodates the cross-platform aspect of double-clicking to highlight function names or parameters on Windows.
Line endings with semicolons: Should not include a space when the line of code is considered "complete". This is done in order to provide a "continuation clue" about the code being read. See the following example. Note that line 7 is an If() statement which uses multiple lines. The space after the test parameter of the If () functions indicates that the function has not been "completed" or "closed". Compare this to lines 2-5 where each variable declaration of the Let() function is considered completed.
Let ( [ ~developers = List ( "" ; "" ); ~version = Get ( ApplicationVersion ); ~isGo = PatternCount ( ~version; "Go" ) = True; ~versionNumber = GetAsNumber ( Substitute ( ~version ; "," ; "." ) ); ~extendedPrivileges = If ( ~isGo or ~versionNumber ? 11 ; Evaluate ( "Get ( AccountExtendedPrivileges )" ) ; /*else*/ Evaluate ( "Get ( ExtendedPrivileges )" ) ) ]; PatternCount ( ¶& ~developers &¶ ; ¶& Get ( AccountName ) &¶ ) ? 1 or PatternCount ( ¶& ~extendedPrivileges &¶ ; ¶& "developer" &¶ ) ? 1 or If ( ~isGo or ~versionNumber ? 11 ; Evaluate ( "Get ( AccountPrivilegeSetName )" ) = "[Full Access]" ; /*else*/ Evaluate ( "Get ( PrivilegeSetName )" ) = "[Full Access]" ) )
Hard tabs (option tab)in the calculation dialog may not work prior to v11
It doesn't work for me in v10 (mac), and I can't find a conflict that might be preventing it.
Typing a hard tab in the calculation dialog on Macintosh workstations was a new feature in FileMaker 11. You can't type a tab into the calculation dialog in FileMaker v10, but you can paste a tab from a text editor, and any tabs in the text do render correctly.
I'm not sure it's worth the slight pain in the ass to use the opt-Tab, since the benefit of a 'real' tab over two space characters is so small, and I've never seen a downside in using two spaces. Further, I submit that two spaces is sufficient to achieve readability in a calculation, and it's faster to type them than Option-Tab.
The primary reason I opted for the tabs was for readability within the calc dialog box. I was personally using 2 spaces, as is the case for many other programming languages ( also something I do when creating Drupal modules in PHP )
There is a calculation formatter which was created by Debi Fuchs and it works as a starting point. The goal is to make calc code as readable as possible. To this end, if it's that much of a pain, I would probably say use the two spaces and then run it through a Calc cleanup tool.
I personally use these tools on the Macintosh to automatically have tabs used, plus function expansion.
FileMaker 11 Only
You'll need FileMaker 11 to use QuickCursor on the Mac because FileMaker 11 is now a Cocoa app
Maybe someone (or myself) will make a calc cleanup tool in FileMaker. Regex will need to be used to accomplish this well - any takers?
I've been working on updating the FileMaker TextMate bundle the last few days and I'm pretty close to having the regex stuff necessary to make a calc formatter. More on that later once I get it all finished, not just "kinda sorta working"...
As a side note I bumped into an interesting "glitch" with Let (  ) function declarations and getting code folding to behave. Not sure where we had the discussion, but in order for code folding to work properly I've resorted to the following template for Let. It's a bit of a space waste, but worth it now that you couldn't pry TextMate out of my cold, dead hands! :)
The sample above allows to fold the entire let, or just the inner bracketed block...so nice!
all the links above point to the same place...
Sorry, went too fast on the copy paste. You can also find the links here on the Editors page in the Developer's Tools section I've started.
This would work better if Filemaker fixed the inconsistency between Mac and Windows versions ( might be a system thing )
If I put tabs into a comment line on a Mac it formats the line properly but on the Windows version it puts a square....
I'm coming new to this site, but wanted to comment on this discussion.
Tab vs. Spaces has been a long running battle in our group. We have standardized on spaces. The main issue was/is "What is a tab"? So many editors define tabs at different lengths. BBEdit defaults to four (if I remember correctly) where VI is eight. I see indicated that some are using TextMate. What is the default "width" of a tab?
As you move from one editor to the next, this can make the code more unreadable. For example, you have a statement where you need to indent multiple times (nested if or case statement). In one editor it would look fine, but when another one is used and a tab stop is set to 10, now your code is pushed to the middle of the page and could cause other problems like wrapping.
This is why we standardized on 3 spaces. It was enough of an indent to give meaning and it would be formatted the same regardless of the editor being used.
In every text editor I've ever worked with (excepting the FileMaker calculation dialog), the default width of a tab stop is customizable. (I use BBEdit/Text Wrangler these days.) A tab is whatever you want it to be, which is the beauty of it. If you like your indents every three spaces, and I like mine every five spaces, tabs can keep us both happy. Tabs will even keep you happy if you don't use a monospaced font and you don't define tab stops in terms of spaces. If you do want to standardize on a specific width for tabs (I don't, for the record), then you can set that in the preferences for your text editors, and now code from anyone else using tabs will fit into your standardized indent size. Some people just like to do things differently from others, and tabs accomodate that better than spaces.
For those Windows users, I use...
When looking at it from the perspective of a new user who is trying to get a handle on the standards, I have a bit of difficulty with suggesting that the "standard" is to use a character than can not be properly typed in the context in which it should be used. In other words, until FileMaker allows you to type a tab by hitting the tab key, we're making a standard out of using a hack... and primarily (as far as I can tell) to helpfully support the workflow of people who do not actually *use* the FileMaker tools to write their calculations.
I love writing the standard to say that whitespace is critical. If we want to link to a Best Practice that says that there are advantages to using the "tab hack", also awesome. But making the tab a standard is (personally) reaching too far within the standard itself.
FileMaker 11 lets you insert a tab with ctrl+Tab (Windows). Doesn't work in 10 or earlier, I believe. I mainly use AutoHotKeys to insert special characters that I can't remember the character code for (alt+####) or for shortcuts based on the keyboard I am using. For instance, the one keyboard I use has a Function key where my finger wants a ctrl key. So instead, I created a script in AHK that replaces three spaces with a ctrl+Tab as I type.
I did not mean to suggest that I *am* a new user. I know that it is possible to insert a tab character. My issue is that in order to insert a tab character, you have to hit something other than the tab key. Personally, by definition, this is a hack. If FileMaker 12 changes to using the tab key to insert a tab, and option-tab (for the mac users) to change focus, I will change my tune.
Try explaining to a new user that the "standard" is to use a hack / "undocumented feature" to force a character to show up within a context that *seems* designed specifically to exclude the character. Or explaining that the best way to comply with the FileMaker standards is to install special software...
I apologize if this comes across as pedantic, but I see no difference between this and saying that the only way to get the character "p" is to type option-p... I can assure you that my systems would not use the letter "p" very often.
So, Proposed: The standard should call for active use of whitespace, and link to a best practice that advises injecting a tab.
So, just to play devil's advocate is using shift+p considered a "hack" in order to get "P"?
The modifier keys on a keyboard are there for exactly this purpose - to modify output of a keystroke. I could understand the perspective of using opt+tab being a hack if we had to modify the FileMaker application to make it work. Fact is that we aren't modifying the application binary to use this technique, more accurately we've found a behavior in the expression editor that isn't discussed in the help files provided by FMI.
Everyone I've shown the opt+tab behavior to is delighted to see that we now have a way to organize code just like a majority of other text editors have and subsequently most other programming languages use.
All that being said these standards are written with the majority in mind and ease of use, readability and organization of calculation code as a primary goal. Jeremy says it best in a comment on the main page - these aren't hard and fast laws and if you need to adapt the standards to fit your workflow / style better, please do so!
ctrl+Tab is a fairly standard keystroke in many applications, especially applications that use a tab to bounce around the application.
Hack is exactly the term I would use for it (for reasons that Perren already mentioned). With tab having become the primary way to move from field-to-field and object-to-object, you need to have an alternate way to insert the character itself. I think users get that...even if they aren't familiar with it, I've rarely seen someone that doesn't understand the concept.
Besides, this is really a discussion on Developer Standards. Developer implies that the person is at least tech savy enough to create a software solution. For your users, you can hijack the FileMaker default behavior to fit your end user's needs.
Correction..."Hack isn't exactly the term I would use..."
I've been racking my brain trying to come up with another application that uses a key combination to insert a tab, and I can't come up with one. Perhaps this is more prevalent on the Windows side than on the Mac side, or perhaps it is possible in many more applications that I use, but I'm unaware that it is an available feature. Since the only one I *currently* know about is FileMaker, it feels like a standards-defying hack.
Where else is it used?
Primarily HTML text areas. Not all, but many of the web forms and web applications I use that have larger text fields, ctrl-tab is the only way to insert a tab.
Outside of that, DBMS will use the key stroke to insert a tab, because the straight tab key moves to the next field. A few desktop publishing applications.
It's by no means a standard implementation, but still fairly common. Far more common than, for example, FileMaker's use of ctrl-shift-B to bold text in a field.