Difference between revisions of "Coding style"

From Free Pascal wiki
Jump to navigationJump to search
(Use of spaces)
Line 9: Line 9:
  
 
== TAB characters ==
 
== 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.
+
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.
 
This may result in a chaotic view of source files.
 
Align by space characters (also see ''Indentation'').
 
Align by space characters (also see ''Indentation'').

Revision as of 06:27, 4 September 2009

Introduction

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.

Keywords

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.

Spaces

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

Indentation size is always 2 space characters per level.

Newlines

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.

Misc

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

if ... then
else if ... then
else if ... then

Examples

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