|
|
ADVISOR TIPS
When and When Not to Use @Formulas in Domino 5x
@Formula programming is a skill all developers should have in their toolbox.
Many Domino developers view the @Formula language as a deprecated tool -- a tool that will eventually fade away with time. Well, I'm here to tell you differently. If you really want to know what tools Lotus views as essential, look at what tools Lotus enhances. Lotus continues to enhance and revise the @Formula language engine, which is further proof that @Formula programming is still a very viable skill, and one all developers should have in their toolbox. I'll show you some of the power of the @Formula language in Domino 5x, when and when not to use it, and provides some tips, tricks, and undocumented features.
 |
| Figure 1: Language/API interaction -- @Formulas are "closer to the iron." |
Why use @Formulas?
One of the questions I hear all the time is: "Why should I use @Formulas? What can they give me that LotusScript and/or Java doesn't?" There are a few reasons why @Formulas are desirable in Domino 5x:
@Formulas can be coded more quickly for many tasks -- Try coding the equivalent functionality of what @DbLookup does. That would require many, many lines of code, and by the time you figure out all the what-if scenarios for error trapping, etc. you could have finished the rest of your coding. Instead, use the proper tool, such as @DbLookup.
@Formulas are supported all the way back to Notes 2x -- Sure, there are newer @Functions that have been added since 2x, but if you're worried about legacy compatibility, @Functions go farther back than LotusScript.
@Formulas are truly cross platform -- @Formulas are fully supported on every platform Domino supports. LotusScript and Java are also supported, but much of LotusScript's functionality is unavailable outside of the Win32 platforms -- items involving COM, OLE, etc. to name a few.
Given like tasks, @Formulas are always faster than LotusScript -- If there is a way to do a particular task in both LotusScript and the @Formula language, the @Formula version will always be faster. Why? Because @Formulas are closer to the API functionality itself. All the languages available in Notes/Domino 5x are children of the same API. But each of them interact with the API differently. LotusScript and Java are "higher-level" programming languages, which means they provide a higher level of flexibility and power, but those benefits come at the cost of some speed. LotusScript and Java also must run through a byte code interpreter. @Formulas, on the other hand, access the API through the @Formula engine, which is "closer to the iron" -- that is, it's closer to the native API level than the higher-level programming languages, as shown in figure 1.
So, now you know why you should use @Formulas. The next question is "When?"
When to use @Formulas
As stated earlier, @Formulas can often provide a quicker way to accomplish the same task, so you don't waste your time reinventing the wheel. For instance, if you are creating a button that simply saves and closes a document, why would you write all the lines of LotusScript required to accomplish this when a simple @Command([FileSave]) and @Command([FileCloseWindow]) would work?
@DbColumn and @DbLookup are very quick at retrieving data, especially from views. Coding these in LotusScript or Java would be a daunting task, so this is an obvious time to use @Formulas.
If the job you're attempting is fairly simple, and doesn't require complex looping or branching, look for an @Formula solution first. You could save yourself quite a bit of coding effort by coding a few lines of @Formulas over many lines of LotusScript or Java.
All this comes down to a simple rule: Take a moment before writing your code to analyze what you are trying to accomplish. Compare this to the simple guidelines mentioned above, and see if @Formulas are the better tool for the job. Am I saying @Formulas can solve the world's problems? Hardly. There are many situations where @Formulas are not a good fit.
When not to use @Formulas
There are many situations when @Formulas aren't a good fit however, and you should use one of the higher-level languages such as LotusScript or Java:
- @Formulas have no looping capability (at least none you would want to use), so anything requiring looping or branching is not a place for @Formulas. However, with Notes/Domino 6, @Formulas have looping capabilities, so this reason applies only to earlier versions.
- If your task requires a solution that is exceptionally complex, use the higher languages of LotusScript or Java.
- @Formulas have no ability to interact with COM or OLE objects, so if you have to access these items, LotusScript is obviously the tool of choice.
- If you have to perform complex searches, use Java or LotusScript.
| Table 1: Front-end and back-end @Formulas -- Front-end @Formulas interact with the user interface, while back-end formulas manipulate data. |
| Front-End @Formulas | Back-End @Formulas |
| @Prompt | @DbColumn |
| @Picklist | @SetField |
| @DialogBox | @UserRolesList |
| ALL @Commands | @Replace |
Although I'm comparing @Formulas to LotusScript and Java, let me point out one likeness that is usually unnoticed -- there are "front-end" and "back-end" @Formulas!
Front-end versus back-end @Formulas
Yes, there are front-end and back-end @Formulas; front-end @Formulas interact with or change the user interface, and back-end @Formulas are those that manipulate data only. Why is this important? As you may recall, when you create scheduled or Web-based LotusScript agents, you can't have any front-end references in it at all -- you can't even Dim a NotesUIWorkspace. Well, the same rule applies for @Formula agents. You can't have any front-end @Formulas in them either. So, what are some examples of front-end and back-end @Formulas? Table 1 shows representatives of both.
Rocky Oliver is a Senior Software Engineer in product development for Lotus Software at IBM. Rocky works on new features for Notes/Domino, and most recently released his latest project, IBM Lotus Notes access for SAP solutions. Rocky began his life as a Lotus geek in 1992 in Lotus' Word Processing Division (WPD). Rocky left Lotus in 1995 to begin a career as the HGOC (Head Geek on Campus) for large national consultancies, pre-IPO startups, and even founded his own company. Besides consulting, Rocky has worked on product development efforts as well. Rocky helped design and develop Synergistics' award-winning Prevail Suite, and has worked on various open source projects at OpenNTF.org (namely Surely Template and Blogsphere). Rocky is a fairly prolific writer and speaker as well. Rocky co-authored Notes and Domino 6 Programming Bible (Wiley, 2003), Teach Yourself... LotusScript for Notes/Domino 4.6 (MIS Press, 1997), and was a contributing author for Special Edition -- Using Lotus Notes and Domino R5 (Que/MacMillan Publishing, 1999). Rocky also regularly speaks on Lotus Domino and IBM WebSphere technologies at various conferences in the US and Europe, including ADVISOR conferences and IBM conferences such as Lotusphere. When not neck-deep in code, And if he's not busy enough, Rocky enjoys spending quality time with his amazing wife and five wonderful children. http://www.lotusgeek.com rock@notesdev.ibm.com
ARTICLE INFO
Web Edition: 2003.09.15, Doc #13046
FREE ACCESS
Keyword Tags: Application Development, Development, IBM, IBM Lotus, IBM Lotus Domino, IBM Lotus Notes, IBM WebSphere, Java, Lotus Formula Language, Lotusscript, Programming
|
|