9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Aharon Robbins <arnold@skeeve.com>
To: 9fans@9fans.net
Subject: Re: [9fans] c++
Date: Mon, 19 Nov 2012 22:02:01 +0200	[thread overview]
Message-ID: <201211192002.qAJK21GB003157@skeeve.com> (raw)
In-Reply-To: <7a746291161fe83e1df0401af21f6ce4@quintile.net>

Hello Steve, 9fans.

> I need to learn c++ for work - people have strong opinions on
> languages I know, and not everyone likes c++ but its a requirment for me.
>
> I really want to develop a good sence of c++ style, I learnt C at the feet of
> K&R and then the plan9 sourcecode so I learnt how to write clean elegant code
> (I think :-). The problem I am finding is there are many c++ styles and I have
> yet to find a clean and elegant one.
>
> anyone sugest a project that I could look at that contains well written code?
> failing that is there a book that teaches good style?

This letter may end up being a bit long, and will be contrary to the popular
wisdom on 9fans. So be it.

I have over 30 years of C and Unix experience and ~13 years of C++ experience.
For whatever that's worth.

I will try to offer practical advice on the assumption that you want to
keep your job and therefore you want to learn C++ and learn it well.

First, realize that C++ is a MUCH bigger language than C. There's more to
C++ style than just naming conventions.  You should work to understand
the language features, first, and in particular understand that they
often interact in somewhat strange ways.

For learning the language, you should probably go with the C++ Primer
by Lippman, Lajoie and Moo. I see that a new edition just came out:
http://www.amazon.com/Primer-5th-Stanley-B-Lippman/dp/0321714113/ref=sr_1_1?s=books&ie=UTF8&qid=1353353296&sr=1-1&keywords=c%2B%2B+primer

Write some code, get a feel for things.  Work your way up slowly, since
there's a lot to learn.

To understand the intricacies of C++, you can't do better than Scott Myers
"Effective C++", "More Effective C++" and "Effective STL":

http://www.amazon.com/Effective-Specific-Improve-Programs-Designs/dp/0321334876/ref=sr_1_1?s=books&ie=UTF8&qid=1353353626&sr=1-1&keywords=Scott+Myers+C%2B%2B

http://www.amazon.com/More-Effective-Improve-Programs-Designs/dp/020163371X/ref=sr_1_4?s=books&ie=UTF8&qid=1353353626&sr=1-4&keywords=Scott+Myers+C%2B%2B

http://www.amazon.com/Effective-STL-Specific-Standard-Template/dp/0201749629/ref=sr_1_3?s=books&ie=UTF8&qid=1353353626&sr=1-3&keywords=Scott+Myers+C%2B%2B

In addition, a book that I found really helpful was Stanley Lippman's
"Inside the C++ Object Model": http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545/ref=sr_1_1?s=books&ie=UTF8&qid=1353353699&sr=1-1&keywords=C%2B%2B+object+model

Lippman worked with Stroustrup on cfront at Bell Labs, he's been involved
since the beginning. Also, he's a great writer.

Despite the scorn expressed here for Design Patterns, they have value.
The canonical reference is the book by the Gang of Four: http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?s=books&ie=UTF8&qid=1353353825&sr=1-1&keywords=Design+Patterns

Not all the patterns see the same amount of use in C++, but a few are
critical for understanding and working with everyday C++: Factory, Singleton
and Visitor come to mind, there are some others.  In any case, the book is
worth having as a reference.

Java and C# provide large "frameworks" out of the box (vendor supplied),
making programming in them a much more "pick the parts and stich them
together" practice. C++ does not have this, although the Qt framework
goes a long way towards filling the gap.  The Qt classes are well designed
and make for clean code that also avoids your having to reinvent certain
wheels yet again.

C++ is far from a perfect language.  It tries to be many things to many people.
Using it well requires discipline on the part of the programmer, as opposed
to newer languages where the compiler imposes much of the discipline. The
Myers books will help with that.

And it's possible to do awful things with it. I think template metaprogramming
is the work of the devil and regular programmers shouldn't even consider
going anywhere near it.

And yes, there's a lot of miserable C++ out there. There's also a lot
of miserable C and shell and even awk code out there. This just proves
that there are lots of crappy programmers.

However, having worked on a project containing over 4 Million lines of C++
code, I can say that there are things you can do with object oriented
design and code in C++ that you simply could not do were you trying to
do them in C.

Some of the cleanest and most elegant code I have ever seen, as well as
some of the best code I have ever written, was in C++.

There is much, Much, MUCH more that could be said, for and against C++.
I'm probably aware of most of it, so don't bother flaming me.  I do think
that C++ is worth learning, knowing, and using well.  (I think that Walter
Bright's D is an even better language, but that's another story.)

So Steve, look upon this as an adventure and keep an open mind. You may find
that you are doing new, different, and maybe even enjoyable things as
your horizons open up.

I think the books I've listed will give you a good start if you're serious
about working in C++. There are others I can name also.  Feel free to
ping me (probably best off list - remove the 9fans from the subject header
so that it doesn't get sent to the wrong mailbox).

Thanks,

Arnold Robbins



  parent reply	other threads:[~2012-11-19 20:02 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-19  9:59 Steve Simon
2012-11-19 10:10 ` Mathieu Lonjaret
2012-11-19 11:31   ` Aram Hăvărneanu
2012-11-19 10:45 ` iainws
2012-11-19 12:17 ` Balwinder S Dheeman
2012-11-19 12:46   ` Aram Hăvărneanu
2012-11-19 12:55     ` hiro
2012-11-19 13:22   ` cinap_lenrek
2012-11-19 14:58     ` tlaronde
2012-11-19 15:17       ` Bence Fábián
2012-11-19 14:25 ` Robert Raschke
2012-11-19 14:56 ` Calvin Morrison
2012-11-19 14:09   ` cinap_lenrek
2012-11-19 15:38     ` Bence Fábián
2012-11-19 16:45       ` Jeff Sickel
2012-11-19 15:10   ` Kurt H Maier
2012-11-22 14:10     ` David Leimbach
2012-11-22 14:13       ` David Leimbach
2012-11-19 16:21 ` Andrés Domínguez
2012-11-19 20:02 ` Aharon Robbins [this message]
2012-11-20  2:24 ` Taj Khattra
2012-11-20  3:47   ` Bruce Ellis
2012-11-19 22:48 steve
2012-11-20  1:37 ` Jeff Sickel
2012-11-20  2:08   ` Matthew Veety
2012-11-20 10:12     ` Steve Simon
2012-11-22  9:54       ` Balwinder S Dheeman
2012-11-22 10:07         ` lucio
2012-11-22 10:21           ` Nemo
2012-11-22 15:37             ` lucio
2012-11-22 16:19               ` Nemo
2012-11-22 16:31                 ` lucio
2012-11-25  6:09                   ` David Leimbach
2012-11-22 10:39           ` Charles Forsyth
2012-11-22 10:18         ` Lluís Batlle i Rossell
2012-11-22 11:34         ` hiro
2012-11-22 11:57           ` Charles Forsyth
2012-11-22 14:25             ` Dan Cross
2012-11-22 13:13           ` Hugo Rivera
2012-11-22 13:48             ` hiro
2012-11-22 14:22               ` erik quanstrom
2012-11-22 14:38                 ` Dan Cross
2012-11-22 14:47                   ` erik quanstrom
2012-11-22 14:54                     ` Hugo Rivera
2012-11-22 15:47                       ` tlaronde
2012-11-22 16:00                         ` erik quanstrom
2012-11-22 16:11                           ` Bakul Shah
2012-11-22 16:15                           ` lucio
2012-11-22 16:31                             ` erik quanstrom
2012-11-22 17:30                               ` lucio
2012-11-22 16:18                           ` tlaronde
2012-11-22 16:06                       ` lucio
2012-11-22 16:07                         ` erik quanstrom
2012-11-22 16:12                         ` Hugo Rivera
2012-11-22 16:25                           ` lucio
2012-11-22 16:51                         ` Bakul Shah
2012-11-22 17:16                           ` Charles Forsyth
2012-11-22 17:39                           ` lucio
2012-11-22 17:51                             ` Paul Lalonde
2012-11-22 17:53                               ` hiro
2012-11-22 18:13                                 ` lucio
2012-11-22 18:00                               ` lucio
2012-12-03 13:43                       ` Ethan Grammatikidis
2012-12-03 14:13                         ` Charles Forsyth
2012-12-03 14:58                           ` Kurt H Maier
2012-12-03 15:21                             ` Charles Forsyth
2012-12-03 15:29                               ` Kurt H Maier
2012-12-04 21:36                                 ` hiro
2012-11-22 16:58                     ` Dan Cross
2012-11-22 22:25                       ` erik quanstrom
2012-11-22 14:54                   ` dexen deVries
2012-11-22 17:04                     ` Dan Cross
2012-11-22 17:31                       ` hiro
2012-11-22 17:45                         ` Dan Cross
2012-11-22 17:46                         ` lucio
2012-11-22 20:17                           ` Matthew Veety
2012-11-22 17:42                       ` lucio
2012-11-22 17:44                         ` hiro
2012-11-22 17:47                           ` lucio
2012-11-22 19:55                             ` Kurt H Maier
2012-11-23  3:31                               ` lucio
2012-11-23  3:56                                 ` Kurt H Maier
2012-11-22 17:50                         ` Dan Cross
2012-11-22 17:59                           ` lucio
2012-11-22 18:02                             ` Charles Forsyth
2012-11-22 18:12                               ` lucio
2012-11-22 19:15                                 ` Richard Miller
2012-11-22 21:48                                 ` Bakul Shah
2012-11-22 21:34                               ` Bakul Shah
2012-11-22 16:15                   ` Christopher Nielsen
2012-11-22 17:10                   ` Kurt H Maier
2012-11-22 17:18                     ` Charles Forsyth
2012-11-22 17:22                       ` tlaronde
2012-11-22 17:27                         ` Bakul Shah
2012-11-22 17:45                     ` Dan Cross
2012-11-22 19:55                       ` Kurt H Maier
2012-11-23  9:42                     ` Balwinder S Dheeman
2012-11-22 17:58                   ` lucio
2012-11-22 16:32                 ` Richard Miller
2012-11-22 17:39                   ` hiro
2012-11-22 20:14                   ` Matthew Veety
2012-11-22 15:50           ` lucio
2012-11-22 14:54         ` Bakul Shah
2012-11-22 17:40       ` Pavel Klinkovsky
2012-11-22 18:11         ` tlaronde
2012-11-20 19:58     ` Wes Kussmaul
2012-11-20 20:07       ` tlaronde
2012-11-20 20:17         ` Wes Kussmaul
2012-11-22 12:58         ` Pedro Lamarão
2012-11-20 19:05 ` Bakul Shah
2012-11-20 20:31   ` Skip Tavakkolian
2012-11-20 20:09 ` dexen deVries
2012-11-22 22:32 [9fans] C++ Winston Kodogo
2012-11-23  3:04 ` Comeau At9Fans
2012-11-23  9:47 ` Gorka Guardiola
2012-11-23 10:21   ` dexen deVries
2012-11-23 13:28     ` Pedro Lamarão
2012-11-23 14:02       ` lucio
2012-11-25  6:03         ` David Leimbach
2012-11-27 17:09     ` Eugene Gorodinsky
2012-11-27 19:57       ` David Leimbach
2012-11-27 20:15         ` Kurt H Maier
2012-12-03 10:02 ` faif
2012-11-24  1:45 Winston Kodogo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201211192002.qAJK21GB003157@skeeve.com \
    --to=arnold@skeeve.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).