Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ Guidelines

Reply
Thread Tools

C++ Guidelines

 
 
Pete Vidler
Guest
Posts: n/a
 
      04-10-2004
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
 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      04-10-2004
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


 
Reply With Quote
 
 
 
 
Daniel T.
Guest
Posts: n/a
 
      04-10-2004
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.
>
> - 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/>
 
Reply With Quote
 
Pete Vidler
Guest
Posts: n/a
 
      04-10-2004
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
 
Reply With Quote
 
Claudio Puviani
Guest
Posts: n/a
 
      04-10-2004

"Pete Vidler" <> 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


 
Reply With Quote
 
Pete Vidler
Guest
Posts: n/a
 
      04-10-2004
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
 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      04-10-2004
On Sat, 10 Apr 2004 16:16:23 +0100 in comp.lang.c++, Pete Vidler
<> wrote,
>> 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


Well, arguing over the placement of braces has less potential for harm
than many of the design guidelines I have seen.

 
Reply With Quote
 
Pete Vidler
Guest
Posts: n/a
 
      04-10-2004
David Harmon wrote:
[snip]
> Well, arguing over the placement of braces has less potential for harm
> than many of the design guidelines I have seen.


Yes, but there's no potential for learning anything with
brace-placement. You can already see the possibilities.

-- Pete
 
Reply With Quote
 
Daniel T.
Guest
Posts: n/a
 
      04-10-2004
Pete Vidler <> wrote:

> 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).


Try the articles at this site:
<http://tinyurl.com/2tt4h >
 
Reply With Quote
 
Steven T. Hatton
Guest
Posts: n/a
 
      04-10-2004
Pete Vidler wrote:

> David Harmon wrote:
> [snip]
>> Well, arguing over the placement of braces has less potential for harm
>> than many of the design guidelines I have seen.

>
> Yes, but there's no potential for learning anything with
> brace-placement. You can already see the possibilities.
>
> -- Pete

This looks like food for thought. I'm not endorsing, just passing it on:
http://www.possibility.com/Cpp/CppCo...ndard.html#cuh

You may already be aware of this. It's general, but certainly has a link or
five that will be relevant:
http://www.fz-juelich.de/zam/cxx/extmain.html
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case Gallery rules and Guidelines Silverstrand Case Modding 0 06-20-2005 11:38 PM
Portable Coding Guidelines? Roger VHDL 0 12-17-2004 07:33 PM
Code Guidelines JIT ASP .Net 2 11-02-2004 06:57 AM
Is WPS compatible with Smart client as defined in WISPr guidelines nsmurthy Wireless Networking 0 08-13-2004 10:23 AM
VHDL Coding Guidelines Francisco Camarero VHDL 1 07-08-2003 08:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57