In this article:

General Information

Description

Principles of Naming

Code Formatting

Indents

Spaces

Empty Lines

Other

Example

Rules of Code Designing

Article number: KB000005

General Information

Related blocks:

Description

See below recommendations on designing the source code of application systems in Foresight Analytics Platform. Coding style is supported automatically by the Platform editor when the Use Code Autoformatting option is enabled in settings of the development environment.

Principles of Naming

Code Formatting

Tab and space characters are to be used for code formatting. Tab character should be used to make indents while the space character is to separate lexemes in code.

Indents

Indents (single tab characters) are to be used in the following cases:

Var
    I: Integer;

Function Calculate(FirstParameter,
    SecondParameter: Integer; Var ThirdParameter: Integer);
    
ThirdParameter := FirstParameter +
    SecondParameter * FirstParameter;

Function ConvertValue(Value: Variant): Integer;
Begin
    Alfa := 1;
End;

Class ConfirmForm: Form;
    OkButton: Button;
End Class;

Enum Colors;
    Red,
    Green,
    Blue
End Enum Colors;

Select Case Value
    Case 0:
        Alfa := 1;
        Beta := 2;
    Else
        Gamma := 3;
End Select;

If Value = 0 Then
    Alfa := 1;
Else
    Beta := 2;
End If;

For I := 0 To Count - 1 Do
    Alfa := 1;
End For

For Each V In List Do
    Debug.WriteLine(V);
End For;

While I < Count Do
    Alfa := 1;
End While

Repeat
    Alfa := 1;
    I := I + 1;
Until I = Count;

Try
    Alfa := 1;
Except
    Beta := 2;
Finally
    Gamma := 3;
End Try;

Using indents in other cases is not allowed.

Spaces

Spaces should be used to separate lexemes in source code. Several consecutive spaces between lexemes are to be replaced with one space character.

Spaces should be used to separate lexemes in the following cases:

Spaces should not be use to separate lexemes in the following cases:

Empty Lines

An empty line should be used in the following cases:

Other

Statements from one language construct (Begin – End, Repeat – Until, Try – Except – Finally – End Try, Select – End Select, and others) must be in one position in the string (in one column).

Example

Enum WhatICanDo
    GetSomeSleep,
    BrowseInternet,
    PlayFavouriteGame
End Enum WhatICanDo;

// Demo class
Class GOODFORMATForm: Form
    PlayGame: Button;
    CancelButton: Button;
    BrowseInet: Button;
    SomeSleep: Button;

    Sub CancelButtonOnClick(Sender: Object);
    Begin
        Self.Close;
    End Sub CancelButtonOnClick;

    Sub Sleep(Millisecs: Integer);
    Var
        J, I: Integer;
    Begin
        I := (Millisecs + 999Div 1000;
        While I > 0 Do
            For J := 0 To 999 Do
                If Millisecs > 0 Then
                    Millisecs := Millisecs - 1;
                Else
                    I := 0;
                    Break;
                End If;
            End For;
            I := I - 1;
        End While;
    End Sub Sleep;

    Sub ShellExecute(Command: String);
    Begin
        Repeat
            Command := Command + " ";
        Until Command.Length > 100;
    End Sub ShellExecute;

    Function CreateProcess(ProcessName: String): Boolean;
    Var
        Result: Boolean;
    Begin
        Result := True;
        Try
            WinApplication.NotImplementedBox;
            Raise New Exception.Create("This function is not yet implemented");
        Except
            Result := False;
            WinApplication.InformationBox(
                "Execution error in  GOODFORMATForm.CreateProcess");
        End Try;
        Return Result;
    End Function CreateProcess;

    Sub HaveFun(Action: WhatICanDo);
    Begin
        Select Case Action
            Case WhatICanDo.GetSomeSleep:
                Sleep(60000 * 30);
            Case WhatICanDo.BrowseInternet:
                ShellExecute("http://www.favouritesite.com");
            Case WhatICanDo.PlayFavouriteGame:
                CreateProcess("C:\Quake3\Quake3.exe");
            Else
                WinApplication.InformationBox("Nothing to do!");
        End Select;
    End Sub HaveFun;

    Sub PlayGameOnClick(Sender: Object);
    Begin
        HaveFun(WhatICanDo.PlayFavouriteGame);
    End Sub PlayGameOnClick;

    Sub BrowseInetOnClick(Sender: Object);
    Begin
        HaveFun(WhatICanDo.BrowseInternet);
    End Sub BrowseInetOnClick;

    Sub SomeSleepOnClick(Sender: Object);
    Begin
        HaveFun(WhatICanDo.GetSomeSleep);
    End Sub SomeSleepOnClick;

End Class GOODFORMATForm;

See also:

Developers Knowledge Base