Sign in Join
Wiki copytemporary

Comments: what changed

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

OldNewLine
11Go to: [[Reserved words]] \| [[Operators]]
22
33Comments are human-readable notes or other kinds of annotations to support understanding of code. They are not interpreted by the compiler and ignored when building your program.
44
55## Block comments
66
7-<div style="float:left; margin: 0 25px 20px 0; padding:50px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">
8-
97{
108
11-</div>
12-
13-<div style="float:right; margin: 0 25px 20px 0; padding:50px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">
14-
159}
1610
17-</div>
18-
1911Block comments are delimited by the characters `{ }`\
2012
21-<div style="float:left; margin: 0 20px 10px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">
22-
2313(*
2414
25-</div>
26-
27-<div style="float:right; margin: 0 20px 10px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">
28-
2915*)
3016
31-</div>
32-
3317or by the bigrams `(* *)`. The latter is a relict from times where computer keyboards did not necessarily have curly braces. It is *not wrong* to use the bigrams, but they are at large superseded by the use of curly braces. There is one place where the `(*` and `*)` bigrams can be useful. if you are testing code and want to "dike out" or disable certain sections by marking them as inoperative, the pieces can be surrounded by these bigrams, and it will not matter if there are and } comments inside of them.
3418
3519Example:
3620
3721``` pascal
3822{ public declarations }
3923```
4024
4125In Pascal block comments can be nested. However, nested block comment delimiters have to match: If a block comment starts with an opening curly brace, it can not be closed by asterisk-closing-parenthesis but has to be closed by another closing curly brace.
4226
4327There is a special class of comment, either beginning `{$` or `(*$`. This indicates the start of a *[[Compiler directive|compiler directive]]*, a special instruction to the ompiler about the program, but it does not actually generate instructions to be executed.
4428
4529## Line comments
4630
4731Line comments or inline comments start with comment delimiter [[Slash|//]] and continue until the [[End of Line|end of the line]]. Example:
4832
4933```delphi
5034// This is a stupid comment
5135```
5236
5337## Comments as declaration hints in Lazarus IDE
5438
5539The Lazarus IDE can display tooltip hints when mouseovering identifiers. You can control this in Options \> Editor \> Completion and Hints.
5640
5741The hint shows the function or variable definition, but can also include custom descriptive text taken from comment lines directly above the declaration.
5842
59-<figure>
60-<img src="laz-comment-hint.png" title="laz-comment-hint.png" />
61-<figcaption>laz-comment-hint.png</figcaption>
62-</figure>
43+![](/wiki-images/8/82/Laz-comment-hint.png)
6344
6445## Best practice for good comments
6546
6647Mentioning some general tips for writing “good” comments may not be left out here, too:
6748
6849- Write *why* something is done. Do not write *what* is done, since that can (provided *meaningful* identifiers are in place) be determined from the code itself. It would be redundant to repeat what the code already says by itself.
6950- Structure your comments. For example write a summary above each method definition explaining what it does and how to use it, i.e. what impact parameters have on the method's behavior.
7051- Especially name (non-trivial) *constraints* that came from other places, that made you choose writing a particular line of code, or select a particular approach to solve the problem.
7152- Write in *one* language throughout the whole project. De facto English is the most prevalent comment language, but especially in the context of teaching other languages are more suitable. It is important that all team members can express complex circumstances in the used language (that's easier said than done).
7253
7354## See also
7455
7556- [[Program Structure|program structure]]
7657- [category: compiler directives](/wiki-category/Compiler%20directives)
7758- [§ “Comments” in the “Free Pascal reference guide”](https://www.freepascal.org/docs-html/ref/refse2.html)
7859
7960---
8061*From the Free Pascal wiki, page "Comments", as it stood on 2022-08-06 after a change by Kai Burghardt, 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).*

Back to history