473,624 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Guidelines

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 #1
64 3360
Pete Vidler <pv*****@mailbl ocks.com> wrote:
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?


Check out these two books:
"Large-Scale C++ Software Design" by John Lakos
"Object-Oriented Design Heuristics" by Arthur J. Riel

This site may also be helpful:
<http://www.chris-lott.org/resources/cstyle/>
Jul 22 '05 #2
Pete Vidler <pv*****@mailbl ocks.com> wrote:
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?


Check out these two books:
"Large-Scale C++ Software Design" by John Lakos
"Object-Oriented Design Heuristics" by Arthur J. Riel

This site may also be helpful:
<http://www.chris-lott.org/resources/cstyle/>
Jul 22 '05 #3
Pete Vidler wrote:
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.
Functions should have 1 to 5 activities. In higher level languages this
translates to 1 to 5 statements, but C++ requires a lot of rigging and
piping.
- Non-leaf classes should be abstract (have pure virtual methods), from
More Effective C++, Item 33.
The corpus of Addison Wesley [Longman]'s C++ and theory books form the
pinacle of known style. Try /Design Patterns/, /Large Scale C++ Software
Design/, and /Refactoring/.
- 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.
Also try /Exceptional C++/, by Herb Sutter.
- Header files should be self contained, from various sources.
The implication here is you can always add a new #include "thing.h", and it
takes care of itself. You never need to add another #include above it.
/Large Scale/ covers this in great detail.
- Destructors for base classes should be either virtual or protected.
Never heard of the "protected" one.
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?


These guidelines occupy a spectrum. At one end, we have requirements that
C++'s minimal expression enforces. Thou shalt make all destructors virtual
unless profiling reveals the need to remove a class's 'vtable'. At the other
end we have team specific patterns and behaviors. For example, one team may
adopt STL for all collection classes, and another may have an alternative
library, hence should not use STL. But we should recommend STL when writing
books for AW.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces
Jul 22 '05 #4
Pete Vidler wrote:
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.
Functions should have 1 to 5 activities. In higher level languages this
translates to 1 to 5 statements, but C++ requires a lot of rigging and
piping.
- Non-leaf classes should be abstract (have pure virtual methods), from
More Effective C++, Item 33.
The corpus of Addison Wesley [Longman]'s C++ and theory books form the
pinacle of known style. Try /Design Patterns/, /Large Scale C++ Software
Design/, and /Refactoring/.
- 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.
Also try /Exceptional C++/, by Herb Sutter.
- Header files should be self contained, from various sources.
The implication here is you can always add a new #include "thing.h", and it
takes care of itself. You never need to add another #include above it.
/Large Scale/ covers this in great detail.
- Destructors for base classes should be either virtual or protected.
Never heard of the "protected" one.
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?


These guidelines occupy a spectrum. At one end, we have requirements that
C++'s minimal expression enforces. Thou shalt make all destructors virtual
unless profiling reveals the need to remove a class's 'vtable'. At the other
end we have team specific patterns and behaviors. For example, one team may
adopt STL for all collection classes, and another may have an alternative
library, hence should not use STL. But we should recommend STL when writing
books for AW.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces
Jul 22 '05 #5
Daniel T. wrote:
[snip]
Check out these two books:
"Large-Scale C++ Software Design" by John Lakos
I've heard of this one, but isn't it seriously out of date? I've also
heard that he has some strange guidelines like not using namespaces?
"Object-Oriented Design Heuristics" by Arthur J. Riel
I'll look into it, thanks.
This site may also be helpful:
<http://www.chris-lott.org/resources/cstyle/>


Most of the links there appear to be documents detailing naming
conventions and recommending a given style for the placement of braces.
I'm looking for more along the lines of design guidelines like I posted
(there was one good page there though, thanks).

I don't really need the basic stuff (I know most of them), but I am
looking for more advanced guidelines (with justifications, like the one
about making virtual methods private).

Thanks,
-- Pete
Jul 22 '05 #6
Daniel T. wrote:
[snip]
Check out these two books:
"Large-Scale C++ Software Design" by John Lakos
I've heard of this one, but isn't it seriously out of date? I've also
heard that he has some strange guidelines like not using namespaces?
"Object-Oriented Design Heuristics" by Arthur J. Riel
I'll look into it, thanks.
This site may also be helpful:
<http://www.chris-lott.org/resources/cstyle/>


Most of the links there appear to be documents detailing naming
conventions and recommending a given style for the placement of braces.
I'm looking for more along the lines of design guidelines like I posted
(there was one good page there though, thanks).

I don't really need the basic stuff (I know most of them), but I am
looking for more advanced guidelines (with justifications, like the one
about making virtual methods private).

Thanks,
-- Pete
Jul 22 '05 #7

"Pete Vidler" <pv*****@mailbl ocks.com> wrote
I'm wondering if there is a compilation of C++ guidelines out there
anywhere.
http://search.barnesandnoble.com/boo...sbn=0521893089

It's basically an extension of what used to be Rogue Wave's guidelines. No
one will agree with every guideline, but they're mostly reasonable.
Here are some of the ones I've picked up so far (as examples):

- Functions should fit on one screen, from various sources.
That's really a side-effect of a few more fundamental principles, such as
"maximize cohesion" and "modularize where reasonable." A function that is
very large should raise flags, but there are rare instances where it's
entirely justified to have even extremely large functions (as anyone who's
ever used YACC will testify).
- Header files should be self contained, from various sources.


This one should be shredded or rephrased. Header files have dependencies
just like any other software component, and so can rarely be self-contained.

Claudio Puviani
Jul 22 '05 #8

"Pete Vidler" <pv*****@mailbl ocks.com> wrote
I'm wondering if there is a compilation of C++ guidelines out there
anywhere.
http://search.barnesandnoble.com/boo...sbn=0521893089

It's basically an extension of what used to be Rogue Wave's guidelines. No
one will agree with every guideline, but they're mostly reasonable.
Here are some of the ones I've picked up so far (as examples):

- Functions should fit on one screen, from various sources.
That's really a side-effect of a few more fundamental principles, such as
"maximize cohesion" and "modularize where reasonable." A function that is
very large should raise flags, but there are rare instances where it's
entirely justified to have even extremely large functions (as anyone who's
ever used YACC will testify).
- Header files should be self contained, from various sources.


This one should be shredded or rephrased. Header files have dependencies
just like any other software component, and so can rarely be self-contained.

Claudio Puviani
Jul 22 '05 #9
Claudio Puviani wrote:
[snip]
http://search.barnesandnoble.com/boo...sbn=0521893089

It's basically an extension of what used to be Rogue Wave's guidelines. No
one will agree with every guideline, but they're mostly reasonable.


Interesting.. but the summary says it deals with formatting, naming,
documentation, etc. I was looking for design guidelines along the lines
of those that I posted. Am I correct in assuming it doesn't cover such
issues?
- Functions should fit on one screen, from various sources.


That's really a side-effect of a few more fundamental principles, such as
"maximize cohesion" and "modularize where reasonable." A function that is
very large should raise flags, but there are rare instances where it's
entirely justified to have even extremely large functions (as anyone who's
ever used YACC will testify).


Yes that example was more basic than I really wanted. Ignore it, I'm far
more interested in guidelines similar to the others that I posted.
- Header files should be self contained, from various sources.


This one should be shredded or rephrased. Header files have dependencies
just like any other software component, and so can rarely be self-contained.

[snip]

Obviously if a header file is from a library then the library must be
linked to. I meant from a compiler point of view.

More specifically that it should forward declare or #include everything
it requires to compile. I'm fairly sure most people would understand
this from "self contained", but I suppose I should have been more precise.

-- Pete
Jul 22 '05 #10

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

Similar topics

22
2206
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?
6
45078
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...
61
669
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.
16
2395
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:
39
2194
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) {
3
2370
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,...
5
1194
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:
8
2287
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...
0
8680
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
8624
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
8336
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
8478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7164
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
6111
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
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
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
2
1485
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.