dominoGuru.com
Your Development & Design Resource
To := or not to :=
04/30/2004 02:28 PM by Chris Toohey
This is more of a generalism on streamlined development than a copy/paste implementation... as that's what I'm going to be turning the tips section into: tips instead of what you would find in an article, example database, or downloadable databases.
Enough of that, and onto the tip!
When developing a routine, it's good to know when to and when not to use variables. Properly using variables can greatly enhance the performance of your applications, but improperly using variables can drastically impact the joy joy happiness of your routine - which could leave your application users sitting back and watching a lightening bolt flicker.
It's a simple thing really... use variables when it makes sense to use them. I'll explain...
I do this myself in my applications:
tmp := @Adjust(@Created;0;1;1;0;0;0);
@if(!@isNull(DueDate); @Prompt([OK];"Document Due Date"; @Text(DueDate));
@Prompt([OK];"Document Due Date"; "Due Date not defined." + @Char(13) +
"Expected Due Date: " + @Text(tmp)))
Simple enough right? Well, this simple formula (as written) will always calculate the tmp value... even if the DueDate has a value in it and the formula doesn't have to do anything!
@if(!@isNull(DueDate); @Prompt([OK];"Document Due Date"; @Text(DueDate));
@Prompt([OK];"Document Due Date"; "Due Date not defined." + @Char(13) +
"Expected Due Date: " + @Text(@Adjust(@Created;0;1;1;0;0;0)))
.
Now, as the above formula is written, the @Adjust
will not
calculate unless it's needed!
On the other hand, a routine like this:
@if(!@isNull(DueDate); @Prompt([OK];"Document Due Date"; @Text(DueDate);
@Do(@Prompt([OK];"Document Due Date"; "Due Date not defined." + @Char(13) +
"Expected Due Date: " +
@Text(@Adjust(@Created;0;1;1;0;0;0)));@SetField("DueDate";
@Adjust(@Created;0;1;1;0;0;0))))
This, of course, is the perfect place for a tmp value... but not in the same place as seen from the first example!
@if(!@isNull(DueDate); @Prompt([OK];"Document Due Date";
@Text(DueDate));@Do(tmp := @Adjust(@Created;0;1;1;0;0;0);
@Prompt([OK];"Document Due Date"; "Due Date not defined." + @Char(13) +
"Expected Due Date: " + @Text(tmp));@SetField("DueDate"; tmp)))
From this, not only will the routine not calculate the @Adjust
unless needed, but it calculates it once. This allows for multiple usage of a
non-static value with only a single calculation to define the non-static value
- or should I say properly using a variable.