Live data from Hacker News

Linus Torvalds on C++

harmful.cat-v.org

161–170 of 190 posts

Re: Linus Torvalds on C++

#161
post #85

I have used C and C++ extensively (10+ years both). I once tried to implement the C++ inheritance model in a C program (basically just fill up the virtual table manually). It was a complete nightmare, wrought with silly mistakes all over the place. Probably Linus is right that C++ does not belong in the kernel but for application level code reinventing all the basic C++ things in C seems like a waste of time. Linked…

One thing about inheritance: It's not necessarily a good way to model things. Often it's a procrustean bed where you try to twist your concepts into what the language will let you express.

I've seen a lot of people use inheritance to save keystrokes. "I can save time if Plane inherits from Bus, they've both got wheels, after all." That's a kind of "typing" system . . . but not the kind that people expect :-)

Honestly, the world does not often cleanly decompose into a class tree. Usually it's pretty messy.

Re: Linus Torvalds on C++

#162
post #133

Earlier quoted context omitted.

#include is hardly going to work at the first insertion that will call the allocator. The argument "let's use a castrated language to avoid mistakes" falls short. What about communication within the team? Properly used and tailored, the STL is extremely adequate to kernel development. The power of the template engine enables the compiler to do some very clever optimizations. More information: http://www.osronline.com…

Huh? That link claims "The STL will not work in kernel mode and cannot be used", which is not much of a surprise given the STL's use of exceptions and dynamic allocation. In any case, kernel guys seem to prefer their data structures in intrusive style rather than the container style ubiquitous throughout the C++ standard library. (For an example, see the intrusive list and red-black tree implementations in the Linux…

Indeed, I've seen a talk from Bjarne recently where he said that by considering what is required to make RAII work in the presence of exceptions you can basically derive the entirety of C++..

Re: Linus Torvalds on C++

#163
post #14

I tend to take everything Linus says with a grain of salt. Not because he's wrong, or because he doesn't know what he's talking about, but there's enough of the puckish troll in him that I tend to read his posts more with an eye to their intended effect, than to what he's actually saying. There are plenty of applications for which c++ is a perfectly sensible language choice. Git isn't one of them.

If I understand what proponents of C++ say, C++ is supposed to be suited best for medium-level programming where abstraction is helpful but low-level constructs and speed are still helpful. It's supposed to give you many of the benefits of higher level languages while still giving you high performance. It's intended to be widely portable but still easily hook into special OS-specific facilities. This description soun…

An alternative to C++ in this situation is to have a C core or set of C libraries, with bindings up to something like JavaScript or Lua. World of Warcraft, Emacs, Firefox are a few popular examples of that architecture. GNOME 3 works this way too.

It's pretty important to have good automation for the C-to-high-level conversion, for example GNOME has a gobject-introspection to do this, and Firefox has XPCOM. Otherwise it becomes too tedious and bug-prone to be gluing two languages together by hand all the time.

An old blog post http://blog.ometer.com/2008/08/25/embeddable-languages/

I suppose node.js could be considered another example of this approach, by writing the super-tiny-and-fast event loop and http parser in C and then putting all the application logic in JavaScript.

Re: Linus Torvalds on C++

#165
post #151

Earlier quoted context omitted.

Can you name any language that does give you that level of control in its standard collection classes? At least C++ gives you the power to define your own if you really need to.

"C++ gives you the power" exactly because there's full C underneath -- once you avoid "standard" containers, "OOP," "STL," "boost" and "best C++ practices" you can still malloc and place structs where you want. Sometimes you really need that level of control, and you get it from C. AFAIK, Google's Go simply just says "we don't give you that level of control." That's why C won't be fully replaced with Go. And that's a…

D give you the same control that C, and same time you have a lot of funny things that have other high level languages at same time that is'nt a kraken like c++

Re: Linus Torvalds on C++

#166
post #102

I've read this "news" like dozens of times, and every time I can't help laughing. What he is speaking of is generally true. If I am not writing in C, then I am writing in ASM for speed, or in LISP for less code. C++ just doesn't fit in my tool chain, because it really doesn't excel in any aspect.

C++ (and other mainstream languages, for that matter) excels in the aspect that you can actually write useful software with it. Yet, to the date, there are exactly zero useful pieces of consumer software (e.g. browsers, office suites, video processing) written in lisp. Thus, I suggest that lisp zealots stfu about C/C++ already, and either fix their favorite language or invent a new one.

Yeah, of course, right... that's why we have Lisp programs on space probes [1], PS2 games written in Lisp [2], PG's Viaweb, Maxima [3] among others, ITA Software, Emacs, StumpWM, and a ton of other stuff I can't remember right now. Ah not to forget AutoCAD. I don't give a flying fart whether it's "consumer" software or not. A ton of useful software has been and is written in Lisp dialects and there are a lot of application domains that are really hard where you just cannot use C++ (or some other blub) because it's just not expressive enough. Often those are not consumer applications because most consumer applications are really mundane glorified reporting apps that could be coded in BASIC by a monkey (and if you read TDWTF you get the impression that happens more often than not).

tl;dr: Obvious troll is obvious.

[1] http://www.gigamonkeys.com/book/lather-rinse-repeat-a-tour-o...

[2] http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp

[3] http://maxima.sourceforge.net/

Re: Linus Torvalds on C++

#167
post #140

Earlier quoted context omitted.

An Obj-C message is still about 5x slower than a C++ virtual function call, but even that is too slow for inner loops of expensive algorithms. For example, I'm doing DSP at 44.1k ops per second and I can only afford about one virtual function call for every sixteen samples but I can put my samples in an STL vector with no access overhead vs a raw array. It's true that most people don't need the performance you can ge…

According to Mike’s measurements I linked above a cached Objective-C message send is faster than C++ virtual method call, so in a loop both languages should come pretty close. You can also get a pointer to the function implementing a method and call it directly. But I think we now understand each other – yes, Objective-C is not as fast as C++ in some cases, but those cases only matter to a very small number of people…

Also, it's _really_ easy to optimize those inner loops if you need to in Objective-C. If message passing is too slow, just turn it into some C function calls and you're done.

Re: Linus Torvalds on C++

#168
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-…

I might suggest taking a look at D. It's more or less C++ redesigned from the ground up by a C++ compiler writer, so it's much more consistent and a lot more pleasant to program in. I've had bad experiences with the third-party libraries, which were sometimes inconsistently documented and half-finished on account of the still unfortunately small community, but the standard libraries are excellent, especially everythi…

Say that doing metaprogramming in D is really fun and not a guru thing like in C++ .

Re: Linus Torvalds on C++

#169
post #154

Earlier quoted context omitted.

IMHO, "being portable" is more about "being available to many users" than "being available to many systems". Focusing on ancient and obscure systems (used by who, exactly?) while ignoring systems used by a large potential users population doesn't make a lot of sense to me. And I don't see how you can blame that on these major systems either. Willing to specifically support archaic but important systems who desperatel…

Git was built specifically to scratch the itch of Linux kernel developers. Linux kernel developers tend to like making sure the Linux kernel works on as many obscure architectures as possible. See https://en.wikipedia.org/wiki/List_of_Linux_supported_archit... Making sure Git is portable across system architectures is quite important. Also, portability in the "being available to many systems" thing is important for a…

I don't see how your example contradicts my point of view. When you move things from a fairly popular system to a widely popular system, you expect it to work as well as before. Now instead if you had chosen an obscure system nobody cared about, of course you would have loved your tools would be supported as well - but hey, you knew that choice was risky.

Of course portability is pretty damn important : it gives you the liberty to choose the system you want (depending on your needs) while keeping the same user experience everywhere. But x86_64 Linux systems (for instance) should not be supported because they run Linux : they should be supported because a whole bunch of people use them and need that support.

Re: Linus Torvalds on C++

#170

Earlier quoted context omitted.

"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've used C++ more than any other language, both professionally and for personal projects, for 13 years. I freely admit that C++ is complex, and it takes considerable effort to understand how to write good C++ code. Even after 13 years, I know that I do not know every rule. Nevertheless, I have been very productive with it. I got about 3 pages into the meat of the FQA. I can't bring myself to spend the time to go fur…

You can pretty much Know C inside of ten years of using it professionally. I swear after twenty years of using C++ I still come across things I've never seen before, the rabbit hole very deep indeed.

Now with the new C++ there's a ton of new stuff to absorb.

Post reply on HN