9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Bakul Shah <bakul@bitblocks.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] c++
Date: Tue, 20 Nov 2012 11:05:37 -0800	[thread overview]
Message-ID: <68EB7559-7A38-455B-9A86-98ABB4CC2521@bitblocks.com> (raw)
In-Reply-To: <17553477-B35F-468B-AD14-FD38068D7684@quintile.net>

On Nov 19, 2012, at 2:48 PM, steve wrote:

> so far i have written a couple of hundred lines of c++, but for me the problem
> i see is how to develop a sense of c++ style.  I want to write good code, but I
> don't even know what good c++ code looks like!

Look at something like OpenSceneGraph. Looks to be pretty
decent code.  Look at Russ's RE2 code. Look at code for varius
data structures (but *not* the boost library or templates).

But I think the only way to develop good intuition is to write
code.  Lots of it!

IMHO, for a competent C programmer it is not hard to pick up
C++ and continue using a spare style.  Basically use C++
features only as needed.  Data structures map fairly naturally
to objects (and hence classes) -- but just build in what you
need.  Rather than write your own implementation of linked
list, doubly linked list, priority queue etc. it may make
sense to use relevant templates. If you have more than one
related class, it may make sense to factor out the common
interface in a separate base class. If it is an interface,
functions will either be virtual or depend on virtual
functions. Deep hierarchies are another thing needing very
strong justification -- they are worse than a chain of #define
macros.

It is probably a good idea to get in the habit of writing test
classes right at the outset. Often you can write the test
class exercising the interface of a class even before you
implement this interface!  This forces you to look at the API
from a user perspective early on and you are less afraid to
experiment as you can quickly test. If your program gets used
a lot, over time you will end up wanting to replace classes
for better performance or changes in usage.

I used the "gang of four" book (desing patterns) in mid 90s
and experimented with it but I haven't even opened the book in
last decade. There are lots of useful patterns in there but as
always one must justify use of every new pattern. Some
patterns are powerful but make the code very hard to read.
A few months ago I rewrote one such program on a challenge. It
was so hard to follow I ended up just looking at its input and
output and reimplementing from scratch.

And profile your code! One should avoid optimizations that 
makes the code uglier but keeping an eye on performance helps
find stupid bugs and hotspots early on when things are not so
complicated.

So that is a long way of saying just dive in and trust your
judegment!

> 
> i will press on with it, and read the pointers that have been suggested.
> 
> thanks again.
> 
> -Steve
> 
> ps i am studiously not reading anything about go in case it distracts me... :-)

Go too considered harmful?




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

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2012-11-20 20:31   ` Skip Tavakkolian
2012-11-20 20:09 ` dexen deVries
  -- strict thread matches above, loose matches on Subject: below --
2012-11-24  1:45 [9fans] C++ Winston Kodogo
2012-11-22 22:32 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-19  9:59 [9fans] c++ 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
2012-11-20  2:24 ` Taj Khattra
2012-11-20  3:47   ` Bruce Ellis

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=68EB7559-7A38-455B-9A86-98ABB4CC2521@bitblocks.com \
    --to=bakul@bitblocks.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).