Identifiers for local variables and method arguments in ObjectScript are case sensitive, which means that, for instance, foo and Foo are different.

However, for readability reasons, it is not recommended for two identifiers to have names which differ only by case. Consider renaming one of these.

Empty CATCH blocks, as in:

    try {
        // whatever
    } catch {
        // nothing
    }

are rarely legitimate and should be avoided.

Try and redesign the code so as to eliminate the need for this construct. If the intent is really to ignore the exception, consider at least logging it.

Given two variables n1 and n2, and assuming both variables have a numeric value, there are two ways to check whether one is greater than, or equal, to the other:

ObjectScript allows to write code such as:

    Method m()
    {
        try {
            do ..something()
        } catch {
            write "Oops...", !
        }
    }

In the sample code above, it is assumed that ..something() may throw an exception.

However, the catch block, as it is declared, will only have the knowledge that the try block failed; it will be unable to inspect the thrown exception.

This rule detects when a method argument is passed by reference but is never assigned in the body of the method.

This either means that this argument does not need to be passed by reference, or that the code forgets to assign a value to it.

ObjectScript's flow control keywords accepting boolean expressions (such as if, while and others) allow to write boolean expressions without surrounding parentheses; for instance:

    if x > 4 {
        write x, " is greater than 4", !
    }

However, such code is rather confusing for people coming from other languages (Java, C, C++, etc) where surrounding parenthese are required.

Many ObjectScript system functions have a short name in addition to their regular name.

However, using these short names can be confusing, especially for new developers, and harm code readability.

Therefore, instead of writing:

    set x = $zdt($horolog)

it is advised to write:

    set x = $zdatetime($horolog)

Many ObjectScript functions have a short name in addition to their regular name.

However, using these short names can be confusing, especially for new developers, and harm code readability.

Therefore, instead of writing:

    set x = $i(x, 1)

it is advised to write:

    set x = $increment(x, 1)

The #Dim preprocessor directive, even though the documentation does not mention it, can be used without specifying the intended type of the variable, as in:

    #dim x

However, this defeats the purpose of this directive; among other things, this prevents Studio from performing completion of properties/methods/etc.

It is recommended that a type be declared at all times, as in, for example:

    #dim x as %Integer

The #Dim preprocessor directive allows to write, for instance:

    #dim x as %Integer = 2

However, this has a hidden consequence of generating an additional statement in the code, even though this is a preprocessor directive. The above is in fact equivalent to:

    #dim x as %Integer
    set x = 2

Pages