The plus plus
Andy Green
andy at warmcat.com
Fri Nov 10 14:10:06 UTC 2006
Alan Cox wrote:
Hi Alan -
>> guy. Somehow the kernel and Gnome reached a local optimum at the C
>> hacker level and that is where they stay.
>
> The kernel uses C for good sound reasons - C++ is slower, harder to
Well C++ can generate pure C with no overhead, in the degenerate case
you are not using the C++ features. So it is not "slower" without some
qualification.
About ten years ago when I was struggling to understand what the C++
deal was about, I realized after it crashed in on me what the benefits
were (the moment I understood how virtual functions worked in the memory
footprint) that I had been blindly reaching for some of the same
principles in my C for some time, eg, binding related data into structs,
composing structs with other more primitive structs at the start, making
the equivalent of constructor functions to prep a struct, using function
pointers and so on.
When I look at bits of the kernel code I need to understand to write my
drivers, I strongly recognize the same aping of OO principles in a
pre-OO language. The shared mindmeld that produced such code is ripe to
move on IMO!
Since for the kernel there is an attempt at implementing the OO action
in C by hand at the moment, it is even harder to flat out say that C++
is "slower" without qualification, since it by delivering implicitly
what is done explicitly now it offsets at least some of the overhead.
> debug and the tools suck in relative terms. You can use a subset of C++
> to write OS core code, that has been demonstrated, but C++ is not
> beneficial in that space. Much of that is down to the fact C++ is a
> dreadfully designed language rather than going agains the basic argument
> about using the right tools for the right job.
Well I think a lot of your skills, experience and opinion, in fact only
illness kept me from the last Linux World where I was anxious to hear
your security talk. But you only need to buy into a pretty thin subset
of C++ to get the bulk of the benefit IMO. You don't need any of that
">>" operator trickery or to use string.
> From the kernel viewpoint C++ is the badly designed swiss army knife
> bought in a cheap junk shop - it has lots of interesting ways to cut
> yourself but none of the tools actually help you do anything useful.
For sure there is a lot that a wise person avoids, particularly in the
libs and templates, but the core class stuff only delivers wins IMO.
Just use it as a better C compiler that natively supports the
abstractions you already insisted to use, you don't have to buy into
anything else.
The original context was the relative success of a C++-based GUI and a
C-based one. Concepts like pure virtual classes give really strong
architectural structure to the implementation, a newbie can glance at
the class definitions and keenly understand the whole deal in a
hierarchical, complete and contained way. Deep structure is readably
captured by the class definitions and derivations.
Before I blew out of being a Windows Trained Monkey I wrote a lot of MFC
for UI, there is much to like in having UI elements integrated into an
OO language, this experience gives me the assurance to claim that C++
makes a major difference in the consistency and architecture you can
hope to succeed with.
-Andy
More information about the users
mailing list