Live data from Hacker News

Linus Torvalds on C++

harmful.cat-v.org

81–90 of 190 posts

Re: Linus Torvalds on C++

#81

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.

"fundamental flaws in its design" It would be pretty hard to fix them without breaking backward compatibility.

Agreed.

Re: Linus Torvalds on C++

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

I've been working on my own DSP library in C++ on and off over the past year and a few times I've gone through the thought experiment of rewriting it in pure C.

Every time I conclude that all I'd gain in the process is the extra work of finding some third party collection library, adding manual resource management where I currently use RAII, and rolling my own struct-based object system, probably with a buch of macro glue.

I don't see how this makes my life any simpler.

Re: Linus Torvalds on C++

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

The STL is a huge leap over C, but it could be so much better.

On one hand, it's not particularly good for really low level coding, as other people have explained.

But on the other hand, it's not really convenient for higher level coding, either.

To see what I mean, compare the interfaces of std::string [1] and Qt's QString [2]. Common, simple things like converting numeric data to/from string, splitting into substrings, and find/replace are a PITA in the STL. The containers are nice, but even they could use some work.

I know it'd never happen, but I think the non-GUI parts of Qt would make a really nice standard library.

[1] http://www.cplusplus.com/reference/string/string/ [2] http://developer.qt.nokia.com/doc/qt-4.8/qstring.html

Re: Linus Torvalds on C++

#84
post #75
post #37

Earlier quoted context omitted.

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

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

When 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).

Re: Linus Torvalds on C++

#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 lists, virtual methods, some form of exception handling.. why waste your time? I laughed pretty hard when I understood how the linked list implementation in the Linux kernel works (pointer arithmetic tricks + sizeof). People don't even invent anything different from whats already in C++.

The key to using C++ is to find a comfortable subset and stick with it. I haven't used C++ on projects with more than 3 people yet so I don't know the pains of agreeing on exactly which subset to use but I imagine it could be done.

Re: Linus Torvalds on C++

#86

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've been writing C and C++ for a long time (kernel and user mode) and what I find is, it takes a fair bit of discipline when writing C++ code (like hiding new/delete for stack-only objects or ensuring operator= works for heap objects and so on). Debugging with STL and templates can be PITA since the error messages are so convoluted in most compilers. One thing I would agree on Linus, is the talent pool of disciplined C++ programmers is pretty scarce. There are tons more C programmers that have enough OO experience of faking vtables and building structs-with-callbacks to simulate class inheritance and what not.

Re: Linus Torvalds on C++

#87
post #76

This saddens me as C++ is growing into such a beautiful language. C++11 is a major step forward, and I don't really buy in to complaints that are not about the current standard. Bad programming is language agnostic. Disliking a language generally implies that you don't know enough about it to really get it.

Here here! I've really enjoyed using C++11. Feels very clean. Lambdas for inlined anonymous callbacks in boost::asio? Yes please.

Re: Linus Torvalds on C++

#88
post #78

Earlier quoted context omitted.

AAA games, browsers... Really, anything where you need to have some abstraction but performance is still critical.

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 everything that Andrei Alexandrescu has touched. For elaboration: http://drdobbs.com/article/print?articleId=217801225&sit...

Re: Linus Torvalds on C++

#89
But no one can deny that c++ is the most fascinating programming language in this world. You can either spend or waste as long time as you want to __LEARN__ this language and never can say I understand ALL.
Post reply on HN