« September 2005 | Main | November 2005 »

FileMaker field naming conventions

I have been developing FileMaker applications for quite a long time (about 8 years) and have worked with different field naming conventions. Now I stick to the one I consider the best of all: natural field names.

I used to work, for example, with naming conventions that required me to name fields after their types (global, calculation), certain options (lookup) or roles (key). There were also standardized prefixes, so field names were quite cryptic like OopsThingAMaBobKeyGlob.

I hated this system. It wasn't difficult to understand and thinking up a name for a field was also very simple, because there was very little to think up, but in effect all the names looked same to me. I wasn't able to remember any of them and had to always pick them up from lists, which is a pain for a fast typist like me, especially when the typist is trying to write a complex FileMaker-4-5-6-style calculation.

I used to work with my own system too. I thought it would be fine to leverage the alphabet sorting as the only available field organization tool and designed a system with one-character prefixes to indicate field role. There were prefixes for data fields (d), derivative fields (e), interface-only fields (i), keys (k), script variables (s) and so on. A sample field name would be dName, eSum, iSaveButton, sCounter and so on. The field names were shorter, more readable, and easier to type — I almost never had to pick them from list and even if I had to, I was able to find a field in the list in seconds by typing first few characters of its name.

Unfortunately, the whole approach turned out to be wrong. Yes, automatic sorting is evil. When I sort fields manually, I express certain subtle relations between them: I usually group related fields together, and, for example, tend to put derived fields after source fields, and so on. As I said these relations are subtle, hard to formalize and often vary from table to table and from application to application. If I sort fields automatically, I'll lose all these tiny bits of information that help me to better control the development process.

When I understood this, the rest was straightforward. If I sort fields in what I think is their natural order, I should give them natural names as well. Yes! I should name first name as First Name, sum as Sum, options as Options. The only thing to consider when thinking up a name must be whether it clearly describes the thing and is easy to remember.

What are the advantages?

The more I use the system, the more advantages I see.

  • The code becomes far more readable making it easier to communicate with co-developers. A calculation like Subtotal + State Tax + Local Tax + Delivery Fee + Tax on Delivery Fee doesn't require any additional comments, does it?

  • Natural names help me to leverage certain FileMaker features with no additional effort. For example, if a field requires a value FileMaker shows a dialog like:

    Validation-Dialog.png

    If you use natural names, you may not have to write your own custom message, because the automatic one can already be good enough.

  • Finally, sometimes it's good to expose field names to users. (I don't mean unlocking an application to users, though with new security options the idea starts making sense.) In one of projects I develop I had to give users a way to compose text templates with data placeholders and later, when a template is processed, replace these placeholders with actual data. For example, user needed to be able to write something like “this task was completed by <User Name>” and have it changed to “by John Doe” when the task was actually completed.

    Initially I was going to add a table to store possible placeholders and then write a few functions to replace them in a piece of text. I did it actually. The system required two tables with several table occurrences, and a bunch of fields to display the possible choices, and a script to cache values in a global field, and a few custom functions to do the replacement. I think it was good experience, because at the end I realized I don't need all this stuff.

    Most of the placeholders were simply field references and these fields were directly available in the context I needed to calculate them in. Immediately I refactored the whole piece. At the end I had a list of field names, and a very simple selector:

    Field-Selector.png

    The Event::Created On is what it looks like: a field name. When it is inserted in a field, it gets << and >> at its sides and then a custom function goes through the text and evaluates everything between << and >>.

    The whole module became much simpler, much more manageable and even more flexible and the key part to this were natural field names; I couldn't do this with cryptic geeky ones. By the way, can you guess where the description string below the field name comes from?

    You're correct — this is a comment of the field.

Technorati tags: , , .

Number to Decimal

A simple function to convert a number of any base from 2 to 36 into decimal form.

Number to Decimal( number, base )

If( IsEmpty( number ) or base < 2 or base > 36; ""; Let( k = Length( number ); ( Position( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Left( number; 1 ); 1; 1 ) - 1 ) * base^( k - 1 ) + Number to Decimal( Right( number; k - 1 ); base ) ) )

Continue reading "Number to Decimal" »

Number to Base

A simple function to convert a decimal number to any base from 2 to 36.

Number to Base( number, base )

If( base < 2 or base > 36 or IsEmpty( base ); ""; Let( current digit = Middle ( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Mod ( number; base ) + 1; 1 ); Case( number ≥ base; Number to Base( Div ( number; base ); base ) ) & current digit ) )

Continue reading "Number to Base" »

Use modular XSLT to simplify importing XML data into FileMaker

A simple XSLT file encapsulates the target FileMaker grammar into easy-to-use parameterized templates; once written, the file can power any import task with no changes.

To import XML data into FileMaker you have to write:

  • Elements of the source grammar;
  • Elements of the target grammar, FMPXMLRESULT;
  • A list of instructions to transform the former into the latter.

You can put all of this into a single file and it will work; almost all XSLT samples are written this way. But as you face more and more complex import task, you start seeing the drawbacks of this approach:

  • You'll have to repeat all the verbose syntax of the target grammar for every XSLT file you write;
  • A mix of source and target elements and XSLT instructions can become hardly readable, that is error-prone and difficult to manage.

The universal way to manage complexity is to break something complex into modules that hide all the complexity beneath a simple interface. Let see how it can be done with XSLT.

Continue reading "Use modular XSLT to simplify importing XML data into FileMaker" »

Use the Gradient() function to apply a smooth gradient to a string

The Gradient( text, colors ) custom function paints the specified text with colors, applying a smooth gradient if more than one color is specified.

Sample.png

It may be not be terrible useful but looks nice and is fun to study as an example of a recursive function.

Technorati tags: , , , , .

Continue reading "Use the Gradient() function to apply a smooth gradient to a string" »

Assert Equals(): a custom function to test other custom functions

This function is designed to test other custom functions using the extreme programming approach and, most probably, a custom function test unit (if you haven't read the referenced post, you'd better start with it). The function works fairly well both as a specification and as a test engine.

Technorati tags: , , , , .

Continue reading "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: , , , .

Continue reading "“Constant” custom functions to save time and write clearer code" »