Best Practices for .NET Projects

Although PowerScript is essentially a compiled language, it is quite tolerant. For the sake of performance, the PowerBuilder .NET compiler is not designed to be as tolerant as the PowerBuilder native compiler.

To be able to compile your applications with .NET, you should avoid certain practices in your PowerScript code.

Syntax issues

These language-level items apply when you plan to transform a PowerBuilder application to a Windows Forms or Web Forms application.
  • Avoid the GoTo statement — jumping into a branch of a compound statement is legal in PowerBuilder, because the concept of scope inside a function does not exist in PowerScript.
    For example, the following code works well in PowerBuilder:
    if b = 0 then
       label: …
    else
        …
    end if
    goto label
    
    This PowerScript translates conceptually into the following C# code:
    if (b == 0) 
    {	// opening a new scope   
       label: … 
    } 
    else 
    {
        …
    }
    goto label; 

    Since a GoTo statement is not allowed to jump to a label within a different scope in .NET, the C# code would not compile. For this reason, avoid using GoTo statements.

  • Do not call an indirect ancestor event in an override event — suppose that there are three classes, W1, W2, and W3. W1 inherits from Window, W2 inherits from W1, and W3 inherits from W2. Each of these classes handles the Clicked event.
In the Clicked event of W3, it is legal to code the following in PowerScript:
call w1::clicked
However, in C#, calling the base method of an indirect base class from an override method is not allowed. The previous statement translates into the following C# code, which might produce different behavior:
base.clicked();

In this example, a possible workaround is to move code from the Clicked event of the indirect ancestor window to a window function, and then call the function, rather than the original Clicked event, from the descendant window.

Semantic issues

External functions