lkml.org 
[lkml]   [2004]   [Dec]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: What if?
On Thu, Dec 02, 2004 at 03:24:32AM -0500, James Bruce wrote:
>
> I think this oft-repeated argument is a strawman, since C++ and C are
> identical on primitive types, and for non-primitive types, C can't use
> operators anyway.

While that may be true, the problem is that you don't know off the top
of your head whether something like:

a = b + c + d + e;

involves primitive types or not just by inspection. So it could be
something that takes no time at all, or a monstrosity which takes a
dozen or more memory allocations, and where it requires a Ph.D. in
understanding obfuscated code to figure out which overloaded operators
and which type coercions had actually taken place. And remember, this
is a language where you can even override the comma (',') operator.
You think you know what a piece of code will do just by looking at it?
Think again!

This is perhaps one of the reasons why no one has bothered to make a
C++ analogue of the Obfuscated C Programming Contest. There simply is
no challenge involved. I have seen propietary codebases written in
C++, where said codebase was the crown jewel of the company, and while
the original C code was understandable, when it was re-written in C++,
it was completely unmaintainable and impossible to understand what was
going on. I was reduced to placing printf's all over the place just
to figure out the flow of control.

(Out of respect to the company involved, I won't name names, but it
was a filesystem-related product, and I was adding ext2 support to the
codebase at the time. While on paper it may have made sense to use
C++ classes to represent different filesystem drivers, the
implementation was a complete and mitigated disaster, IMHO. And this
is not the only C++ project I have seen where it would have been much
easier to understand the darned thing if it had been written in C
instead.)

On Thu, Dec 02, 2004 at 08:33:44AM +0000, J.A. Magallon wrote:
> Don't ge silly. I have written C++ code to deal with SSE operations
> on vectors, and there you really need to control the assembler produced,
> and with the correct const and & on correct places the code is as
> efficient as C. Or more. You can control everything.....
>
> It is as all things, you need to know it deeply to use it well.
> There are a ton of myths around C++.

If you know how to use a table saw deeply and well, you can use it
safely even with all of the safeties disabled and the blade guard
removed. There are even a few cases where you have to do this.
However, I wouldn't recommend it for most people since it is far too
likely they will lose a finger or a hand....

That's the problem with C++; it is far too easy to misuse. And with a
project as big as the Linux Kernel, and with as many contributors as
the Linux Kernel, at the end of the day, it's all about damage
control. If we depend on peer review to understand whether or not a
patch is busted, it is rather important that something as simple as

a = b + c;

does what we think it does, and not something else because someone has
overloaded the '+' operator. Or God help us, as I have mentioned
earlier, the comma operator.

> In short, with C++ you can generate code as efficient as C or asm.
> You just have to know how.

You can juggle running chain saws if you know how, too. But I think I
would rather leave that to the Flying Karamazov Brothers.

- Ted
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:08    [W:1.242 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site