Hi Folks,
I'm wondering if there is a compilation of C++ guidelines out there
anywhere. Here are some of the ones I've picked up so far (as examples):
- Functions should fit on one screen, from various sources.
- Non-leaf classes should be abstract (have pure virtual methods), from
More Effective C++, Item 33.
- Virtual methods should be private by default and protected if they
need access to a base classes version (except for the destructor, of
course), from http://www.gotw.ca/publications/mill18.htm.
- Header files should be self contained, from various sources.
- Destructors for base classes should be either virtual or protected.
I think I've probably missed (or never heard of) quite a few more.
Anyone know where I can find such things? Or have some guidelines of
their own to share?
-- Pete
Jul 22 '05
64 3371
"Pete Vidler" <pv*****@mailbl ocks.com> wrote in message
news:OV******** ****@newsfe1-gui.server.ntli .net... A suggestion. Functions could easily be longer once you add blank lines
and comments. Functions that are pretty straightforward but long, say
because they have to read in a lot of input arguments, are fine, it seems to me.
As soon as you start to process input arguments and do stuff, that's when
the long function should raise a bell.
A related concept is that functions should have few input arguments.
I usually adhere to this one because I find that I make fewer mistakes if the entire method is immediately available. I'm not sure how this relates to the number of arguments, but I'll accept that as a suggestion.
Worry about cohesion rather than number of lines. If you worry too much
about number of lines, then you'll start breaking down every 2 lines into
function, and that can make things *less* readable ultimately.
"jeffc" <no****@nowhere .com> wrote in message
news:40******** @news1.prserv.n et... "Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message - Header files should be self contained, from various sources.
What?
Makes sense to me, and I wholeheartedly agree. Nothing worse than unnecessary dependencies in header files.
You mean like header A.h fails to include B.h though it depends on entities
from B.h. Then the user who includes A.h has to include B.h first then A.h.
Is this what you mean? If so, definitely this is a good rule.
In fact, my cpp files always include the h file as the first non-comment
line. But in windows they have this stdafx.h if you use pre-compiled
headers, and so you shouldn't by accident include B.h in this file.
Pete Vidler wrote: I am not patting myself on the back. I do not believe it will be obvious to me. It's just that the book has some /very/ mixed reviews on the internet, so I need some solid reassurance that it covers the kind of guidelines that I mentioned earlier before I go out and buy it.
-- Pete
I got to #3, and so far, I'm finding these worth considering. I suggest
reading with your eyes open. #3 threw me for a loop at first.
The Top 20 C++ Tips of All Time http://www.devx.com/cplus/Article/16328/0/page/1
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Steven T. Hatton wrote: Pete Vidler wrote:
I am not patting myself on the back. I do not believe it will be obvious to me. It's just that the book has some /very/ mixed reviews on the internet, so I need some solid reassurance that it covers the kind of guidelines that I mentioned earlier before I go out and buy it.
-- Pete I got to #3, and so far, I'm finding these worth considering. I suggest reading with your eyes open. #3 threw me for a loop at first.
Doh! #2 is the one that tripped me up.
The Top 20 C++ Tips of All Time http://www.devx.com/cplus/Article/16328/0/page/1
Can I trust #4? I believe I can by virtue of this: http://www.itga.com.au/~gnb/wp/cd2/
3.6.2 Initialization of non-local objects [basic.start.ini t]
1 The storage for objects with static storage duration
(_basic.stc.sta tic_) shall be zero-initialized (_dcl.init_) before any
other initialization takes place. Objects of POD types
(_basic.types_) with static storage duration initialized with constant
expressions (_expr.const_) shall be initialized before any dynamic
initialization takes place. Objects of namespace scope with static
storage duration defined in the same translation unit and dynamically
initialized shall be initialized in the order in which their defini-
tion appears in the translation unit. [Note: _dcl.init.aggr_
describes the order in which aggregate members are initialized. The
initialization of local static objects is described in _stmt.dcl_. ]
But I'm not sure if there are any subtelties I need to be aware of.
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Siemel Naran <Si*********@re move.att.net> spoke thus: In fact, my cpp files always include the h file as the first non-comment line. But in windows they have this stdafx.h if you use pre-compiled headers, and so you shouldn't by accident include B.h in this file.
If one writes header files correctly, including header files
accidently causes very minor effects at worst.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: beliavsky |
last post by:
Is there a more recent set of Python style guidelines than PEP 8,
"Style Guide for Python Code", by van Rossum and Warsaw, at
http://www.python.org/peps/pep-0008.html , which is dated July 5,
2001?
|
by: stevehayter |
last post by:
Wonder if anyone can help me solve this problem!
I have a 3x3 table which i'm using to create a table with a rounded
edge using images in the top left, top right, bottom left, and bottom
right cells and lines in the top/left/right and bottom cells (sounds
odd, you'll see what i mean when you see the site). It works fine,
except the top and bottom rows are a lot bigger than i've specified
when they should be flush with the centre cell as...
|
by: Pete Vidler |
last post by:
Hi Folks,
I'm wondering if there is a compilation of C++ guidelines out there
anywhere. Here are some of the ones I've picked up so far (as examples):
- Functions should fit on one screen, from various sources.
- Non-leaf classes should be abstract (have pure virtual methods), from
More Effective C++, Item 33.
|
by: E. Robert Tisdale |
last post by:
C++ Programming Style Guidelines
http://geosoft.no/development/cppstyle.html
I think that these guidelines are almost *all* wrong.
For example:
11. Private class variables should have underscore suffix.
class SomeClass {
private:
|
by: jamilur_rahman |
last post by:
What is the BIG difference between checking the "if(expression)" in A
and B ? I'm used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A ?
style A:
....
....
int a = 1;
if(0==a)
{
| |
by: John Salerno |
last post by:
Does Microsoft have any naming guidelines for variables? I've been
reading their guidelines for just about every other type (methods,
parameters, properties, etc.) but nothing about variables. Are variables
treated the same as parameters (i.e., camel case)?
I notice that Hungarian notation is being done away with.
Also, is it good practice to use an underscore to begin the name of a
field? I've seen that, and it seems like a good idea,...
|
by: Laurent Bugnion [MVP] |
last post by:
Hi group,
In agreement with the head of our R&D department, I published my firm's
JavaScript Coding Guidelines. I work for Siemens Building Technologies.
We developed these guidelines for a web application project in 2004,
based on our C# guidelines.
http://www.galasoft-lb.ch/myjavascript/Siemens_SBT_JavaScript_Coding_Guidelines.pdf
Please note the following:
|
by: mrashidsaleem |
last post by:
Can anyone guide me what is wrong with the naming conventions
suggested below? I know that this is not recommended by many
(including Microsoft) but I need to know what exactly is the rationale
behind going for a different convention in .NET. The recommendations
do make sense (to me, at least but I may be wrong and would like
someone to correct me).
Scope Prefixes
Member Variable Prefix: Most of the people still use (and like the
idea...
|
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...
|
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,...
|
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...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |