Sign in Join
Wiki copytemporary

Coding style: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## FPC compiler and RTL
22
33### Introduction
44
5-Some people might think that the coding style used in the FPC compiler and base RTL (run-time library) source code is a little bit strange. But it has been in use for a lot of years and is not subject to discussion. So take the following as a standard to be used.
5+Some people might think that the coding style used in the FPC compiler and base RTL (run-time library) source code is a little bit strange. But it has been in use for a lot of years and is not subject to discussion. So take the following as a standard to be used.
66
77### Keywords
88
9-Write all keywords in all lower *snake_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.
9+Write all keywords in all lower _snake_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.
1010
1111### Spaces
1212
13-Don't use spaces around operators, colons, parentheses etc.
14-
15-``` pascal
13+Don't use spaces around operators, colons, parentheses etc.
14+```
1615{ correct }
17-p:=p+i;
18-
19-{ incorrect }
20-p := p + i ;
16+ p:=p+i;
17+
18+ { incorrect }
19+ p := p + i ;
2120```
2221
23-Spaces in parameter lists. TODO: ???
24-
25-``` pascal
22+Spaces in parameter lists. TODO: ???
23+```
2624function do_this(a: tdef; var b: tdef): boolean;
2725```
2826
29-Spaces in variable lists. TODO: ???
30-
31-``` pascal
27+Spaces in variable lists. TODO: ???
28+```
3229var
33- a,b,c : tprocdef;
30+ a,b,c : tprocdef;
3431```
3532
3633### TAB characters
3734
38-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*).
35+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_).
3936
4037### Indentation
4138
42-Indentation size is always 2 space characters per level.
43-
44-Never place a *begin* on the same line as while..do/if..then/..., but always on its own line (and indent it compared to the while/if/...).
39+Indentation size is always 2 space characters per level.
4540
46-``` pascal
41+Never place a _begin_ on the same line as while..do/if..then/..., but always on its own line (and indent it compared to the while/if/...).
42+```
4743{ correct }
48-if true then
49- begin
50- end;
51-
52-{ incorrect }
53-if true then begin
54- end;
55-
56-{ incorrect }
57-if true then begin {...} end;
44+ if true then
45+ begin
46+ end;
47+
48+ { incorrect }
49+ if true then begin
50+ end;
51+
52+ { incorrect }
53+ if true then begin {...} end;
5854```
5955
6056### Newlines
6157
62-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.
58+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.
6359
6460### Comments
6561
66-Comments should use curly brackets, be lower case and contain a single space between the {}.
67-
68-``` pascal
62+Comments should use curly brackets, be lower case and contain a single space between the {}.
63+```
6964{ this is an example of a comment }
7065```
7166
7267### Routines
7368
74-All sections (var, const, begin etc...) after routine header are indented one level.
75-
76-``` pascal
69+All sections (var, const, begin etc...) after routine header are indented one level.
70+```
7771procedure do_this;
78- var
79- sym: tsym;
80- begin
81- end;
72+ var
73+ sym: tsym;
74+ begin
75+ end;
8276```
8377
84-No spaces after name and parenthesis for parameters.
85-
86-``` pascal
78+No spaces after name and parenthesis for parameters.
79+```
8780procedure do_this(param: integer);
88- begin
89- end;
81+ begin
82+ end;
9083```
9184
92-Nested functions are indented one level (the same level as other sections like var, const etc...)
93-
94-``` pascal
85+Nested functions are indented one level (the same level as other sections like var, const etc...)
86+```
9587procedure do_this;
96- var
97- i: integer;
98-
99- { nested function }
100- function getter: boolean;
101- begin
102- end;
103-
104- var
105- x: integer;
106- begin
107- end;
88+ var
89+ i: integer;
90+
91+ { nested function }
92+ function getter: boolean;
93+ begin
94+ end;
95+
96+ var
97+ x: integer;
98+ begin
99+ end;
108100```
109101
110-Use result instead of function name for return values.
111-
112-``` pascal
102+Use result instead of function name for return values.
103+```
113104function getter: boolean;
114- begin
115- result:=true;
116- // wrong!
117- //getter:=true;
118- end;
105+ begin
106+ result:=true;
107+ // wrong!
108+ //getter:=true;
109+ end;
119110```
120111
121112### Classes/Records
122113
123-Class sections should appear on the same indention level as the class name.
124-
125-``` pascal
114+Class sections should appear on the same indention level as the class name.
115+```
126116tloadnode = class(tunarynode)
127-protected
128- fprocdef : tprocdef;
129-public
130- constructor create(v : tsym;st : TSymtable);virtual;
131-end;
117+ protected
118+ fprocdef : tprocdef;
119+ public
120+ constructor create(v : tsym;st : TSymtable);virtual;
121+ end;
132122```
133123
134124### Misc
135125
136-Please note that the `else` in consecutive `if`s is not indented:
137-
138-``` pascal
139- if x then
140- begin
141- ..
142- end
143- else if y then
144- begin
145- ...
146- end;
126+Please note that the `else` in consecutive `if`s is not indented:
147127```
148-
149-Split all composite if-conditions over multiple lines, so no "if (x) and (y) then" but
128+if x then
129+ begin
130+ ..
131+ end
132+ else if y then
133+ begin
134+ ...
135+ end;
136+```
150137
151-``` pascal
138+Split all composite if-conditions over multiple lines, so no "if (x) and (y) then" but
139+```
152140if p1.nodetype=ordconstn and
153- not is_boolean(p1.resultdef) and
154- not is_enum(p1.resultdef) then
155- begin
156- ...
141+ not is_boolean(p1.resultdef) and
142+ not is_enum(p1.resultdef) then
143+ begin
144+ ...
157145```
158146
159-(except possibly if x and y are simply boolean variables)
160-
161-Extraneous parenthesis in if statements: TODO: ???
147+(except possibly if x and y are simply boolean variables)
162148
163-``` pascal
149+Extraneous parenthesis in if statements: TODO: ???
150+```
164151if (pd.maxparacount>0) then
165- ;
152+ ;
166153```
167154
168155### Examples
169156
170-How it looks like can be easily checked by having a look at the [FPC sources](http://www.freepascal.org/cgi-bin/viewcvs.cgi/?root=fpc).
157+How it looks like can be easily checked by having a look at the [FPC sources](<http://www.freepascal.org/cgi-bin/viewcvs.cgi/?root=fpc>).
171158
172159## FCL
173160
174-The FCL follows the same rules as above, with 1 exception: routines are not indented, and there are empty lines between the \`\`var\`\` section and surrounding code.
175-
176-So do not write
161+The FCL follows the same rules as above, with 1 exception: routines are not indented, and there are empty lines between the ``var`` section and surrounding code.
177162
178-``` pascal
163+So do not write
164+```
179165procedure do_this;
180- var
181- sym: tsym;
182- begin
183- end;
166+ var
167+ sym: tsym;
168+ begin
169+ end;
184170```
185171
186-But write
187-
188-``` pascal
172+But write
173+```
189174procedure do_this;
190-
191-var
192- sym: tsym;
193-
194-begin
195-end;
175+
176+ var
177+ sym: tsym;
178+
179+ begin
180+ end;
196181```
197182
198183## Other packages distributed with FPC
199184
200185There are no formal standards. **To do: write me.**
201186
202187## Lazarus
203188
204-Since Lazarus and LCL follow Delphi compatibility, a code style similar to the one used in Delphi is used.
189+Since Lazarus and LCL follow Delphi compatibility, a code style similar to the one used in Delphi is used.
205190
206-If you're writing a patch or an extension for LCL you should follow its code style.
191+If you're writing a patch or an extension for LCL you should follow its code style.
207192
208-If you're developing your own component, you're free to use any style you like, but it's suggested to use the LCL style, too.
193+If you're developing your own component, you're free to use any style you like, but it's suggested to use the LCL style, too.
209194
210195See the Lazarus coding guidelines: [[DesignGuidelines]]
211196
212-For reference, you can find the description of Delphi coding style [here](http://edn.embarcadero.com/article/10280#8.2.3)
197+For reference, you can find the description of Delphi coding style [here](<https://docwiki.embarcadero.com/RADStudio/Athens/en/Delphi%E2%80%99s_Object_Pascal_Style_Guide>)
213198
214199## See also
215200
216-- [[DesignGuidelines|Coding Guidelines for Lazarus]]
201+ * [[DesignGuidelines|Coding Guidelines for Lazarus]]
217202
218203---
219-*From the Free Pascal wiki, page "Coding style", as it stood on 2022-01-07 after a change by Michael, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
220-Category: Coding style
221-Category: FPC
222-Category: FPC development
223-Category: Lazarus
204+*From the Free Pascal wiki, page "Coding style", as the Internet Archive kept it on 2025-12-24, last changed on 2025-09-13. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history