Coding style

From Lazarus wiki
Revision as of 22:53, 3 May 2013 by Chronos (talk | contribs)

FPC compiler


Some people might think that the coding style used by the FPC compiler sources and base rtl is a little bit strange but it has been used for a lot of years and isn't subject to be discussed. So take the following as a standard to be used.


Write all keywords in lower case. There is no need to make them unreadble by writing them in upper case. Modern IDEs support syntax highlighting, so keywords will be easily recognizable.


Don't use spaces around operators, colons, parentheses etc. e.g. write p:=p+i; instead of p := p + i ;.

TAB characters

Do not use TAB characters (ASCII HT, 0x09). There is no standard default TAB setting, so the look of source files using TAB characters will depend on client settings. This may result in a chaotic view of source files. Align by space characters (also see Indentation).


Indentation size is always 2 space characters per level.

Never place a begin on the same line as, but always on its own line (and indent it compared to the while/if/...).


Newlines are set as it is done by most Object Pascal programs (what does this mean? advice: avoid passive voice). Separate subroutines by three newlines, that is, put two blank lines between them.


Please note that the else in consecutive ifs is not indented:

if x then
else if y then

Split all composite if-conditions over multiple lines, so no "if (x) and (y) then" but

if x and
   y then

(except possibly if x and y are simply boolean variables)


How it looks like can be easily checked by having a look at the FPC sources.


Since Lazarus and LCL follows delphi compatibility, the similar code style is used.

If you're making patch or an extension for LCL you should follow its code style.

If you're developing your own component, you're free to use any style you like, but it's suggested to use LCL too.

You can find the description of Delphi coding style here

See also