In these code samples:

    do ..someMethod(.x)
    // or
    do ##class(some.Class).someMethod(.x)

x is automatically created and initialized.

However, this can be confusing since no prior declaration of x exists.

For clarity reasons, it is recommended that a prior declaration exists. The preferred way here is to use #dim which, even though it will do nothing to create the variable itself, has the advantage that you can declare the type, if any. Therefore, the code above would become:

Consider this code:

    Class Fubar
    {
    ClassMethod m(someArg as Some.Class)
    {
        if (someArg =' "") {
            w "my argument was a null oref", !
        }
    }
    }

There is a trap in this code.

ObjectScript allows spaces between the unary negation operator (that is, ') and its argument: 'a and ' a are the same.

Which means that another way to write the code above would be:

The $CASE function can be written without a default case, as in:

    set x = $case(someVar, "foo": val1, "bar": val2)

However, this means that if, in the above example, the value of x is neither "foo" nor "bar", the resulting value will be undefined.

On Unicode installations of Caché, it is possible to use letters in variable names which are not ASCII letters.

For instance, a program written in Caché could have a variable named validación.

ObjectScript allows local variables to have the same name as builtin commands, as in:

    set throw = 1

This is very confusing and should be avoided. It is highly recommended to change the variable name to something else.

It is customary to use the HANG command so that the debugger can attach to the running process when debugging code.

However, it frequently occurs that this extra statement, which is there only for debugging purposes, is not removed before the code is commited.

Please check that this usage of HANG is legitimate; if this is the case, mark this issue as a false positive.

ObjectScript allows to attach postconditionals to some commands; for instance:

    // Set the value only if condition c is true
    set:c x = 2

This is in fact equivalent to writing:

    if (c) {
        set x = 2
    }

This feature of the language may lead to shorter code overall; however, users unfamiliar with the language may have trouble understanding what this syntax means.

For understandability reasons, it is preferred to use an if statement instead.

The OPEN command has a very complicated syntax which is difficult to get right.

It is preferable to use classes from the %IO package instead which are much easier to use and provide the same functionality.

For instance, for opening a file, instead of using:

Given a property named, for instance, p in a class instance, ObjectScript automatically defines both getter and setter methods named, respectively, pGet() and pSet().

This means that the two following lines are equivalent:

    // Given an object instance o and a property p, write the value of p
    w o.p
    w o.pGet()

However, ObjectScript allows to override those methods. Consider the following:

The BREAK command is normally used in interactive code to suspend the execution of a program at a given point.

This means that it should never be used in non interactive code. You should check that this BREAK invocation is legitimate in this context.

Trap...

People coming from other languages where break exits a loop may be tempted to write, for instance:

Pages