Live data from Hacker News

Linus Torvalds on C++

harmful.cat-v.org

121–130 of 190 posts

Re: Linus Torvalds on C++

#121
post #113
post #78

Earlier quoted context omitted.

There's a large faction in AAA games that thinks C++ is a stupid idea. It's debatable who's right in that debate, but good points are being raised. The problem is not so much that C++ is a worse language than C - it's that it makes it insanely easy to shoot yourself in the foot in hideously complex ways that take forever to unravel. See e.g. two phase name lookup - http://blog.llvm.org/2009/12/dreaded-two-phase-name-…

It’s a great pity that Objective-C doesn’t get more attention in this regard. It’s C, so it features all the simplicity, elegance and existing APIs. And at the same time it offers a good, simple and flexible object model with almost no surprises. The performance can be very good, too, as proved by the Apple runtime, and you can always drop to lower-level tricks or plain C when you need it. The syntax takes some getti…

The problem is that Obj-C message passing is always going to have a cost. STL implementations can inline accessors, for instance, to provide containers and algorithms with essentially zero overhead that can even be faster than raw C because the compiler has more type information.

Re: Linus Torvalds on C++

#122

Linus is probably the %1 of people in the world who actually needs to get the performance gain that C has over C++ - as for the rest of us? Probably doesn't matter.

C++ can actually be faster because it doesn't throw away as much type information. A good, typed C++ quicksort implementation, for example, will be faster than a C version using void*.

Re: Linus Torvalds on C++

#123
post #109

Earlier quoted context omitted.

And everything to do with the fact that it was written by C++ programmers.

Doom3 was written in C++ by John Carmack. https://github.com/mtrencseni/doom3

John Carmack is a C programmer coding in C++ which fits pretty well with sirclueless's point about that it is the C++ programmers that are the problem. All his games before Doom 3 were implemented in C.

Re: Linus Torvalds on C++

#124
post #33

Earlier quoted context omitted.

Yup, and if you avoid using any of the new language constructs like objects and whatnot that C++ brings and basically stick to standard C, maybe using just a bit of C++ sugar here and htere, true.... but at that point you might as well be using C, and the argument is really moot.

You are wrong. Those the only two features that incur any performance penalty for just existing, and even then it's implementation dependent and in some cases can be zero (ie. zero cost exceptions). Other things that are possibly slow, like virtual functions, can be avoided in specific cases when needed. This is similar to many how C projects use structures of functions pointers, for abstraction, but not everywhere (…

[deleted]

Re: Linus Torvalds on C++

#125
post #113

Earlier quoted context omitted.

It’s a great pity that Objective-C doesn’t get more attention in this regard. It’s C, so it features all the simplicity, elegance and existing APIs. And at the same time it offers a good, simple and flexible object model with almost no surprises. The performance can be very good, too, as proved by the Apple runtime, and you can always drop to lower-level tricks or plain C when you need it. The syntax takes some getti…

The problem is that Obj-C message passing is always going to have a cost. STL implementations can inline accessors, for instance, to provide containers and algorithms with essentially zero overhead that can even be faster than raw C because the compiler has more type information.

That’s a non-issue for the vast majority of people. As an example, I have written games in Objective-C for the first iPhones. In a game running at 50 fps you have about 20 ms to get a single frame out, and still I could freely use message passing in the inner game loop without giving it a thought. See also some older measurements by Mike Ash: http://goo.gl/DBTPE.

Re: Linus Torvalds on C++

#126

Linus is probably the %1 of people in the world who actually needs to get the performance gain that C has over C++ - as for the rest of us? Probably doesn't matter.

C++ can actually be faster because it doesn't throw away as much type information. A good, typed C++ quicksort implementation, for example, will be faster than a C version using void*.

One of the reasons for the performance difference is that you can't inline into the libc DLL blob: If you use qsort(), you'll get a lot of overhead from calling the comparison function.

If you use a custom quicksort implementation and put it into the same translation unit as the comparison function (or compile statically and use link-time optimizations with a sufficiently advanced compiler) you can get the same performance out of C.

Re: Linus Torvalds on C++

#127
post #96

Earlier quoted context omitted.

And also what Bloomberg saw C++ lacking: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n185... I'd still like to see how both these papers influenced last C++ standard at the end (I admit I didn't try to follow) -- is there finally a "standard" way to do all that?

Notice the dates on these papers though. 2005 and 2007 are a long time ago in C++ compiler land. I'm using the STL in very low latency DSP code with zero problems. You have to make sure you don't allocate memory in realtime callbacks but that's just as true of malloc.

Dates are irrelevant if you really want to control where something gets allocated. Last time I've checked there weren't the level of control described in the linked articles in "standard" C++. If you know how I can achieve it, please write, but please don't dismiss my need with "you wouldn't notice everything is fast enough it's 2012."

Re: Linus Torvalds on C++

#128
post #24

Linus' rant is grounded in practicality. Portability concerns are huge for git. Read the source code. Git compiles on lots of (arcane and ancient) Unix flavors, and has to deal with the compilers on those platforms. C is still the right choice for git.

> Portability concerns are huge for git.

Oh, is that why Git has such great support for Windows?...

...

Re: Linus Torvalds on C++

#129
post #6

Earlier quoted context omitted.

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…

Except it's not true: The Commodore Amiga delivered multi-tasking, shared objects and sophisticated IPC in only 256k of main memory. They cite OO techniques as being key.

http://en.wikipedia.org/wiki/Exec_(Amiga)

Re: Linus Torvalds on C++

#130
Its quite fascinating seeing heavy weights have a go at each other. Most of the discussion here is right over my head but I find myself quite enjoying it. At least its better that the current boxing heavy weight scene. This is about the only post on hacker news that I have read comments on from start to finish. Brilliant all!
Post reply on HN