Style Guide & Code Rules

DWScript promotes a consistent coding style through its built-in rules engine (Gabelou). Following these guidelines ensures that your code remains readable and idiomatic.

Naming Conventions

CamelCase

  • Parameters: procedure DoWork(itemCount : Integer);
  • Local Variables: var userName := 'John';

PascalCase

  • Functions/Procedures: function CalculateTotal : Float;
  • Types: type TUserRecord = record ... end;
  • Properties: property FullName : String ...

Prefixes & Suffixes

Category Rule Example
Private Fields Start with F followed by PascalCase FInternalValue
Class Variables Start with v followed by PascalCase vGlobalCounter
Constants Start with c + PascalCase OR ALL_CAPS cDefaultPort, MAX_RETRY
Exceptions Type names starting with E should be Exception classes EValidationError
Attributes Should end with Attribute and NOT have a T prefix WebMethodAttribute

Formatting Rules

Consistency is key to a healthy codebase. The following rules are promoted by the formatter:

  • Compact Blocks: Keeping begin on the same line as then, else, or do is encouraged to reduce vertical space.
  • Multiline Strings: For long or multi-line strings (using #' or #" ), it is recommended to place the closing delimiter on a new line. This improves readability and makes it easier to append content.
  • Indentation: Content within blocks is always indented to show structure.
  • Spacing: Mandatory spaces around assignment := and after commas ,.

Tip

You can use the TdwsAutoFormat class in your own tools to programmatically clean up DWScript source code according to these rules.

On this page