It is possible for legacy flow control statements (if, else and for) to have more than one statement; for instance:

    // if condition c is true, set variable x then print variable y
    if c set x = 1 w y,!

However, this is hardly readable.

If you have more than one statement, it is preferred to use the brace forms of these statements instead; the code above becomes:

Those two constructs implicitly inspect the value of the $TEST special variable:

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.

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

Pages