linux-embedded.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: "Leisner, Martin" <Martin.Leisner@xerox.com>
Cc: Bernd Petrovitsch <bernd@firmix.at>,
	Alexander Neundorf <neundorf@eit.uni-kl.de>,
	linux-embedded@vger.kernel.org
Subject: Re: prevalence of C++ in embedded linux?
Date: Wed, 30 Jul 2008 11:16:35 +0100	[thread overview]
Message-ID: <20080730101634.GA8992@shareable.org> (raw)
In-Reply-To: <556445368AFA1C438794ABDA8901891C092D3CF7@USA0300MS03.na.xerox.net>

Leisner, Martin wrote:
> I've found you can understand spaghetti C code with some effort -- its
> nearly impossible to understand spaghetti C++ code.  Much professional
> programming is "kitchen sink mentality" -- if there's a feature, use it.
> 
> I find it interesting K&R is about 200 pages, Stroustrup is 1000+ pages.
> What percentage of the 200 pages is understood by the average C
> programmer versus the 1000+ pages by the average C++ programmers?
> 
> I program by the quote by Einstein "Things should be as simple as
> possible, no simpler".
> 
> Much of the C++ code I've seen has more complicated implementation
> details than the problem being solved (I'm a believer in Halstead
> metrics, a lot of solutions I've seen in C++ would be much smaller in
> C).  Of course, that's the solutions in C++ I've seen...not all of
> them....

Ok, but most of what you say applies the same to "generic" programming
and not particularly to embedded.  I.e. if you agree with your points,
you won't use C++ much in general, and if you disagree and like C++ in
general, then why not use it for embedded as well.

> I think C++ lends itself to coming up with complicated solutions to
> simple problems...(of course really good C++ is simple and
> clever...but much C++ I see is poorly designed raw overcooked
> spaghetti).

If you think C lends itself to simple solutions, go read a Linux
kernel sometime :-)

> Also its very useful to have an understanding how the hardware works in
> systems where memory/time is an issue (and it almost always should be an
> issue).  I have a good understanding of what will happen in my C
> compiler 
> (a good algorithm in C runs rings around bad algorithms in assembler).
> [nowadays, instead of processor performance, you think about cache
> performance].  I doubt there's generally a good understand of time/space
> of C++ features in the compiler and standard library...]

Actually, the C++ standard library specification _defines_ time
requirements for many of its algorithms.  That's better than C - in
theory.  (Whether implementations follow the spec that far in practice
is a different question.

I can honestly say I've both read and written simple to understand,
and lousy and complex C code.  And the same with C++.

For some problems, C++ has expressed the solution far more clearly
than the equivalent C.  Most notably in a video game with lots of
characters and representations of physical objects, and in a GUI -
very object oriented systems by nature - fit a C++ expression very
well.

You can imagine in a video game, time/space performance is critical.
Some understanding of what goes on behind the scenes in C++ is very
helpful to manage performance.  I guess knowing C and machine code
helps one's understanding of what a C++ compiler produces :-)

Aside from time/space performance, another factor in many types of
embedded programming is time to deliver the product - or how good can
you make it in the fixed time available.  If C helps, go for it; if
C++ is familiar to you and gets you a better looking product in the
same time, though, it might be prefereable for some parts.  (Same for
choice of libraries, tools, etc.).  That really depends what kind of
device you're making.

-- Jamie

  parent reply	other threads:[~2008-07-30 10:16 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-28 15:43 prevalence of C++ in embedded linux? Robert P. J. Day
2008-07-28 15:54 ` Chris
2008-07-28 15:55 ` Jamie Lokier
2008-07-28 16:15 ` Domenico Andreoli
2008-07-28 17:30 ` Matthias Kaehlcke
2008-07-28 21:47 ` Ben Nizette
2008-07-29  5:42   ` Roberto A. Foglietta
2008-08-02  4:14   ` Ben Nizette
2008-07-29  7:40 ` Marco Stornelli
2008-07-29  7:51   ` Alexander Neundorf
2008-07-29  8:20     ` Bernd Petrovitsch
2008-07-29  8:35       ` Marco Stornelli
2008-07-29  8:58       ` Alexander Neundorf
2008-07-29  9:47         ` Bernd Petrovitsch
2008-07-29 20:08           ` Leisner, Martin
2008-07-30  4:46             ` Bart Van Assche
2008-07-30 10:25               ` Jamie Lokier
2008-07-30 11:04                 ` Bart Van Assche
2008-07-30 11:58                   ` Haavard Skinnemoen
2008-07-30 12:38                     ` Jamie Lokier
2008-07-30 13:01                       ` Haavard Skinnemoen
2008-07-30 12:48                   ` Bernd Petrovitsch
2008-07-30 13:07                     ` Jamie Lokier
2008-07-30 13:58                       ` Bernd Petrovitsch
2008-07-30 10:16             ` Jamie Lokier [this message]
2008-07-29  8:50   ` Bart Van Assche
2008-07-29 11:39     ` Richard Danter

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=20080730101634.GA8992@shareable.org \
    --to=jamie@shareable.org \
    --cc=Martin.Leisner@xerox.com \
    --cc=bernd@firmix.at \
    --cc=linux-embedded@vger.kernel.org \
    --cc=neundorf@eit.uni-kl.de \
    /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).