473,800 Members | 2,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comments at the beginning of source files

Hello,

i'm looking for guidelines about what are the comments to be written at the
beginning of source files.
Thanks a lot.

Olivier
Jul 22 '05 #1
7 1981
"Olivier Mandavy" <ol************ *@wanadoo.fr> wrote in message
news:bp******** **@news-reader1.wanadoo .fr...
Hello,

i'm looking for guidelines about what are the comments to be written at the beginning of source files.


Describe the purpose of the file. You might also want
to include indications of the author, revision history,
dependencies, etc. The actual file contents can also
dictate what to write, e.g. if there is conditional compilation
(e.g. via #ifdef), then describe what the macros the #ifdefs
refer to mean.

It's all really up to you. Comments are for making the code more
easily readable and usable (by yourself and/or others).

-Mike
Jul 22 '05 #2
"Olivier Mandavy" <ol************ *@wanadoo.fr> wrote...
i'm looking for guidelines about what are the comments to be written at the beginning of source files.


The language does not require you to write any comments, nor does
it prohibit you from writing a whole novel. It's really up to you
what you want to share with those who you think will read the code
you have written.

If your primary concern for code maintainability , you might want
to indicate the overall purpose of the file, what it contains,
what project it is a part of, your name, who owns the copyright
(if it's not you). Often I see a list of changes in the same
general area as the title comment of the file. However, with
modern version control systems it is really unnecessary.

I am not sure how this is relevant to comp.lang.c++, though.
Perhaps you could tie it closer to the language (to make it on
topic) or go ask the same question in comp.software-eng.

Good luck!

Victor
Jul 22 '05 #3
Olivier Mandavy wrote:
Hello,

i'm looking for guidelines about what are the comments to be written at the
beginning of source files.
Thanks a lot.


Whatever you think appropriate.

It really depends on what you put in the file. Personally I
have one source file for each class and the comments refer
the reader to the header, which contains an overview of the
class and its typical usage.

The most important information though is change history -
who, why, and when, with similar history attached to each
function/method in the file. Ideally each change history
should refer to a bug or enhancement document which gives
more detailed information about each change.
Jul 22 '05 #4
lilburne wrote:
Olivier Mandavy wrote:
Hello,

i'm looking for guidelines about what are the comments to be written
at the
beginning of source files.
Thanks a lot.


Whatever you think appropriate.

It really depends on what you put in the file. Personally I have one
source file for each class and the comments refer the reader to the
header, which contains an overview of the class and its typical usage.

The most important information though is change history - who, why, and
when, with similar history attached to each function/method in the file.
Ideally each change history should refer to a bug or enhancement
document which gives more detailed information about each change.

One of the things I try to do is make the act of creating a new class as
low cost as possible and if it means that it exists only in one file so
be it. Yeah, sometimes it's not the best thing but it's a whole lot
better than a mash of repeated code everywhere. It's easier to rip out
a class from a file (when you realize what you need some factorization)
than it is to do code surgery. It's also easier to realize two (or
more) classes are easily factorizable than a "Mess O Code" (TM).

Also, the class boundary is rather an artificial place to decide to
"break" into files. I can think of a number of solutions that I would
literally define 100 or so very small very related classes. The
overhead of having all these in different files (i.e. having to compile
the headers for each one for each build) is rather onerous for no reason
that I can imagine.

Also, in many cases I simply want one compilable module that implements
an interface an have absolutly no-one be able to see the implementation
except for the things that exist within that implementation. Sure, I
could use private members but that can still cause linking issues.

A different opinion ...

Jul 22 '05 #5
> The most important information though is change history -
who, why, and when, with similar history attached to each
function/method in the file. Ideally each change history
should refer to a bug or enhancement document which gives
more detailed information about each change.


If you use a version control system this is not really necessary. The
same information is (should be) also in the version control system. My
experience is that most people prefer to use the version control system
to see what is changed, when and why. We used to have a macro in our
file comment headers that expanded to the complete revision history when
the file was retrieved from the version control system, essentially
producing what you described. It turned out that nobody used the source
file to look at the revision history, and that was considered to be
noise rather than useful information. Since then that macro was replaced
by a macro which just expands to the current revision number of the file
(which can be useful for example when you have a printed version of a
file).

--
Peter van Merkerk
peter.van.merke rk(at)dse.nl

Jul 22 '05 #6
"Victor Bazarov" <v.********@com Acast.net> wrote in message news:<YNbub.174 219$275.555414@ attbi_s53>...
"Olivier Mandavy" <ol************ *@wanadoo.fr> wrote...
i'm looking for guidelines about what are the comments to be written at

the
beginning of source files.


Often I see a list of changes in the same
general area as the title comment of the file. However, with
modern version control systems it is really unnecessary.


With modern version control systems, IMO including change history in a
comment block in the file is worse than unnecessary. If the change
history information exists in two places (comments in the file and the
version control system's log) then those two will inevitably diverge.
You gain nothing and you risk confusing the next person who has to
contend with discrepancies between the two histories.

This is the same as the argument against writing comments to describe
a piece of code, when the intent is clear from the code itself.

GJD
Jul 22 '05 #7
Gavin Deane wrote:
This is the same as the argument against writing comments to describe
a piece of code, when the intent is clear from the code itself.


My philosophy is that the comments should say "why", the code itself
already says "how"

Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3389
by: Sridhar R | last post by:
When writing a python library, we can use docstrings for methods and functions that are part of API. But what about comments for non-API objects or python application code? For applications, docstrings are not really much useful. Instead language comments are prefered for them. Language comments (starting with #) are usually considered to be a little more readable than docstrings (when reading the source code for understanding it).
4
10940
by: Uwe Ziegenhagen | last post by:
Hello, my fellows and me implement a c++ tool that is able to divide blank/tab separated files into <number>, <text>, <c-singlelinecomment> and <multilinecomment>. So far it's not working bad, we have just one problem if I call the a.exe that gcc compiles with the following textfile (./a.exe < test.txt) he does not match the multiline comments correctly. *test.txt contains:
10
2093
by: Monk | last post by:
Hi, Have a query regarding comments that extend over multiple-lines. Would like to know if the standard's view of this, so that we can create a code which doesn't run into compiler specific issues. 1. A normal comments is /* comment text */ 2. A multiple line comment is
4
1752
by: Michael Lang | last post by:
I need a simple way to parse comment lines from aspx (ASP.NET) files; in which comments are surounded by <%!-- and --%> So I created a simple regex: <%!--(?<val>.*)--%> With 'singleline' option on, and the following as input...
14
6114
by: dmh2000 | last post by:
I recently complained elsewhere that Python doesn't have multiline comments. i was told to use triple quoted strings to make multiline comments. My question is that since a triple quoted string is actually a language construct, does it use cause a runtime construction of a string which is then discarded, or is the runtime smart enough to see that it isn't used and so it doesn't construct it? example def fun(self):
1
8390
by: michael8 | last post by:
The problem was to write a program that reads a .cpp file containing a C++ program and produces a file with all comments stripped from the program. I finally got the answer. Here it is if someone want it as no one could do it : P #include <iostream>
4
3986
by: Joel Andres Granados | last post by:
Hi list: I have run across a situation with ConfigParser Module. It refers to the comments in the configuration filed. According to the http://docs.python.org/dev/lib/module-ConfigParser.html it states that lines starting with "#" and ";" are ignored. So lines like: ; comment # comment are considered comments. So far so good.
9
2940
by: Szabolcs | last post by:
I am not familiar with the UTF-8 encoding, but I know that it encodes certain characters with up to four bytes. Is it safe to use UTF-8 encoded comments in C++ source files? For example, is there a remote possibility that some multi-byte character, when interpreted byte-by-byte, will contain */ and close the comment? Or is there something else that can go wrong?
4
3616
by: maria | last post by:
I only use C++ with Visual Studio 6.0 for string manipulations in thousands of HTML pages on my website. Many times, the output files of many of my C++ programs contain a spanish question mark (¿) as their first character. What creates it? How do we avoid it? Thanks! maria
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.