One of the things that struck me when I attended my first C# programming class was the fact that the instructor was often switching between code examples written in either c# or VB.Net.
These two languages had evolved in such a way that in many ways they had become the same. This means programmers in one language can more easily adapt to develop/maintain code in the other. This started me thinking about the opportunity to write Notes applications in such a way that non-Notes developers could better make the transition to develop/maintain LotusScript code. The same concept also holds true for java, which is not all that different to C#. The following are some of the coding practices that can be applied to LotusScript to give them a look/feel more like these other programming languages.
Note: The goal here is coding consistency between programming languages. These suggestions do absolutely nothing to improve the functional nature of the LotusScript code and actually increases the length of the resulting code.
Object Oriented Programming:
Java, C#, and VB.Net are all examples of object oriented programming languges. With LotusScript the use of OOP (e.g. classes) is optional. If you get into the habbit of using OOP when developing Notes applications via LotusScript the chances are the code will be WAY more understandable to a java or .Net developer. Note: Without a proper class editor for LotusScript it can be a little more painful to maintain code in classes but the pain does subside after a while and a new eclipse editor for LotusScript is not far away...
Error Handling:
LotusScript does not support the try/catch construct found in many modern programming languages, but it is possible to simulate this by adding a non-functional try label at the start of the code and always using catch as the error handling label. This results in code block similar to the following:-
Try:
On Error Goto Catch
.... (normal code)
Exit Sub
Catch:
.... (error handling)
Exit Sub
This concept can be extended to include the optional finally block used for code to be executed after both normal completion or an error.
Try:
On Error Goto Catch
.... (normal code)
Goto Finally
Catch:
.... (error handling)
Resume Finally
Finally:
.... (final code)
Exit Sub
If... Then... Else
Both java and c# require conditional expressions be enclosed in parenthesese - with LotusScript this is optional. For consistency make it habbit to use this optional capability of LotusScript.
If (iDocument Is Nothing) Then
...
Else
...
End If
Method Calls
When invoking a methods (sub or function) with zero parameters in c# or java it is a requirement to place empty parentheses at the end of the method name - with LotusScript this is optional. Again, for consistency, make it a habbit to use this optional capability of LotusScript. The use of parentheses helps to make methods distinct from properties. Note: LotusScript also requires the somewhat redundant Call statement to be used with methods - but thats another story...
Call UIW.ReloadWindow()
Inheritence
Both java and C# support the this statement as a way of referring to methods/properties of the current class. With VB.Net and LotusScript the equivalent statement is the me statement. To refer to a property/method in a base/super class that has been overriden in the current class .. notation is used. While it is only ever necessary to use either statement when the same variable/method/property exists in different scopes, it is often a good idea to use either statement to make it clear wherever a method/property defined elsewhere in the class is being invoked. This also provides a way to minimize the use of variable names like EmployeeName1 to avoid clashes with property names.
If (Me.EmployeeName$ <> EmployeeName$) Then Me.EmployeeName$ = EmployeeName$
If (baseclass..EmployeeName$ <> EmployeeName$) Then baseclass..EmployeeName$ = EmployeeName$
1 Richard H. Schwartz Permalink I don't like the idea of using try:, catch: and finally: labels. In general, I think trying to make one programming language look like another is a bad idea. (And I'm pretty sure that that is one of the principles that I learned from Kernighan and Plaugher's "Elements of Programming Style".)
2 Tony A Palmer Permalink I think that the steep part of the learning curve isn't the language syntax but the native classes/api. For a VB developer or Java developer looking throught LotusScript understanding flow will be relatively easy in comparison with understanding which combination of classes (like notes document, uidocument etc) does what. If you look at the newbie questions in the forums it's usually a case of not understanding the notes classes rather than the language syntax. The same is true with Java. The syntax is way easier than understanding the API's classes (like JEE or building an eclipse plug-in). I agreed OO (and patterns) would be a good way to reduce the learning curve.