Chapter 20 ObjectScript - Potential Pitfalls

Chapter 20 ObjectScript - Potential Pitfalls

The following items may be ObjectScriptconfusing to new programmers, especially those responsible for maintaining code written by other programmers:

  • Within a routine or method, each line must be indented by at least one space or tab unless it contains a label. That is, if there is any type of text at the first character position, the compiler IDEtreats it as a label.

There is one exception: curly braces are accepted at the first character position.

There must be a space (not a tab) between the command and its first argument. IDEOtherwise, you have a syntax error in your instructions:

insert image description here

Similarly, the terminal displays a syntax error as follows:

TESTNAMESPACE>write  5
 
WRITE  5
       ^
<SYNTAX>
TESTNAMESPACE>
  • ObjectScriptOperator precedence in an expression is strictly from left to right; operations within an expression are performed in the order in which they appear. You can use explicit parentheses in an expression to force certain operations to precede others.

Usually, parentheses are used even where they are not strictly required. Doing this is useful to other programmers (and later to yourself) because it makes the intent of your code clearer.

  • For historical reasons, the empty string ( ) ObjectScriptis not considered equal to a value. To table values, use . ( Is a system function that returns a decimal-based character.)""ASCII NULL示ASCII NULL$CHAR(0)$CHARASCII For example:
 write "" = $char(0)

Similarly, when ObjectScripta value is mapped to SQLor XML, the values ""​​and $CHAR(0)are treated differently.

  • ObjectScriptSome parts of are case-sensitive, while other parts are not. Case-insensitive entries include command names, function names, special variable names, namespace names, and user names.

Case-sensitive items include the names of most elements of the definition: routines, variables, classes, properties, and methods.

  • Most command names can be represented in abbreviated form. Therefore, WRITE, write, Write, Wand Ware all WRITEvalid forms of commands.
  • For many commands, it is possible to include postconditional expressions (often simply called postconditions).

This expression controls IRISwhether the command is executed. If the postcondition expression evaluates to true(non-zero), IRISthe command will be executed. If the expression evaluates to false(zero), IRISthe command is ignored and execution continues with the next command.

 Set count = 6
 Write:count<5 "Print this if count is less than five"
 Write:count>5 "Print this if count is greater than five"

The previous content produces the following output: If count is greater than 5then print this

Note: If postconditions are new to say, you may find the phrase "postcondition expression" somewhat misleading, as it (wrongly) indicates that the expression is executed after the command. Despite the name, postconditions are executed before the command.

  • You can have multiple commands on one line. For example:
 set myval="hello world" write myval

When doing this, note that if there are other commands on the line, you must use two spaces after any command that takes no arguments; otherwise, you will get a syntax error.

  • IFThe , ELSE, FORand DOcommands have two forms:

    • A newer form of block that uses curly braces to indicate blocks. For example:
     if (testvalue=1) {
          
          
     write "hello world"
    }
    

    ISCIt is recommended to use block form in all new code.

    • An older line-based form that does not use curly braces. For example:
     if (testvalue=1) write "hello world" 
    
  • Thanks to the preceding content, ObjectScriptit can be written in a very compact form. For example:

 s:$g(%d(3))'="" %d(3)=$$fdN3(%d(3)) q 

The class compiler automatically generates compact code of the form shown above (although not necessarily using abbreviated commands as in this example). Sometimes it's useful to look at the generated code, track down the source of a problem, or understand how something works.

  • ObjectScriptThere are no real reserved words in , so in theory there could be a setvariable named . However, it is prudent to avoid using SQLthe names of commands, functions, reserved words, and certain system items;
  • IRISAllocate a fixed amount of memory to hold the results of string operations. If the string expression exceeds the amount of allocated space, <MAXSTRING>an error is generated.

For class definitions, string manipulation limitations affect the size of string properties. IRISA system object (called a stream) is provided that can be used when it is necessary to process strings that exceed this limit; in this case, the stream interface class can be used.

Guess you like

Origin blog.csdn.net/yaoxin521123/article/details/132729260