# 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.
* **Case Statements:** The `else` keyword in a `case` statement should be aligned with the `case` keyword, and the code within the `else` block should be indented.
```pascal
var value := 1;
procedure DoSomething; begin end;
procedure DoSomethingElse; begin end;
procedure DoDefault; begin end;
case value of
1: DoSomething;
2: DoSomethingElse;
else
DoDefault;
end;
```
* **Spacing:** Mandatory spaces around assignment `:=` and after commas `,`.
:::info
#### Tip
You can use the `TdwsAutoFormat` class in your own tools to programmatically clean up DWScript source code according to these rules.
:::
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.
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.
Case Statements: The else keyword in a case statement should be aligned with the case keyword, and the code within the else block should be indented.
var value :=1;procedure DoSomething;beginend;procedure DoSomethingElse;beginend;procedure DoDefault;beginend;case value of1: DoSomething;2: DoSomethingElse;else
DoDefault;end;
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.