Live data from Hacker News

Linus Torvalds on C++

harmful.cat-v.org

51–60 of 190 posts

Re: Linus Torvalds on C++

#51
post #17

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 struct…

It'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.

Just to follow up, here's a posting from Linus around that time: 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 "

Re: Linus Torvalds on C++

#52
post #6

Has anyone really not seen this in the last two years? Anyway, Linus may be a very experienced C programmer, but that doesn't mean his opinion on C++ carries much weight... I'd be more interested on what someone who actually has a lot of experience in using C++ says. Especially with modern C++ and recent tools, libraries etc, which are very different from what was around five or ten years ago. I suppose it is nice fo…

Haven't seen it. I've seen many other examples of Torvalds being an ass, but I don't bother to keep track really. It does make me wonder though how he's able to get away with responses like that, when most other "founders" (not sure what the proper term here really is) would have the majority of their users/supporters just go elsewhere. EDIT: ... Let alone have supporters who get defensive enough to start downvoting…

This man is being downvoted unfairly.

I've read Torvalds' post at the top of the page. I've also read the balance of opinion on this page. The majority view is that C++ really is a terrible language for writing a kernel. Fine, I accept that.

Now re-read Torvalds' post. How many people here would want to work with someone who regularly expresses himself like that? I know, I know; substance is more important than image and so forth. But that post reminds me of what people said working with Steve Jobs was like before he died.

Life is too short to work with jerks.

EDIT: Removed excess snark.

Re: Linus Torvalds on C++

#53
I wonder what Linus thinks about Objective C as another as an alternative approach to Object Orientation in C.

IMO Objective C gets much farther in implementing polymorphism and dynamic binding than C++ can even dream of.

Although I hear good things about Boost, I think thats like patching the language instead of fixing the fundamental flaws in its design.

Re: Linus Torvalds on C++

#54
post #2

A discussion which was inspired by this rant by Linus Torvalds on Stack Overflow: http://stackoverflow.com/q/1995471/89391 (Is learning C++ a good idea?)

To avoid confusion, the link is "A discussion on Stack Overflow which was inspired by this rant by Linus Torvalds"

Re: Linus Torvalds on C++

#55
I use C and C++ extensively (30+ years writing C, 25 or so writing C++).

I much prefer C when writing systems-level code. It's simpler and a lot more predictable. You don't get the illusion that things like memory management are free.

I /have/ written drivers in C++. Here you have to be very careful about memory allocation (calling 'new' in an interrupt handler is usually death, though I've also written very specialized allocators that work in IRQ contexts). STL isn't going to cut it, especially if you're writing something real-time that needs very predictable performance.

So, my basic prejudice is that while you can use C++ for systems stuff, you still really need to be close to C semantics, so you're basically buying namespaces and "C with classes" at the risk that some yahoo later on is going to #include and utterly hose things . . .

Re: Linus Torvalds on C++

#56

Has anyone really not seen this in the last two years? Anyway, Linus may be a very experienced C programmer, but that doesn't mean his opinion on C++ carries much weight... I'd be more interested on what someone who actually has a lot of experience in using C++ says. Especially with modern C++ and recent tools, libraries etc, which are very different from what was around five or ten years ago. I suppose it is nice fo…

I work with both C and C++ regularly.

I don't like C++, but I like C.

Counterintuitively I think the underlying reason is that C++ follows the exact same philosophy as C. For all of the following statements you can replace C with C++ and it is equally true:

Every feature X acts in such a way to make implementing it at the time of its invention as expedient as possible

The best heuristic for guessing how a feature you don't know (or forgot) works in X is to say "let's imagine X was just as it is now, only without this feature, how would I implement it?"

All of this means that in order to be a competent X programmer, one ought to be able to write an X compiler without too much outside help.

I could go on and on like this, but hopefully you get the point. Now it is clear that the philosophy for X works for small languages (like C) but could easily have scaling problems (like C++).

It also becomes clear why so many places subset C++, but don't pick the same subset. The problem isn't that some feature is broken, the problem is that there are too many features without an overriding rule that most people can apply. I would also believe that Bjarne Stroustrup can be quite effective programming C++ since he knows the language intimately enough.

Re: Linus Torvalds on C++

#57

Has anyone really not seen this in the last two years? Anyway, Linus may be a very experienced C programmer, but that doesn't mean his opinion on C++ carries much weight... I'd be more interested on what someone who actually has a lot of experience in using C++ says. Especially with modern C++ and recent tools, libraries etc, which are very different from what was around five or ten years ago. I suppose it is nice fo…

"I'd be more interested on what someone who actually has a lot of experience in using C++ says." I have considerable experience with C++, going back to when it was called C with Classes and you used a preprocessor to convert C with Classes code to C and then compiled the C. What Linus says is pretty much true. I don't expect it to matter though since when people say "I'd be more interested on what someone who actuall…

I don't like C++ but the FQA isn't a very good critique of it. It's basically "Why didn't Bjarne write the language the way Yossi would have?"

Re: Linus Torvalds on C++

#58
post #20

Now this has me a bit confused, why no love for STL ? I wish Linus had added more detail. Is the complaint that the binaries are too big (not quite, if you strip them of the unnecessary symbols) ? or is it that it can be a tedium to go over the reams of error messages that compilers spit out when things go wrong. The second point I am willing to concede, it requires you to read messages inside out, which lisp does tr…

STL containers are essentially the opposite of what's used in many C programs, Linux kernel included. In C, in order to string several data items into a collection one would add a container-specific control element to the data item, and then feed a pointer to this element to the container code. Container sees only these elements, and nothing else. On one hand, accessing actual data item obviously requires casting and…

I don't see this. You can have a container of pointers in C++ just as you can in C. No special ownership semantics is assumed, nor do you have to decide which is the "owner" any more than you do in C. Or the problem is the same, at any rate. Plus you're not constantly casting to things.

You can have a container of smart pointers, too, if you really don't want to think about ownership.

Re: Linus Torvalds on C++

#59
post #47

Although it is true that certain languages give you the flexibility of writing "utter crap", I can also write pretty crappy unmaintainable code in pure C just as easily. Nevertheless, after 14 years of coding in C++, I love how beautiful my C++ code comes out. All that "OO crap" makes my code easier to understand, debug, maintain and extend. I would take that at the expense of how much more difficult it is to create…

[deleted]

Re: Linus Torvalds on C++

#60
post #19

Earlier quoted context omitted.

You also need to not use: STL(most implementations are too slow) Boost or STLPort(namespace and compatability issues if you're not producing executables) Most OO features like inheritance and polymorphism(a lot of that is resolved at runtime, which eats cycles) Function overloading(debatable, since the compiler should resolve the function signatures at compile time) You're pretty much left with C with namespaces at t…

C++ actually has some performance advantages over C, especially relating to static polymorphism (qsort v. std::sort)

Technically you can do tricks like that with the C preprocessor, though it is a bit ugly and lacks automatic instantiation.
Post reply on HN