Fpsonar layout

← Back to fpsonar

Fifteen rules about whitespace, line length, keyword casing and stray punctuation. All are on by default. None will ever find a bug — they exist so that diffs stay small and so nobody spends review time on formatting.

If your project's conventions differ, these are the rules to reconfigure or switch off first. They encode one house style, not a universal truth.

NoTabs

edit

minor · on by default

Tabs render at different widths in different editors, so a file mixing tabs and spaces looks aligned to its author and ragged to everyone else. Use spaces.

fpsonar complains about this

procedure Run;
begin
→ Process;                    // tab indent
end;

fpsonar accepts this

procedure Run;
begin
  Process;
end;

NoTrailingWhitespace

edit

minor · on by default

Spaces at the end of a line are invisible and show up as noise in diffs. Most editors can strip them on save.

fpsonar complains about this

  Process;····                // trailing spaces

fpsonar accepts this

  Process;

LineTooLong

edit

minor · on by default · parameter maxLength (default 120)

Long lines force horizontal scrolling and make side-by-side diffs unreadable.

The rule counts characters, not bytes, so a line with accented text is measured as a reader sees it.

fpsonar complains about this

  Result := Format('%s scored %d in %s at %s', [APlayerName, AScore, AVenueName, FormatDateTime('yyyy-mm-dd hh:nn', AWhen)]);

fpsonar accepts this

  Result := Format('%s scored %d in %s at %s',
    [APlayerName, AScore, AVenueName,
     FormatDateTime('yyyy-mm-dd hh:nn', AWhen)]);

LowercaseKeywords

edit

minor · on by default

Pascal is case-insensitive, so BEGIN, Begin and begin all compile. Lowercase is the FPC convention, and consistency lets a reader tell keywords from identifiers at a glance.

fpsonar complains about this

Procedure Run;
Begin
  If Valid Then Process;
End;

fpsonar accepts this

procedure Run;
begin
  if Valid then Process;
end;

NoIndentUnitLevelKeywords

edit

minor · on by default

Unit-level keywords — unit, interface, implementation, uses, end. — start at column 1. They mark the file's top-level structure, so indenting them hides it.

fpsonar complains about this

unit Report;

  interface

  uses Classes;

fpsonar accepts this

unit Report;

interface

uses Classes;

IndentVisibilitySpecifiers

edit

minor · on by default

private, public and friends line up with the type declaration they belong to, not with the members inside them.

fpsonar complains about this

type
  TReport = class
      private
    FLines: TStringList;
  end;

fpsonar accepts this

type
  TReport = class
  private
    FLines: TStringList;
  end;

BeginEndRequired

edit

minor · on by default

Requires begin..end around a controlled statement even when it is a single statement. Verbose, but it removes a whole class of editing accident: adding a second statement to an unbraced if silently moves it outside the condition.

fpsonar complains about this

if Valid then
  Process;

fpsonar accepts this

if Valid then
begin
  Process;
end;

NoStraySemicolons

edit

minor · on by default

A semicolon that terminates nothing. Usually harmless, occasionally not — a stray semicolon after then creates an empty statement and detaches the branch, which is the EmptyThenWithFollowingStatement bug in control flow.

fpsonar complains about this

begin
  Process;;
end;

fpsonar accepts this

begin
  Process;
end;

NoOmittedSemicolons

edit

minor · on by default

Pascal allows the last statement before end to omit its semicolon. Including it means adding a statement afterwards touches one line rather than two.

fpsonar complains about this

begin
  Process;
  Finish
end;

fpsonar accepts this

begin
  Process;
  Finish;
end;

NoExtraneousCommas

edit

minor · on by default

A trailing or doubled comma in a list.

fpsonar complains about this

Log(Format('%s %s', [A, B, ]));

fpsonar accepts this

Log(Format('%s %s', [A, B]));

NoEmptyParenthesesOnRoutines

edit

minor · on by default

Pascal does not require () on a parameterless routine, in the declaration or at the call site. Omitting them is the convention.

fpsonar complains about this

procedure Run();
begin
  Process();
end;

fpsonar accepts this

procedure Run;
begin
  Process;
end;

RemoveRedundantParentheses

edit

minor · on by default

Parentheses that change nothing. Note this is the opposite direction from ParenthesizeAmbiguousNot below — the aim is parentheses exactly where precedence is genuinely unclear, and nowhere else.

fpsonar complains about this

if ((Valid)) then
  Total := ((A + B));

fpsonar accepts this

if Valid then
  Total := A + B;

ParenthesizeAmbiguousNot

edit

minor · on by default

not binds very tightly in Pascal — more tightly than comparison. So not A = B parses as (not A) = B, which is almost never what was written. Parenthesise the operand.

fpsonar complains about this

if not Count = 0 then         // parses as (not Count) = 0
  Handle;

fpsonar accepts this

if not (Count = 0) then
  Handle;

DigitGroupingStandard

edit

info · on by default

If you group digits in a numeric literal, group them consistently — threes for decimal, fours for hex.

fpsonar complains about this

const
  Limit = 1_00_000;

fpsonar accepts this

const
  Limit = 100_000;

LongNumericLiteralUnderscores

edit

info · on by default

A long literal without separators is hard to read and easy to mistype by one digit. FPC accepts _ as a digit separator.

fpsonar complains about this

const
  MaxValue = 2147483647;

fpsonar accepts this

const
  MaxValue = 2_147_483_647;
edit

How declarations are grouped and split across lines is in declarations. Comment formatting is in comments.

See also

edit
  • fpsonar — what fpSonar is, and how to run it

← Back to fpsonar