3 ms·
Linus's objections seem centered on the fact that it makes it easier to generate bloated code. While this may be true, there's nothing a little self-discipline
by strags 15y ago
Linus's objections seem centered on the fact that it makes it easier to generate bloated code. While this may be true, there's nothing a little self-discipline can't control.
STL and Boost may not make sense for the kernel, but there's nothing wrong with using C++ classes at their most basic. The kernel would be far more readable if it used classes and simple inheritance rather than re-inventing the wheel with structs full of function pointers.
C++ gives you more flexibility with regard to encapsulation as well - it's hard to argue that that doesn't lead to cleaner, safer code.
- jmj42 15y ago"...rather than re-inventing the wheel with structs full of function pointers." I think you got that backwards. Structs full of function pointers predate c++. Going for the ad absurdum, why bother inventing C++, it's just a re-inventing of the structs full of function pointers wheel?
- strags 15y agoYou're right - "re-inventing the wheel" is probably the wrong phrase - I used it because it conveys a sense of needless effort when there is a better alternative. Basically, those who don't have access to basic object-orientation are doomed to implement it themselves in a messier, more verbose form.
- jmj42 15y agoI think the argument that Torvalds was making here is that that's exactly what C++ is. Messy and unnecessary. You can write C++, but if you do so without the mess, you're so close to C that there's no point in using C++. I, on the other hand, would argue that C's lack of object-orientation somehow dooms one to implement it. OOP is _not_ the pinacle of software development. Further, I would argue that "structs full of function pointers" neither, necessarily, represents a desire for object-orientation nor is it messy.
- strags 15y agoWhen your source code is full of structs that look like this: struct obj { struct obj_functions* functions; ... } struct obj_functions { void (*do_something_with_object)(struct object* obj,...); ... } ... I'd say it's hard to argue that you're not implementing C++ style OOP, and that it wouldn't be cleaner to use C++. Now, if you're just going to stick to the basics of C++ (ie. avoid templates, operator overloading, etc...), then there's a fair argument as to whether it's worthwhile. Certainly it's not worth rewriting the Linux kernel at this point. But, I don't think Linus's comment that "C++ is a horrible language" is fair. (I'm sure most of that is just Linus being Linus).
- emmelaich 15y agoIt's also based on experience. For a while, he was convinced to at least compile the kernel with the C++ compiler. The experiment didn't last long.
- emmelaich 15y agoJust to follow up, here's a posting from Linus around that time: http://goo.gl/tTvg2 http://goo.gl/tTvg2 "The changes to get linux to compile with C++ were very minor, so if your extensions are well-written, it should be no problem at all getting it working. Gcc gives reasonably good error messages anyway, so you can usually just try to compile the old code and fix the problems as they crop up. Linus "