10 fundamental LotusScript tips

  1.  

    to code
  2. "Measure twice, cut once"
  3. Extending arrays the easy way
  4. Use the list operator
  5. Logging agents
  6. Code structure
  7. 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.

 
  
 

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:

 
  
 

  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.


TUTORIAL: 30 LOTUSSCRIPT TIPS

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

转载于:https://www.cnblogs.com/hannover/archive/2012/04/24/2467550.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值