473,773 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Commenting style?

Can someone recommend a good source of C/C++ coding style.
Specifically, I am interested in commenting style and in
particular how to indent comments and the commented code, rather
than when to use comments. Thanks in advance!
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 11 '07
100 4759

Keith H Duggar wrote:
Seungbeom Kim wrote:
That style of commenting falls into the same category as
this:

++x; // increment x

and I would object to it, unless the code is for
exposition of the relevant part of the language in a C++
textbook.

/** First Paragraph */
This is a good observation. Perhaps such comments should
also be avoided in textbooks as well? Those who learn from
such books may come to believe this is good style (after all
it's in a book!) and hence fall into the habit of writing
such useless comments. // End First Paragraph
The fundamental problem is that actually programming generally pays
better
than teaching programming, so most people end up learning to program
from
mediocre programmers. Fortunately, some good programmers have written
books. Unfortunately, few schools seem to select those books.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #41
Angel Tsankov <fn*****@fmi.un i-sofia.bgwrites:
Can you point out such an editor?
Emacs: "/ runs `c-electric-slash'."
Again: example of an editor providing this functionality?
Emacs: "M-q runs `c-fill-paragraph'."

--
Steven E. Harris

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #42
Keith H Duggar wrote:
/** Second Paragraph */
Books are not ASCII source code and are not bound by it's
limitations. Authors are free to use a variety of expository
tools (tables, line numbers, weights, styles, colors, etc)
and I have seen all these alternatives used in programming
textbooks. So don't we set a bad example by choosing the
useless redundant comment tool? // End Second Paragraph
Sometimes the "book" and the source code are the same thing, as in literate
programming. For a real world example, have a look at "Physically Based
Rendering" from Matt Pharr and Greg Humphreys. The layout of the book is
amazing, the source code (c++) is perfectly readable and has perfectly
helpful documentation.

So it is possible to achieve good documentation, readable layout with lots
of additional information and maintainable source at once. But I can't
imagine, how much discipline it takes to consequently follow the rules of
such documentation style. And the worst is, currently there are very few
tools that help, to do this kind of intermixed coding/documenting.

Regards
Stephan

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #43
ia******@hotmai l.com (Ian Collins) wrote (abridged):
What's wrong with isEmpty()? Sums up the comment and is unambiguous.
"IsEmpty" is hardly better than "empty" in that both assume the reader
knows what "empty" means. As I explained, projects often develop
specialised vocabularies that need to be documented.

(What's wrong with "isEmpty" specifically is that it's inconsistent with
std::vector; but we're surely talking general principles here and don't
want to nit-pick details of the examples.)

-- Dave Harris, Nottingham, UK.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #44
Dave Harris wrote:
ia******@hotmai l.com (Ian Collins) wrote (abridged):
>>What's wrong with isEmpty()? Sums up the comment and is unambiguous.


"IsEmpty" is hardly better than "empty" in that both assume the reader
knows what "empty" means. As I explained, projects often develop
specialised vocabularies that need to be documented.
If a team or project has an established metaphor, it doesn't require
explanatory comments in the code. If anywhere, such documentation
belongs in the project documentation or Wiki.

--
Ian Collins.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #45
* Dave Harris:
ia******@hotmai l.com (Ian Collins) wrote (abridged):
>What's wrong with isEmpty()? Sums up the comment and is unambiguous.

"IsEmpty" is hardly better than "empty" in that both assume the reader
knows what "empty" means. As I explained, projects often develop
specialised vocabularies that need to be documented.

(What's wrong with "isEmpty" specifically is that it's inconsistent with
std::vector; but we're surely talking general principles here and don't
want to nit-pick details of the examples.)
Conforming to a convention just for conformance's sake is seldom a good
idea.

The C++ standard library constitutes a fine set of examples of how to
/not/ name things, a standardized "worst practice", which it's not a
good idea to conform to -- presumably the idea was to force novice C++
programmers to struggle with these names and so understand, from the
inflicted pain, what to avoid in their own code (it would be nice to
also have a set of "best practice" examples in the standard, carrots in
addition to the sticks, and there are some, e.g. the names 'list' and
'vector', which are short, readable and self-documenting names, but
unfortunately only the stick method of providing how-not-to-do-it
examples now seems to be in vogue with the international C++ committee,
and now applied also to the language itself, e.g. 'declspec').

And 'empty' is perhaps one of the best of these "worst practice"
examples, because it's short and readable and actually related to what
the function accomplishes, while suggesting something else, namely
suggesting an action (make empty) instead of a check (is empty), thus
sending the unsuspecting novice in the wrong direction first.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #46
Dave Harris wrote:
"IsEmpty" is hardly better than "empty" in that both assume the reader
knows what "empty" means. As I explained, projects often develop
specialised vocabularies that need to be documented.
Knowing what "empty" means does not resolve the ambiguity, which is
caused by the nature of the English language: little inflectional and
conjugational variation, usage of words both as verbs and adjectives.
Thus the word "empty" by itself could either be interpreted as an
imperative ("empty!"), or as an abbreviated question ("empty?").

I prefer to prefix boolean queries with "is" or "has" because it avoids
unnecessary mental effort on the part of the reader.
(What's wrong with "isEmpty" specifically is that it's inconsistent
with std::vector; but we're surely talking general principles here and
don't want to nit-pick details of the examples.)
The C++ Standard Library naming convention is not very helpful in that
empty() is used as an adjective (query), but clear() as a verb
(command). Obviously, terseness was valued higher than intuitive
understanding.

--
Gerhard Menzl

Non-spammers may respond to my email address, which is composed of my
full name, separated by a dot, followed by at, followed by "fwz",
followed by a dot, followed by "aero".

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #47
kevin cline wrote:
Better naming works wonders, but first one has to see a program
with consistently good naming. In my experience, few programmers
have seen such a program.
Do you know one (or more ;) whose code is public?
Martin

--
Quidquid latine scriptum est, altum videtur.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #48

Dave Harris wrote:
ia******@hotmai l.com (Ian Collins) wrote (abridged):
What's wrong with isEmpty()? Sums up the comment and is unambiguous.

"IsEmpty" is hardly better than "empty" in that both assume the reader
knows what "empty" means. As I explained, projects often develop
specialised vocabularies that need to be documented.
Is "empty" a question or command? I don't see that ambiguity with
"is_empty".
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #49
Gerhard Menzl wrote:
Dave Harris wrote:
>"IsEmpty" is hardly better than "empty" in that both assume the reader
knows what "empty" means. As I explained, projects often develop
specialised vocabularies that need to be documented.

Knowing what "empty" means does not resolve the ambiguity, which is
caused by the nature of the English language: little inflectional and
conjugational variation, usage of words both as verbs and adjectives.
Thus the word "empty" by itself could either be interpreted as an
imperative ("empty!"), or as an abbreviated question ("empty?").

I prefer to prefix boolean queries with "is" or "has" because it avoids
unnecessary mental effort on the part of the reader.
Then how would you name a function that does the emptying action?
make_empty()?
>(What's wrong with "isEmpty" specifically is that it's inconsistent
with std::vector; but we're surely talking general principles here and
don't want to nit-pick details of the examples.)

The C++ Standard Library naming convention is not very helpful in that
empty() is used as an adjective (query), but clear() as a verb
(command). Obviously, terseness was valued higher than intuitive
understanding.
I think the C++ Standard Library established the convention anyway,
no matter how bad some people may argue it is (because it is "the"
standard). Then following the already-established convention certainly
has its merits, because people already know it.

--
Seungbeom Kim

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 16 '07 #50

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

Similar topics

46
2496
by: Profetas | last post by:
Hi, I know that this is off topic. but I didn't know where to post. Do you comment your source code while coding or after coding. for example: you write a procedure and after it is working, you'll comment it.
9
1877
by: | last post by:
Does C++/CLI have XML style commenting like C#?? If i do /// I dont get the completion like C#
8
1866
by: lallous | last post by:
Hello I've been programming for a number of years, however my commenting style is always different. Sometimes I use something like: /************************ * method .... * comments... *************************/
0
9621
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
9454
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,...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
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
6717
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
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2852
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.