Manage Learn to apply best practices and optimize your operations.

10 fundamental LotusScript tips

Here are 10 basic LotusScript techniques that you should already be using if you've had any previous exposure to LotusScript. These beginner-level tips are also perfect for a Notes/Domino developer just getting started with LotusScript.

  1. Option Declare
  2. Templates and versions
  3. Application lifecycles
  4. How to code
  5. "Measure twice, cut once"
  6. Extending arrays the easy way
  7. Use the list operator
  8. Logging agents
  9. Code structure
  10. Hiding your code

  Fundamental LotusScript Tip #1. Option Declare  

Make sure you always use "Option Declare." It sounds obvious, but there are several determining factors as to why you should always use it. Here are some of the reasons:

  • If you don't use "Option Declare," all variables are created at runtime as variants, and this makes fact checking redundant.

  • Data conversion will cost your company 10 times your performance.

  • All your errors will be runtime errors.

  • Also, always remember that you should test often and test early. Use the strength of the compiler to help you.

  Fundamental LotusScript Tip #2. Templates and versions  

When working with templates and versions in LotusScript in custom code, there are a few things you should always do:

  • Always create templates with new code, which may include databases with an NTF extension or databases with Master Template Name set.

  • Make sure you create a separate version for each copy you're working on.

  • And always keep your templates and versions in a central repository.

You might say these all sound like good reasons, but why should I use them? There are three major reasons:

  1. Because it makes it much easier to roll back.

  2. It helps with version control.

  3. It makes it simpler to construct test cases with other versions.

  Fundamental LotusScript Tip #3. Application lifecycles  

When dealing with the lifecycles of your applications, there are a few best practices you should follow:

  1. Always develop in a development sandbox -- a non-production environment where each developer keeps his or her working copy of the code base.

  2. Always test in a user acceptance environment.

  3. Pass the template to your Domino administrator to copy.

Here is why you should adhere to these rules:

  • It's a basic change-control system.

  • It is you doing your part as a development professional.

  • It shakes out hard-coded bugs, such as hard-coded server names, paths and replica IDs.

  • It allows you to run extensive testing without affecting your company's production.

  Fundamental LotusScript Tip #4. How to code  

Here are the fundamental how's and why's of how to code in LotusScript:

  • Always code for maintenance.

  • Only code for performance if it is required. Make sure you get your code working in general, before you get it working for speed.

Here is why you should follow these LotusScript how-to coding guidelines:

  • The highest cost in development is software maintenance.

  • You make it easier for the person maintaining the application.

  • You could be working on that application!

  Fundamental LotusScript Tip #5. "Measure twice, cut once"  

"Measure twice, cut one" may sound a bit cliche, but it is a good analogy when you are writing LotusScript code. Here are a couple ways it applies.

  • You should always spend more time thinking about what you are coding and less time doing the actual coding.

  • You should always try to think of two different ways of solving the problem at hand. The best approach is usually a combination of the two, and you should always think about your data model.

This works well because you are spending more time planning and less time doing actual labor.

  Fundamental LotusScript Tip #6. Extending arrays the easy way  

You should always try to use "ubound" to establish the size of your array. Below you will find an example of it in use.

Sub initialize()
        Dim myArray() as String
        redim my Array(0)
        call myExtend (myArray, "Hello Sailor"")
end sub

function myExtend(S() as String, ns as String) as integer
        if (S(ubound(S)) <> "") 
then redim preserve  S(ubound(S)+1)
        S (ubound(S)) = ns
        extend = true
end function

If you set up your arrays this way, you won't need to keep a separate index of the array size; it also automatically trims the code. However, there is a minor drawback to implementing this. It will slow down large arrays, so you'll need to define the "empty" value. Otherwise, it works great.

  Fundamental LotusScript Tip #7. Use the list operator  

When you use the list operator, it stores a value with a unique lookup key. It's a good idea to use the list operator because:

  • It's easy and fast
  • It's built right into LotusScript (as long as you're using version 4.5 or higher)

Here is some example code:

Dim WR list as String
WR("Peter") = "Perfect"
WR("Penelope") = "Pitstop"

Print "Peter's last name is: " +WR("Peter")
if not isElement(WR("Dick")) then print "Dick isn't racing!"
forall thisRacer in WR
        Print listtag(thisracer) + " " + thisRacer
end forall

  Fundamental LotusScript Tip #8. Logging agents  

Another good tip is to log your LotusScript agents, especially if they are scheduled agents. It's also a good idea if you have a broad range of clients. If you do, you need to log both your client and scheduled agents runtime status.

If you don't log your agents, chances are that your applications will break. Logging your agents will also help to let you know when your LotusScript agents do break. It's also a good timing metric for performance testing.

Show caution when logging your agents though -- you don't want to make the logging so slow that it affects application performance!

  Fundamental LotusScript Tip #9. Code structure  

When dealing with the structure of your LotusScript code, it is usually good to keep it as short as possible. Smaller code sequences are easier to deal with and maintain and are easily reusable. A good rule to go by is if your code is more than a screen's worth, you should determine if it is possible to break it up.

Some tips when determining your LotusScript code structure:

  • Try to keep your functions/procedures/classes at a manageable size.

  • Think before decomposing problems.

  • Don't over comment -- explain your "why."

  • Try to use non-intuitive algorithms.

  Fundamental LotusScript Tip #10. Hiding your code  

When we say we're "hiding our code," we're basically saying that we're decomposing it so consumers can't see it. You don't want anyone to be able to view it, not even yourself.

When you hide your code, you are inferring a logical interface with clear naming. As such, your users and customers can write to the interface but not the code itself. This is good practice because it simplifies the coding experience.

You can easily hide your code by using "private/public" methods in your classes, script libraries, etc.


 Home: Introduction
 Part 1: 10 fundamental LotusScript tips
 Part 2: 10 everyday LotusScript tips
 Part 3: 10 advanced LotusScript tips
 Part 4: More LotusScript learning resources

Dig Deeper on LotusScript

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...