Well, it's quite simple, really...
Posted Jan 18, 2011 11:34 UTC (Tue) by
khim (subscriber, #9252)
In reply to:
Not everything is a nail... by khim
Parent article:
Sobotka: Why GIMP is inadequate
Everything that can be done in C can be done at least as well in C++.
Well, this is strawman argument: of course you can just ignore all C++ extensions and then produce the same code in C++ as in C. But what's the point? If you try to use "real" C++ facilities...
$ cat hello.c
#include <stdio.h>
int hello() {
printf("Hello, World!\n");
}
$ gcc -O3 -c hello.c ; size hello.o
text data bss dec hex filename
72 0 0 72 48 hello.o
$ cat hello.C
#include <iostream>
int hello() {
std::cout << "Hello, World!" << std::endl;
}
khim@khim-glaptop:/tmp$ gcc -O3 -c hello.C ; size hello.o
text data bss dec hex filename
244 8 1 253 fd hello.o
Claiming that C++ would have led to a more complex and less flexible design is thus downright absurd.
Not really. Most C++ designs are indeed more flexible, but this is not a big factor for kernel development where you can always redesign anything (the infamous "stable API nonsense"), but the fact that they are "more flexible" usually means they are more complex and less efficient.
(and the code produced in C++ is usually significantly more resource-hungry and slower then code written in C)
That's outright bullshit. A key design decision in C++ has always been "don't pay for what you don't use", and it worked out pretty well in fact.
Where "pretty well" == "bloat of about factor of two or three". Yup. C++ does not impose choice on your so you end up with 4-5 implementations for basic things. Heck, C++ standard includes two different string implementations from the start (I mean "char *" and "std::string") - and different libraries like to add additional ones! And we are talking about kernel, remember? Kernel shares L1 with userspace program and it's pitiful: 64K at most. And, please, don't talk about Moore's Law here: PowerPC 601 had 32K cache 18 years ago, Intel Core2 has 32K cache today. Yeah, it's kind of "apples vs oranges" because there are two 32K caches on Core2 and PowerPC 601 and AMD's Phenom has whopping 64K L1 cache, but anyway: even two doublings per 18 years is not enough to claim that endless adapters and transformers are no longer meaningful for kernel.
The "don't pay for what you don't use" is only good when you don't use anything. When you actually do use some facilities you suddenly find out that they cost more then in case where language imposes things on you.
(
Log in to post comments)