VIEW MEMBER FEEDACK TO THIS TIP
These are some basic guidelines for coding agents. Although each developer is unique in his or her coding standard, I wanted to share my style for coding an agent.
1) Naming Convention: agentName | agt<abbreviatedAgentName>
2) Use Option Explicit in the Options section. Make use of shared code from existing script libraries. Most of the times, you have a sendMail() in you script library. So make use of it like this -- use "<scriptlibraryname>".
3) In the Declarations section, put the agent task and its functionality in easy English language. For example,
%REM
Created on: 18-Jul-2005
By: Sunilkumar Vishwakarma
This agent is an autonomous agent
that fires daily at a scheduled time.
This agent sends a reminder to every manager
who did not act upon a request for last 3 days
instead of waiting for approval.
Logic:
--------
1) Identify the documents waiting
approval/completion from a manager
2) Send a mail to each of them as a reminder.
%END REM
4) Declare global variables
in the Declarations section. For example:
Dim db as NotesDatabase
Dim dContext as NotesDocument
5) In the Initialize section,
first line should be errorHandler.
On Error Goto errorHandler
'Declare variables
......
'Set Variables
......
'Agent's Business Logic
......
'Freeup Resources
......
Exit Sub
errorHandler:
Call handleError("",Err,Error$,Erl)
Here, handleError is a logger function placed in the script library which you can create yourself that will help in debugging the application errors.
6) Make use of subroutines or functions in the agent's local domain. This will make you code more readable and structured. This will make your life easy when a code change is required in the agent or function.
7) When using arrays, make sure to use the following statement in the lifecycle of the agent: Erase <arrayName>
8) Whenever referring an object or variable, test it for not being set to Nothing:
Set = SomeFunction()
If Not Is Nothing then
'Code Follows
End If
MEMBER FEEDBACK TO THIS TIP
Coding standards and error handling can be overused. You must use 'Option Declare' -- not only in agents, but in all LotusScript agents.
I'm not sure about putting AGT in the front of the agent. It is far better to name the design element based on its purpose. This makes life easier for other developers who have to understand what you were trying to do.
It's much better to concentrate on performance limitations, and write your code as efficiently as possible. That way, as your applications grow in size, performance won't suffer.
Andrew B.
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip exchange by member Sunilkumar Vishwakarma. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.