From: Avi Kivity <avi@argo.co.il>
To: Willy Tarreau <willy@w.ods.org>
Cc: David Schwartz <davids@webmaster.com>,
"Linux-Kernel@Vger. Kernel. Org" <linux-kernel@vger.kernel.org>
Subject: Re: Compiling C++ modules
Date: Tue, 02 May 2006 17:41:15 +0300 [thread overview]
Message-ID: <44576F8B.7000206@argo.co.il> (raw)
In-Reply-To: <20060502132139.GA16647@w.ods.org>
Willy Tarreau wrote:
> It would be the exact same problem I discribed above. If nobody understand
> what it does, or if people need some deep thoughts to guess its behaviour,
> the result will be negative. Currently, everyone can read the kernel code.
> I was a terrible looser in C 11 years ago when I first looked at it, but I
> did not need specific knowledge of implicit things that the kernel does to
> understand what the code did, and to propose patches.
>
>
11 years ago the kernel was _way_ simpler.
These days, you need to know that you can't call schedule() (or any
function which may sleep -- why is that not implicit) within spin locks.
You need to understand per-cpu variables, initcalls, rcu, memory
barriers, reference counting, and lots of other "infrastructure" details
that are engraved into your brain but not accessible to a newbie. Most
of these (except perhaps reference counting) cannot be understood from
looking at the code.
C++ allows you to add even more infrastructure, by providing support for
patterns that can't be done in C. So yes, that adds more to the
vocabulary you have to learn by heart but once you're over that the code
is _more_ readable, more maintainable.
> Right now, lots of newbies review the code and find bugs. If you write it
> in a language such as above, it will quickly end up like the BSD kernels,
> with a small very competent core team and lots of newbies around them.
>
>
C++ knowledge is now fairly widespread, I believe.
> I don't know, what I can say is that they were people who regularly discuss
> the kernel semantics on other threads. That's what matters. Those people are
> good at finding kernel bugs and proposing interesting algorithms, it's a shame
> that they had to discuss langage semantics on 5 lines of code !
>
I'm sorry to have wasted their time. But surely you understand these
things once and then move on? Like when someone proposes a new function
to replace repeated code, there's argument about it's name, coding
style, and hopefully about the content. The people replace the
open-coded sequence with the new function.
It's the same here at a slightly higher level. You argue what s spinlock
guard should look like, whether it's optimal or not, and then you can
use it where applicable and avoid those gotos or code duplications for
error cases.
>
> I seems like pro-C++ people constantly tell the other ones "look, C++ can
> code for you so that you won't have to worry about boring parts. Of coure,
> if you need to know, you're still able to write is the old way". Since we
> always want to know, I guess we'd use the C++ compiler (the slow one), with
> pure-C code borrowing nothing from the C++ language. That would only be a
> pure loss.
>
It's not "if you need to know", it's "if you want to break the rules".
For example, the spinlock guard thingie allows you to say, "please
spin_unlock this spinlock for me, whichever way I return from this
function". There is no knowledge taken away, you know exactly what it
will do and when; only the code is made clearer.
But if you want the function to lock but not unlock, or do the
atomic_dec_and_lock() thing, or do lock reordering to avoid ABBA
deadlocks, or whatever, the primitives are still there.
These constructs allow you to make simple things simple (and automatic)
but don't take away the complex things.
(example, for context:
{
spinlock_guard guard(some_lock);
if (x)
return -ESOMETHING;
blah();
return 0;
}
there is nothing implicit once you know spinlock_guard)
>> No, they want not to repeat code and code patterns. It's the same
>> motivation that lead to the invention of functions:
>>
>> - functions allow you to reuse code instead of open-coding common
>> sequences
>> - constructors/destructors allow you to reuse the do/undo (lock/unlock,
>> etc.) pattern without writing it in full every time
>> - templates allow you to reuse code even when the data types change
>> (like the preprocessor but not limited to linked lists)
>> - virtual functions allow you to dispatch a function based on the
>> object's type, without writing the boilerplate casting
>> - exceptions allow you to do the detect error/undo partial
>> modifications/propagate error thing without blowing up the code by a
>> factor of five
>>
>> It's just shorthand: but shorthand allows you to see what the code is
>> doing instead of how it handles all the standard problems that occur
>> again and again in programming.
>>
>
> I'm still not convinced. Every time I came across C++ code, it was an immense
> unreadable crap (indentation, cAmEl case, "funny" operators which you have to
> stop at because you need a few seconds of thought before confusing them with
> others, etc...). Code that cannot be read at 3am. If you want a good example
> of this, download and read p7zip. It does lots of magic^Wimplicit things which
> quickly got me lost. I agree, I'm not a C++ developper. But many language are
> slightly understandable to non-fellows, and this one looks really nasty.
>
I agree - I've seen it done many times. C++ has the potential for a lot
of nastiness, and what is more, it seems to bring out the worst in
people. We would definitely need an Al Viro for C++ if the kernel were
to be ported.
I've yet to find a language that combines low level access, efficiency,
cleanliness, and expressive power.
> You told us examples of programs you have written. If this is true, I have
> a lot of respect for this, because it still seems impossible to me. I
> understand they were closed source, but if you come across open source
> kernel code that is readable by newbies, I think many people would be
> interested to get a clue.
>
I posted an example of do_sendfile() as it might be incrementally converted.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
next prev parent reply other threads:[~2006-05-02 14:41 UTC|newest]
Thread overview: 200+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-24 19:16 Compiling C++ modules Gary Poppitz
2006-04-24 19:27 ` Greg KH
2006-04-24 20:02 ` C++ pushback Gary Poppitz
2006-04-24 20:15 ` Christoph Hellwig
2006-04-24 20:16 ` Greg KH
2006-04-24 20:18 ` Martin Mares
2006-04-24 21:36 ` Jeff V. Merkey
2006-04-24 21:28 ` J.A. Magallon
2006-04-24 21:43 ` Harald Arnesen
2006-04-24 21:52 ` Alan Cox
2006-04-24 22:16 ` J.A. Magallon
2006-04-25 0:05 ` Harald Arnesen
2006-04-25 0:46 ` Diego Calleja
2006-04-25 9:12 ` Harald Arnesen
2006-04-25 1:30 ` linux-os (Dick Johnson)
2006-04-25 2:58 ` marty fouts
2006-04-27 22:55 ` Bill Davidsen
2006-05-02 15:58 ` Randy.Dunlap
2006-05-02 20:36 ` David Schwartz
2006-04-25 8:15 ` Xavier Bestel
2006-04-25 8:42 ` Avi Kivity
2006-04-25 8:52 ` Martin Mares
2006-04-25 9:00 ` Avi Kivity
2006-04-25 9:05 ` Martin Mares
2006-04-25 9:13 ` Avi Kivity
2006-04-25 9:22 ` Xavier Bestel
2006-04-25 20:20 ` J.A. Magallon
2006-04-25 20:31 ` Barry Kelly
2006-04-25 9:09 ` Nikita Danilov
2006-04-25 20:10 ` J.A. Magallon
2006-04-25 18:02 ` Geert Uytterhoeven
2006-04-27 9:09 ` Alexander E. Patrakov
2006-04-24 22:39 ` Willy Tarreau
2006-04-24 22:57 ` Jeff V. Merkey
2006-04-24 23:02 ` David Schwartz
2006-04-25 8:55 ` Martin Mares
2006-04-25 8:59 ` Jan Engelhardt
2006-04-25 14:37 ` David Schwartz
2006-04-25 19:50 ` Martin Mares
2006-04-26 2:33 ` David Schwartz
2006-04-26 3:42 ` Matthew Frost
2006-04-26 19:25 ` David Schwartz
2006-04-26 20:01 ` Jan-Benedict Glaw
2006-04-26 20:09 ` Linus Torvalds
2006-04-26 20:19 ` Al Viro
2006-04-26 21:37 ` Sam Ravnborg
2006-04-28 9:23 ` Avi Kivity
2006-04-28 12:00 ` linux-os (Dick Johnson)
2006-04-28 12:46 ` Jan-Benedict Glaw
2006-04-26 20:25 ` Jan-Benedict Glaw
2006-04-26 20:43 ` David Schwartz
2006-04-26 23:00 ` Roman Kononov
2006-04-27 0:38 ` Kyle Moffett
2006-04-27 2:05 ` Roman Kononov
2006-04-27 3:37 ` Kyle Moffett
2006-04-27 5:37 ` Roman Kononov
2006-04-27 13:58 ` Michael Buesch
2006-04-27 14:22 ` linux-os (Dick Johnson)
2006-04-27 8:07 ` Avi Kivity
2006-04-27 13:55 ` Denis Vlasenko
2006-04-27 14:27 ` Avi Kivity
2006-04-27 14:56 ` Denis Vlasenko
2006-04-27 15:54 ` Bob Copeland
2006-04-27 16:03 ` Avi Kivity
2006-04-27 15:00 ` Martin Mares
2006-04-27 15:31 ` Avi Kivity
2006-04-27 15:38 ` Martin Mares
2006-04-28 8:16 ` Avi Kivity
2006-04-28 8:30 ` Avi Kivity
2006-04-28 15:47 ` Jan Engelhardt
2006-04-28 15:51 ` Jan Engelhardt
2006-04-28 16:51 ` Avi Kivity
2006-04-27 14:50 ` Sam Ravnborg
2006-04-27 8:50 ` Martin Mares
2006-04-27 3:57 ` Willy Tarreau
2006-04-27 5:53 ` Roman Kononov
2006-04-27 7:55 ` Jan-Benedict Glaw
2006-04-27 17:20 ` C++ pushback (when does this religious thread end?) Leonard Peterson
2006-04-30 17:48 ` C++ pushback Jan Harkes
2006-04-30 20:55 ` David Schwartz
2006-04-26 20:05 ` linux-os (Dick Johnson)
2006-04-26 20:09 ` Xavier Bestel
2006-04-26 20:44 ` Randy.Dunlap
2006-05-02 20:09 ` C++ pushback + sparse Randy.Dunlap
2006-04-27 7:49 ` C++ pushback Jiri Kosina
2006-04-26 21:05 ` Martin Mares
2006-04-25 7:33 ` Avi Kivity
2006-04-25 7:47 ` Nick Piggin
2006-05-13 16:21 ` Esben Nielsen
2006-04-24 20:36 ` Thiago Galesi
2006-04-24 21:38 ` Kurt Wall
2006-04-27 16:17 ` Roman Kononov
2006-04-27 21:59 ` Grant Coady
2006-04-27 22:09 ` Bill Davidsen
2006-04-27 23:19 ` Jan Knutar
2006-04-24 19:30 ` Compiling C++ modules Al Viro
2006-04-24 19:40 ` linux-os (Dick Johnson)
2006-04-24 20:54 ` Geert Uytterhoeven
2006-04-24 19:42 ` Alexey Dobriyan
2006-04-24 20:30 ` Daniel Barkalow
2006-04-24 20:35 ` C++ is in US [Re: Compiling C++ modules] Jiri Slaby
2006-04-24 20:45 ` Compiling C++ modules Alan Cox
2006-04-24 21:03 ` Avi Kivity
2006-04-24 21:23 ` Joshua Hudson
2006-04-24 21:29 ` Kyle Moffett
2006-04-24 21:50 ` marty fouts
2006-04-24 22:09 ` Martin Mares
2006-04-24 22:30 ` Willy Tarreau
2006-04-24 22:32 ` Joshua Hudson
2006-04-24 22:45 ` marty fouts
2006-04-25 15:32 ` Michael Buesch
2006-04-25 7:08 ` Avi Kivity
2006-04-25 10:23 ` James Courtier-Dutton
2006-04-25 15:59 ` Kyle Moffett
2006-04-25 16:46 ` Avi Kivity
2006-04-25 17:10 ` Dmitry Torokhov
2006-04-25 17:19 ` Avi Kivity
2006-04-25 17:28 ` Dmitry Torokhov
2006-04-25 17:53 ` Avi Kivity
2006-04-25 18:04 ` Dmitry Torokhov
2006-04-25 18:08 ` Valdis.Kletnieks
2006-04-25 18:26 ` Avi Kivity
2006-04-25 18:38 ` Avi Kivity
2006-04-25 18:52 ` Michael Poole
2006-04-25 19:13 ` Avi Kivity
2006-04-27 15:10 ` Denis Vlasenko
2006-04-27 20:15 ` Willy Tarreau
2006-04-27 21:08 ` Davi Arnaut
2006-04-28 9:33 ` Avi Kivity
2006-04-28 10:03 ` Avi Kivity
2006-04-28 11:27 ` Sergei Organov
2006-04-28 11:03 ` Martin Mares
2006-04-28 11:30 ` Avi Kivity
2006-04-28 15:56 ` Jan Engelhardt
2006-04-28 17:02 ` Avi Kivity
2006-04-28 17:38 ` linux-os (Dick Johnson)
2006-04-29 2:50 ` Christer Weinigel
2006-05-01 17:46 ` Dave Neuer
2006-05-01 20:21 ` Jan Engelhardt
2006-05-01 23:53 ` David Schwartz
2006-05-02 5:12 ` Willy Tarreau
2006-05-02 10:32 ` Avi Kivity
2006-05-02 11:15 ` Martin Mares
2006-05-02 11:26 ` Avi Kivity
2006-05-02 11:40 ` linux-os (Dick Johnson)
2006-05-02 12:42 ` David Woodhouse
2006-05-02 16:27 ` Christer Weinigel
2006-05-02 12:48 ` Martin Mares
2006-05-02 13:52 ` Avi Kivity
2006-05-02 14:13 ` Al Viro
2006-05-02 14:54 ` Avi Kivity
2006-05-02 16:16 ` Brian Beattie
2006-05-02 16:21 ` Avi Kivity
2006-05-02 13:21 ` Willy Tarreau
2006-05-02 14:41 ` Avi Kivity [this message]
2006-05-02 22:25 ` Diego Calleja
2006-05-02 13:34 ` Al Viro
2006-05-02 14:02 ` Avi Kivity
2006-05-02 14:34 ` Al Viro
2006-05-02 15:04 ` Avi Kivity
2006-05-02 15:15 ` Al Viro
2006-05-02 15:19 ` Avi Kivity
2006-05-02 15:27 ` Kyle Moffett
2006-05-02 15:30 ` Avi Kivity
2006-05-02 15:28 ` Al Viro
2006-05-02 15:51 ` Avi Kivity
2006-05-02 15:24 ` Kyle Moffett
2006-05-03 13:13 ` Mark Lord
2006-05-03 20:51 ` David Schwartz
2006-04-30 21:15 ` Eric W. Biederman
2006-04-25 17:54 ` linux-os (Dick Johnson)
2006-04-26 8:30 ` Jan Engelhardt
2006-04-26 11:36 ` linux-os (Dick Johnson)
2006-04-25 19:22 ` Kyle Moffett
2006-04-25 19:54 ` Michael Buesch
2006-04-25 20:24 ` Avi Kivity
2006-04-25 20:11 ` Bongani Hlope
2006-04-25 20:26 ` Avi Kivity
2006-04-25 21:02 ` Valdis.Kletnieks
2006-04-25 21:15 ` Avi Kivity
[not found] ` <71a0d6ff0604251646g4fc90b3dr30a03b8606360e7f@mail.gmail.com>
2006-04-26 4:39 ` Avi Kivity
2006-04-25 17:55 ` Geert Uytterhoeven
2006-04-24 21:58 ` Alan Cox
2006-04-25 7:20 ` Avi Kivity
2006-04-25 9:06 ` Matt Keenan
2006-04-25 20:29 ` Bongani Hlope
2006-04-25 20:37 ` Avi Kivity
2006-04-25 21:08 ` Bongani Hlope
2006-04-25 4:17 ` Martin J. Bligh
2006-04-25 5:30 ` Avi Kivity
2006-04-25 8:58 ` Sam Ravnborg
2006-04-25 7:56 ` Jakob Oestergaard
2006-04-25 9:03 ` Jan Engelhardt
2006-04-24 21:36 ` J.A. Magallon
[not found] <65eLE-GJ-21@gated-at.bofh.it>
[not found] ` <65zwH-61W-51@gated-at.bofh.it>
[not found] ` <65zZH-6Bw-23@gated-at.bofh.it>
[not found] ` <66grR-2DK-27@gated-at.bofh.it>
2006-04-28 0:03 ` Robert Hancock
-- strict thread matches above, loose matches on Subject: below --
2006-04-28 9:37 Khushil Dep
2006-05-02 18:21 Al Boldi
2006-05-02 20:28 ` J.A. Magallon
2006-05-02 23:55 ` Peter Williams
2006-05-03 8:09 ` Steven Rostedt
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=44576F8B.7000206@argo.co.il \
--to=avi@argo.co.il \
--cc=davids@webmaster.com \
--cc=linux-kernel@vger.kernel.org \
--cc=willy@w.ods.org \
/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