Menu

#200 Alternative formatting layout around conditionals

open
nobody
Formatter (6)
5
2025-09-15
2025-09-15
Lars Fosdal
No

The purpose is to hi-lite the if/then/else on separate lines, using single char indentation for breaking the visual pattern when only using simple statements and not blocks.
I also prefer a blank line before and after the conditional blocks, the way it looks in the examples below.

See also: https://en.delphipraxis.net/topic/14363-new-delphi-features-in-delphi-13/?do=findComment&comment=107848

// if then / if then else single statements

if Condition
 then Action;

if Condition
 then Action
  else Alternative;

if Condition // sometimes I use these variation - yeah I know, not 100% consistant.
 then Action
else begin
  Alternative; 
end;

if Condition
then begin
  Action;
end
 else Alternative;

if Condition
then begin
  Action;
end
else begin
  Alternative;
end;

// for / while

for var x in Collection
 do Something(x);

for var x in Collection
do begin
  Something(x);
end;

while Condition
 do Action;

while Condition
do begin
  Action;
end;

Discussion


Log in to post a comment.

MongoDB Logo MongoDB