dominoGuru.com

Your Development & Design Resource

To := or not to :=

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.


About the author: Chris Toohey

Thought Leadership, Web & Mobile Application Development, Solutions Integration, Technical Writing & Mentoring

A published developer and webmaster of dominoGuru.com, Chris Toohey specializes in platform application development, solutions integration, and evangelism of platform capabilities and best practices.



More from dominoGuru.com


dominoGuru.com is powered by IBM Notes Domino XPages & hosted by Prominic.NET

Contact Us

Use our Contact / Feedback form or one of these email addresses:

Creative Commons License

Except where otherwise noted, dominoGuru.com by Chris Toohey is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.