l4-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++


From: Bas Wijnen
Subject: Re: C++
Date: Thu, 24 Sep 2009 22:59:26 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

On Thu, Sep 24, 2009 at 02:00:31PM +0100, Sam Mason wrote:
> Yup, but if you're effectively ending up with C code what's the point
> in pretending it's C++.

That you can use the features that make sense in the context you're
using them in.  For example, code just becomes more readable if you
don't need to pass your object as first argument to functions which act
on it.  I'm now using capabilities as simple numbers (in user space; in
kernel space their quite a bit bigger), but I've wrapped them into a
class which makes it possible to call member functions on them.  And I
have other classes which inherit from that class which have their own
member functions which implement a certain interface.

None of this costs anything really; I could have used Stream_write (cap,
data, size); instead of Stream s; s.write (data, size);  I much prefer
the latter for readability, also because it will not allow me to
accidentily use a method that the type doesn't support (but it is
possible with a cast, of course).

I'm not saying the kernel needs to be "real" C++ and use everything it
provides.  I'm saying that using selected features can make it better
maintainable and more readable, and it doesn't have to cost anything if
you're careful.[1]

The features I select specifically don't include things which may be
implemented in complex ways, such as virtual functions and exceptions.
I even avoid constructors most of the time, because they are too easily
called.

Thanks,
Bas

[1] Being careful is not always easy though, I suppose.  For example,
default function arguments sound very nice, but when used incorrectly,
they let you pass many more arguments than you really need, which may
impact performance.

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]