How to write better code in Domino Designer – Part 1

The inspiration to this series of blog entries partially comes from looking at code posted in the developerWorks forums. Some of it is extremely hard to read and understand, even if you ignore the fact that the forum removes indentation from the code.

If you write code that is hard to read, your applications will be hard to maintain. Write the code so it is easy for the poor person who will be maintaining the code in the future. Most probably that person will be you. You might also have to post your code in the developerWorks forum or on StackOverflow for help. If the code is hard to read and understand, you might not get very much help.

What I will talk about is what you can do to become a better programmer, and write code easier to maintain. After being a Notes developer since 1996, I have learned a bit about what makes a Notes application easy to read and to maintain. I want to share some of my thoughts on this blog, or in the words of Kevin Spacey at Lotusphere 2011: “sending the elevator down”. Hopefully it will help someone.

I will not talk to much about basic programming concepts or how to program in Domino Designer. I will assume that the reader already knows that, and is familiar with especially Lotusscript. I will also not talk much about how to create applications with a nice and easy-to-use user interface. That I will save for a later series of articles.

Instead I will focus on things that I think will make you a better Notes programmer. I don’t take credit for coming up with all the ideas I will talk about, some are from attending sessions at Lotusphere in the past, and some were methods I picked up where I work or worked before. Many of the tips are almost defacto standards among Notes/Domino developers.

In this first article, I will start with some tips for when you create forms.


Field Names

Use field names that makes sense, and don’t use cryptical field names. You may remember right now what kind of data the field is supposed to hold, but in a few months, you have no idea what is stored in it. Some developers use hungarian notation or some similar system with prefixes to indicate what is in a field, but in my experience that makes just for massive confusion later. The only prefixes I use on field names are dsp for any computed-for-display fields and flag for fields that are used to indicate if a document has been processed, is ready to be deleted or to decide if parts of the form should be hidden or not.

If you use field names that indicates what kind of data types they contain, be consistent and at least use proper indicators. It is not a good idea to call a field txt_no1 if it contains a number. Anyone that sees that field name will assume it is a text field, and this will cause errors later on.

Don’t copy fields and keep the automatically generated name. If you make two copies of the field Comment, you will have the fields Comment, Comment_1 and Comment_2. Rename the fields at once, before you save the form. If you save the form, the fields will be added to the UNK list, and will show up in different places, even if you never used them, and they are not present on any forms.

My next suggestion is just something to think about, and it is actually more important when writing Lotusscript code. But since it impacts @Formula language, I am bringing it up together with the forms/fields. My suggestion is to consider using English field names, even if you are not a native English speaker. If you post code on forums like developerWorks — where the majority uses english — people will understand your code and thought process much better when the field names and variables are “self documenting”. However, I can understand that in some companies, you are told to use the native language for fields. In those cases, consider translating your code (field names and variables) before posting it. Test it to make sure you did not introduce any errors during the translation process. But if you can, use English as that is the universal language for programmers.


Hidden Fields and Text

When you hide text or fields on a form, use color coding and fonts to easily spot what is hidden and what’s not. I format everything that is always hidden in red, Arial 8pt. This makes it easy to see if red text is actually visible on the form, for example as an error message. Fields and text that is hidden to the normal user, but visible to certain users (e.g. database administrators), I often make blue.

When it comes to hidden fields, I try to put them all in one section, usually at the top of the form. I do this as they often are used for computed fields further down, or to control hide-when sections of the form, and that is evaluated from the top of the form.

In some places, I have a hidden field, followed by a computed-for-display field. I do this so the field can not be modified by the user, but it is modified by action buttons or other code using the UI classes. In those cases I put the hidden field first, then the computed-for-display field named the same but prefixed with dsp right after..

Below you can see a simple form from one of my production applications.

Simple form showing hidden fields in red and computed-for-display fields prefixed with dsp.
Simple form showing hidden fields in red and computed-for-display fields prefixed with dsp.

With just a glance, you know what is hidden and not, and if any fields are display-only. You may wonder why I use computed-for-display fields instead of computed text. That is because if a user would forward a document via email, any computed text will be blanked out, while a computed-for-display field will show the value correctly. You also want to use descriptive labels, or even comments, to explain what the hidden fields are used for.

You can also see that I try to make the hidden fields easy to read. Using tabs makes it very easy to line up the fields and labels. You will find that in the long run, this makes it much easier for you to read and understand your own forms later.
Just as an example, below is another form where the hidden fields are all over the place, different format and some with labels/explanation, some without. Much harder to read, even if this is not an extreme example. Since the fields are logically named and grouped, it can work, but it is not pretty or optimal.

It i smuch harder to read this, with different fonts, missing labels and fields all over the place.
It is much harder to read this, with different fonts, missing labels and fields all over the place.
Imagine how hard it would be with crypic field names in addition to this!

I also use red for hidden columns in views, again to make it obvious what is visible to the user and what is not. Normally I make even hidden columns wide enough to display the content, at least during the design phase.

I use red text in views as well to indicate that a certain column is hidden, and used only for sorting,
I use red text in views as well to indicate that a certain column is hidden, and used only for sorting,

That is it for forms and views. In my next article, I will look closer at Lotusscript, and how you can make your code there easy to read and maintain.


IBM Notes and Domino 9.0 Social Edition

This morning, IBM presented the latest version of Notes and Domino. The new product name is IBM Notes 9.0 Social Edition. As you notice, the Lotus name is now gone, and the look is changed to look more like other IBM applications, with a more modern design. There are also changes and updates to the user interface inside the different parts of the client.

IBM Notes 9.0 Social Edition - Welcome Screen
IBM Notes 9.0 Social Edition – Welcome Screen


One thing, totally new for Notes, is that tutorials and training videos are available in the client.  The tutorials are not just for new functions, but also older tips and tricks that will make the users more productive.

During the presentation, new functions in mail and calendar were demonstrated. One function that will surely be popular with users is to group mail by date:

Other new features shown were the ability to color code different categories of meetings using custom colors and improved monthly view, as well as a weekly planner taken from Organizer.

The activity stream is using the OpenSocial standard, and Domino is now supporting OAuth and SAML for authentication. Customers can however deploy Notes 9.0 without the Social Edition functions, and add them later.

Not only has the traditional Notes client been updated, iNotes is also updated to look even more like the rich client. One of the biggest news in this version is the Notes browser plugin, that allow user to run traditional Notes applications directly in the browser, in full fidelity with no Notes client installed. The new version of iNotes also contains the new activity stream, as shown in the image below.


The new version of Traveler will (in addition to iPhone and Android) also support the Blackberry 10 platform and Windows Phone 7.5/8, and now also be available for IBM iSeries.

A public beta version of Notes 9.0 Social Edition will be available December 14. For previous versions of Notes, since (if I remeber correctly Notes 5), IBM have been doing managed beta testing and not released public beta version.
The final version is planned for Q1 2013. IBM also outlined the future roadmap for the next couple of years, which included a new major realease in 2015:


Welcome to my new blog

After having my blog hosted by Lotus911 (later GBS) at for almost five years, I have decided to switch blog platform. The main reason is due to limitations in IBM Connections as a blog platform (no anonymous comments and issues for example when trying to embed videos). I decided to go with WordPress as my blog platform, as it is common and widely supported.

Another advantage with a WordPress hosted blog that is that I now can have the blog hosted under my personal domain, as

Earlier today I imported the existing content to the new blog. I will write about that process in another blog entry shortly. Basically I wrote a couple of Lotusscript agents in Notes and retrieved the existing blog content and then reformatted it for WordPress. As I did not have very many comments, I did not import them, as I decided the amount of work was not worth it. They can be found on my old blog, as I will keep it alive. That way all the links to it from different placs will also continue to work.
I have not verified all old entries, so if you notice anything that need to be fixed, please let me know. One known issue is when I reference another blog entry, the link will currently take you to

Again, a big thanks to GBS who hosted my blog for the last five  years, and who got me into blogging. I had made some attempt prior to 2008, but never got motivated enough. Hopefully the switch to WordPress and the greater possibilities will lead to me blogging more frequently than lately.


Things to think about when programming in Notes

Inspired by some of the posts in the DeveloperWorks forums and on StackOverflow, I thought I would post some more basic concepts and how I handle them. I am not saying my way is the best way, this is just what works for me. I am sure there will be more posts in the future”…”

I will also mention a few other things I noticed while reading the code posted in the forums.


Retrieve something that doesn´t exist

The question is how to identify what dates there are no documents created for. This is where lists are very useful. Richard Schwartz answered this question and posted some good code.
Rich suggests to create a list of dates, with each list item having an initial values of false, and then loop through the documents. As each document is processed, the value of the corresponding list item is changed from false to true. You can then go through the list and see which dates still have a value of false, those dates are missing documents.

My version of the same code is to actually delete the list item you have a match for, instead if setting it to true. In the end you have a list of just the items of dates without a corresponding document.


Write readable code

This could be a blog entry all by itself. But I notice that much of the code in the DeveloperWorkds forums is hard to read”´”. Partially because any tabs or multiple spaces used for indenting the code is stripped out, but also because the posters don´t write easy-to-read code.

Variable names are often not descriptive:

Dim db1 As NotesDatabase
Dim db2 As NotesDatabase


Dim thisdb As NotesDatabase
Dim nabdb As NotesDatabase

Which one is easier to understand? In my opinion (and I am sure you agree) the second variant. Also function names and other variables should be named so you understand what they do and what kind of data they contain.

Comments are mostly non-existing. It is not that hard to add some comments to the code that explain what the code is doing. But don´t explain every line of actual code (it should be self-explanatory, if variables are named correctly), explain what a particular section of code is intended to do.

Here is a section of code from an agent I wrote earlier this week:

'*** Read PhotoUNID field in LossControl document'*** and build a list of the UNID values in the fieldphotoUNID = lcdoc.GetItemValue("PhotoUNID")(0)If photoUNID<>"" Then '*** Create array of values and put into photolist tmparray = FullTrim(Split(photoUNID,";")) ForAll t in tmparray If t <> "" Then photolist(t) = t End If End ForAll End If

The comments above will help the next person to look at the code to quickly understand what it is intended to do.


More on variables

Use Option Declare/Option Explicit. This will find many errors, especially for more inexperienced programmers, where variables are misspelled or missing, something that is a very common reason for posts in the forums.

Another thing that a surprisingly large number of posters seem to struggle with is how to correctly declare variables. I see many cases where several variables are declared on one row, but only the last one has the data type. The author of the code was thinking it would apply to all the variables:

Dim FirstName, LastName, Street, City, PostalCode, State as String

This will declare State as String, but all other variables as Variant. This is not unique for Lotusscript, Visual Basic (on which Lotusscript is based) works the same way.

I always declare each variable on a separate line. This makes it easier to find a particular variable if I am looking for it. I also declare all variables in the beginning of the code/function, again to make it easier to find it in the future. Finally I order the declarations in the same order:

1. Notes UI classes (so they are easy to locate, in case I need to rewrite the code to be used in a server-based agent.

2. Notes backend classes. I always declare them in the order they are being used, as this also is how the classes are structured.

3. Variables and custom classes, in the order they are used.

Here is an example, from the same agent as above:

 Dim session As New NotesSession Dim photodb As NotesDatabase Dim lcdb As NotesDatabase ' LossControl DB Dim lcview As NotesView Dim lccol As NotesViewEntryCollection Dim lcentry As NotesViewEntry Dim lcdoc As NotesDocument Dim photodoc As NotesDocument Dim rtitem As Variant Dim rtnav As NotesRichTextNavigator Dim rtlink As NotesRichTextDocLink  Dim cnt List As Long Dim photoUNID As String Dim unid As String Dim photolist List As String Dim verifiedlist List As String Dim tmparray As Variant Dim photos As String

As you can see, I also put a comment there, to explain what lc stands for.
I also try to use a list for counters, instead of having a number of separate variables. Doing that makes the code easier to read and understand, despite it actually being longer:

 cnt("Total") = lccol.Count cnt("Processed") = 0 cnt("Updated") = 0 cnt("UpdatedPhoto") = 0
 cnt("Processed") = cnt("Processed") + 1 If cnt("Processed") Mod 10 = 0 Then Print cnt("Processed") & " of " & cnt("Total") End If

See how easy that code is to read?


Use the Debugger

I see many messages where the poster is getting an error message, or an unexpected result (or no result at all). Sometimes a large chunk of code is posted, but no indicator where the error happens.

It seems like very few (at least of the obviously less experienced programmers) use the debugger at all. In most cases they would quickly find the problem that way, instead of asking why they get “object variable not set” or “type mismatch” errors somewhere in 100 lines of code”…”

Yes, the debugger has limitations, and it could use some new features (like breaking when a particular variable has a specified value or match an expression), but it is a huge help even in the current form.


Understand Data Types

Many problems are because the programmer did not understand what data type different functions returns, or even (in some cases) what the different data types means. One poster (I can´t find the post right now) had code like this:

 Dim x As Integer x = 0 x = x + 3.5 MsgBox x

He was the surprised that the message box displayed the value 4… I think understanding data types is a requirement of being a programmer, even if the language you work with is forgiving or don´t require variables to be declared.


Analyze the problem

Another common issue I see is that it seems like the programmer just got an assignment and started to write code, without thinking through what the actual process is going to be. He/she often write him/herself into a corner, or is so focused on solving it with existing knowledge (e.g. “has to be @Formula language”), that the difficulty level of the task approaches impossible. Or the code will be extremely convoluted.

Think through the problem, break it down into small problems/steps. Break each of those down into even smaller steps, etc. Finally you have a good specification, and often even pseudo code. It m
ay be that the user requesting the program/functionality (a.k.a. stakeholder) is saying how he want it to be done, but that is really not the stakeholders responsibility. He/she should just explain what the end result should be, and the developer will design the best solution.

I have examples where a manager comes to me and asks for a report “in Excel” of data in a Notes database. That is because the manager in this case was used to working in Excel, and thought of how Excel displays data as the way he wanted it.
I could very easily create a report directly in Notes, displaying exactly the same information. Since I asked what the end result was supposed to be, and how the data was supposed to be used (and by whom), I could avoid Excel altogether and built a pure Notes solution.

This is where experience comes in, things like that is not something you can just pick up at college/university. If you don´t have the analytical/problem solving skills, you will struggle as a programmer. You might be able to write code under strict guidance, or you might even be able to eventually complete the assignment, but it will most probably not be the best/fastest solution, even if the code will work.

Two good blog entries are Separating Programming Sheep from No-Programming Goats (CodingHorror, July 2006) and Why Can´t Programmers.. Program? (CodingHorror, February 2007). Programming consists of problem solving and analytical skills, fundamental skills (like data types, how functions works, recursion different kind of branching/looping), as well as understanding the language and platform you use. If you are missing any of those things, you will probably not be a very good programmer.



Review: LEGO Lord of The Rings

This weekend I spent with my son building some of the new LEGO kits from the new Lord of The Rings series. Here is a quick review of the kits we have built this far. You can click on the images for high-res versions of them.


9469 Gandalf Arrives – 83 pieces


A small but nice set. Contains Gandalf in his cart loaded with fireworks, as well as Frodo welcoming him.
Plenty of nice details, like the fireworks, a carrot for the pony and an envelope for Frodo to put the ring in.


9472 Attack on Weathertop – 430 pieces


This is a very nice set. It contains five minifigs: Aragorn, Frodo (with the ring), Merry and two Nazgûl (ringwraiths), as well as two horses. The three first minifigs have a feature I have not seen before, they have two sets of faces. By turning the head and exposing the part hidden by the hair, you get two different facial expression, like stern and aggressive or scared. The Frodo minifig in 9460 got the same feature, but not Gandalf as the back of his head is visible. All the minifigs are extremely detailed, it is obvious that the designers of the kits realized that collectors and adults will buy these kits.



The kit itself is of the ruins on top of Weathertop (Amon Sûl), and it features a trap door and a cooking fire. The ruins can be opened and in the inside you find weapons, toches and much more. Even a rat! There is also a stand-alone pieved of ruin with a bush and some plants.


The plants are the only thing I did not like with the kit. For some reason, perhaps the kind of softer plastic used, they don’t stick well to the bricks they are placed on. But that is a minor detail, otherwise this is a great kit.


9473 The Mines of Moria – 776 pieces


This is a big set, the second largest in the series, and it depicts the events in the Chamber of Mazarbul. It contains six minifigs (Gimli, Legolas, Boromir, Pippin and two Moria orcs), as well as the cave troll. There are four separate sections, a large wall section, the doors to the chamber, the well with the skeleton and the chain and bucket, as well as Balins tomb, containing the skeleton of Balin. By pulling a lever, the skeleton, bucket and chain will fall down in the well, just like in the book and movie.

There are plenty of details, from old weapons to gems and even the Book of Mazarbul.



9476 The Orc Forge – 363 pieces


This is currently my son’s favorite kit. It features a light brick, so when a rod is pushed, it looks like fire under the melting pot. In addition, there are four minifigs: Lurtz, two Mordor orcs and one Uruk-hai. To be really picky, Lurtz was created by Sauron, just like the Uruk-hai, so there should not have been any Morder orcs, but Isengard orcs. There is two sets of Uruk-hai armor (complete with the white hand of Sauroman), a crane to lift material to melt for the forge, etc.





So what is the verdict? As a Lord of the Rings fan (both the books and the movies by Peter Jackson), I am very happy with the LEGO kits this far. The quality is good, the instructions are very clear (recently I have seen some instructions where it was easy to miss a piece of pick the wrong shade of gray) and the detailing is amazing.
I still have two more kits to build that I already purchased, and I have to get the last kit (Battle of Helms Deep). I will report on them later.



End of content

No more pages to load