473,385 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1964
"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.merkerk(at)dse.nl

Jul 22 '05 #6
"Victor Bazarov" <v.********@comAcast.net> wrote in message news:<YNbub.174219$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
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,...
4
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,...
10
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...
4
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'...
14
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...
1
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...
4
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...
9
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...
4
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 (¿)...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.