Skip to main content
    Country/region select      Terms of use
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

I know that in Domino developer training, you were taught to create a dozen temporary variables for the arguments to your @Functions.

years := 0;
months := 0;
days := 30;
hours := 0;
minutes := 0;
seconds := 0;
tmp := @Adjust(SomeDate; years; months; days; hours; minutes; seconds);

If you still do this, don't. Because:

  • It's unnecessary extra typing, using up time that you could be spending on slack.
  • It hurts performance, especially in "hot" code areas such as before a SELECT statement.
  • It makes the formula harder to read because you can't tell what the value of an argument is without looking at two different places in the code -- and if the temporary variable assignments are far from the @Function, a reader must scan all the intervening code to be sure they haven't changed meanwhile.
  • No, you can't make it a rule to always define the temporary variables you need just before you use them, because the syntax doesn't always allow that (maybe the @Function is in the fifth "elseif" clause of an @If). So there will be intervening code, or else you force yourself to use @Do everywhere just so you can do this dumb thing.
  • Person A writing the formula will be lazy and reuse an argument variable name further down in the formula so that they don't have to make up a new name and type the assignment. Person B (or person A later on, having forgotten) will change the value of the argument variable because they want to change it in the first function call, not realizing that they also affect the second function call.
  • Because macro language lets you use an undeclared name anytime, it won't warn you if the spelling of your variable name is different in the two places.
  • It prevents you from noticing otherwise obvious errors in the code as you're looking at it for other reasons, because you don't know the argument values as your eyes scan past them.
You may think you're helping readability by flagging your argument values with useful names, but as we can see from the above the overall effect on readability and maintainability is negative.

Here's another problem:

profilename := "Keywords";
fieldname := "History";
value := "";
uniqueKey := "";
REM {Clear the history entries from the shared profile document.};
@SetProfileField( profilename ; fieldname ; uniqueKey; value )

This works great! Later, someone decides that the proper value for a cleared history is "|" instead of "". So they change the line:

value := "|";

This likely results in a post to the Domino forums that "@SetProfileField doesn't work." Figuring out why it doesn't work is left as an exercise for the reader. It might take you longer when you run across it unexpectedly 'in the field' because I've already hinted where to look. How long might it take someone without the hint, and who also doesn't know formula language as well as you, to catch on?

If you must flag your arguments with a name, take advantage of the fact that := returns the assigned value as its value. E.g.:

tmp := @Adjust(SomeDate; _years:=0; _months:=0; _days:=30; _hours:=0; _minutes:=0; _seconds:=0);

You could still fool yourself as in the above example, but at least you don't have the possibility of spelling them differently in the two places, or of changing their values between where they are set and used, and it doesn't matter if you use the same variable name in two places. I'm not saying you should do it this way; I'm just saying this is a little less dumb than the way you were taught.

Andre Guirard | 25 June 2008 06:09:00 AM ET | Home, Plymouth, MN, USA | Comments (15)

Search this blog 


    About IBM Privacy Contact