5 ms·
C++ is a horrible language, says Linus Torvalds
- far33d 19y agoHa Ha Ha Ha. So hilarious.
- far33d 19y ago"Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C." What's not hilarious about that?
- reitzensteinm 19y agoI think you were downmodded not because your post was wrong, but because it's essentially noise (I didn't downmod you).
- nickb 19y agoThe whole exchange is great! Keep on reading the subsequent messages. Here's some interesting parts: " The fact is, that is exactly the kinds of things that C excels at. Not just as a language, but as a required mentality. One of the great strengths of C is that it doesn't make you think of your program as anything high-level. It's what makes you apparently prefer other languages, but the thing is, from a git standpoint, "high level" is exactly the wrong thing. " and "And if you want a fancier language, C++ is absolutely the worst one to choose. If you want real high-level, pick one that has true high-level features like garbage collection or a good system integration, rather than something that lacks both the sparseness and straightforwardness of C, and doesn't even have the high-level bindings to important concepts. IOW, C++ is in that inconvenient spot where it doesn't help make things simple enough to be truly usable for prototyping or simple GUI programming, and yet isn't the lean system programming language that C is that actively encourags you to use simple and direct constructs."
- far33d 19y agoI just read the whole thing... Linus basically says "I wrote it in C so idiots like you wouldn't (and couldn't) contribute". Which is mean spirited and kind of an asinine thing to say, but so awesome at the same time.
- Zak 19y agoThat's not what he said. He said "I wrote it in C because C was the best language for the job. It's also nice that C discourages idiots from trying to contribute.". He's right on both counts. I've always found using tools designed for smart people to be an effective way to cut down on the number of stupid people attempting to work on a project, but the main advantage is getting to use a good tool instead of a bad one.
- timr 19y ago<i>"pick one that has true high-level features like garbage collection or a good system integration, rather than something that lacks both the sparseness and straightforwardness of C, and doesn't even have the high-level bindings to important concepts."</i> That's a straw man. There are garbage collectors and "system integration" libraries for C++. The language doesn't lack for high-level bindings, but it also doesn't force you to adopt a paradigm. This flexibility is C++'s greatest strength, as well as its greatest weakness. Personally, I find it more than a little ironic that a huge amount of the complexity of C++ comes from its insistence on remaining backwards-compatible with C. Linus may love the "lean system programming language", but it sure does bring a lot of ugly baggage to the C++ party....
- timr 19y agoNow, why in the world would someone mod down my comment? Honestly, folks...it isn't a criminal offense to disagree with Linus Torvalds. There are positive things to be said about C++.
- jimbokun 19y ago"...but it also doesn't force you to adopt a paradigm. This flexibility is C++'s greatest strength, as well as its greatest weakness." Lisp is mult-paradigm also. I think the difference is that Lisp has a philosophy. The paradigms fit together in a consistent way. For example, Common Lisp has an object system, CLOS. But they implemented it around generic functions, in order to keep the functional programming nature of Lisp intact. Lisp will let you do pretty much anything. But it often gives you a "nudge" in a particular direction. I believe pg points this out in On Lisp; you can write procedural code in Lisp, for example, but the code flows a lot better if you write in a functional style. C++ just seems like a kitchen sink language. Everything is in there somewhere. But it doesn't seem like the parts were designed to fit together in any particular way.
- marketer 19y agoLinus basically says that C++ has "inefficient abstracted programming models". Looking at the STL, you only see some very basic abstractions: vectors, lists, hash tables, sets, and others. These are very well tested, and extremely optimized. Anyone writing a decent amount of code will undoubtedly run into a situation where they need such structures.
- jsjenkins168 19y agoAgreed. You would have to have to invest a considerable amount of time to beat the STL objects in terms of efficiency. I cant even think of a situation when you really could. Why try to reinvent the wheel? Seems like time wasted if you ask me.
- timr 19y agoThe arguments I hear most frequently are the same ones that Linus jumps on in this thread: the syntax is obtuse, the code isn't portable, and the language isn't truly high-level (i.e. it doesn't have built-in garbage collection). The first argument is (sadly) true -- C++ is ugly and complicated. A lot of that comes from the need for backwards compatibility with C (which isn't going to win any language beauty pageants, either), but a lot more of it comes as a consequence of the syntactic flexibility of the language. The second argument is mostly bunk. A decade ago, it was difficult to find a standards-compliant C++ compiler; today, it's fairly easy. Sure, there are dark corners of the language where certain compilers get funky, but that can be said of FORTRAN 77 compilers, too. In general, unless you're forced to work with a old compiler, or an old, unmaintained package, it isn't very difficult to write cross-platform C++ code. The third argument is just a straw man. Anyone who has read Stroustrup's book on the design of C++ knows why garbage collection and other "high-level" features weren't incorporated into the standard -- they didn't want to force users to adopt particular programming models or designs. Stroustrup has insisted that C++ be a flexible tool for many different types of programs and programmers; that attitude leads, somewhat inevitably, to complexity. But it makes me sad that so many people are bashing on C++ for not being "more like" other languages, when its biggest strength is probably its ability to mimic many features of those same languages, while still allowing for great efficiency.
- uuilly 19y agoI stopped listening to linus after he layed into gnome.
- portLAN 19y agoInstall Vista and that'll flip him. Flip him for real.
- eusman 19y agomaybe this will help you Stroustrup: Well, one day, when I was sitting in my office, I thought of this little scheme, which would redress the balance a little. I thought 'I wonder what would happen, if there were a language so complicated, so difficult to learn, that nobody would ever be able to swamp the market with programmers? Actually, I got some of the ideas from X10, you know, X windows. That was such a bitch of a graphics system, that it only just ran on those Sun 3/60 things. They had all the ingredients for what I wanted. A really ridiculously complex syntax, obscure functions, and pseudo-OO structure. Even now, nobody writes raw X-windows code. Motif is the only way to go if you want to retain your sanity. [NJW Comment: That explains everything. Most of my thesis work was in raw X-windows. :)] Interviewer: You're kidding...? Stroustrup: Not a bit of it. In fact, there was another problem. Unix was written in 'C', which meant that any 'C' programmer could very easily become a systems programmer. Remember what a mainframe systems programmer used to earn? Interviewer: You bet I do, that's what I used to do. Stroustrup: OK, so this new language had to divorce itself from Unix, by hiding all the system calls that bound the two together so nicely. This would enable guys who only knew about DOS to earn a decent living too. Interviewer: I don't believe you said that... source: http://members.safe-t.net/jwalker/programming/interview.html http://members.safe-t.net/jwalker/programming/interview.html
- deleted 19y ago[deleted]
- thomasptacek 19y agoLet's make it clear that that was a joke.
- mynameishere 19y agoI heard "fake steve jobs" was conducting that interview.
- kingkongrevenge 19y agoAnyone see Linus's Google git presentation? That and reading various stuff like this shows he's a rude egomaniac.
- uuilly 19y agohttp://www.youtube.com/watch?v=4XpnKHJAok8 http://www.youtube.com/watch?v=4XpnKHJAok8 I think he has a unique combination of mild autism, artistic stubborness and scandanavian directness. In the end he makes valid points and he sold me on trying git. It is hard to tell if he's being serious or if he's just making socially retarded attempts at sarcasm. Either way he's infinitely more charming than Mr. Zuckerburg...
- thomasptacek 19y agoIt was a rude and egomaniacal comment that he responded to, if you think about it. But that's OK. I don't think Linus cares if you use his code or not.
- damon 19y agoLinus is hellbent on not working with "substandard programmers" and chooses his tools accordingly. Bad programmers are really counterproductive and he's damn brilliant for weeding them out so aggressively. In his "I'm a bastard" post to the linux kernel thread in 2000, he lambasted people arguing for a kernel debugger. His argument, clear as day, says he doesn't want to work with people who depend on the debugger , he wants people to understand the code as a whole. "Oh. And sure, when things crash and you fsck, and you didn't even get a clue about what went wrong, you get frustrated. Tough. There are two kinds of reactions to that: you start being careful, or you start whining about a kernel debugger. Quite frankly, I'd rather weed out the people who don't start being careful early, rather than late. That sounds callous, and by God, it is callous. But it's not the kind of "if you can't stand the heat, get out the the kitchen" kind of remark that some people take it for. No, it's something much more deeper: I'd rather not work with people who aren't careful. It's Darwinism in software development." Here, 7 years later, he applies much the same argument to C++: "C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C." "And limiting your project to C means that people don't screw that up, and also means that you get a lot of programmers that do actually understand low-level issues and don't screw things up with any idiotic "object model" crap." Call him a prick, call him selfish, call him egotistical, the bottom line is he's in charge of a product that is much bigger, more complicated, diverse, mature, and successful than the majority on the planet. Smart hackers will get past their emotion and understand his principles are sound, proven, and successful.
- thomasptacek 19y agoIt was also a uniquely useless comment he responded to. Imagine the alternate universe where Linus responds, "you're right! Git hackers, commence the rewrite!" In a job interview, statements like Dmitry's are what I'd call a "leading indicator". NO HIRE.
- jey 19y ago- Yes, it takes a C++ expert to do C++ well. If you aren't an expert, you're going to screw it up. You'll either get mired in what I call "Fancy C++ Voodoo Magic" by over designing your code and doing weird template meta-programming without any real goal or just use the wrong idioms, or forget about some random subtleties. - Sometimes you really do need to write systems software. In these instances, I'm still going to use C++. I won't claim that C++ is a great language, but at the end of the day, the benefits provided by C++ make it worth it. It would just be more footwork in C. Classes, RAII, STL, templates, type-safety are all worth it. But this is because I have already made all the mistakes and written lots of bad C++ that I'm now able to write clean, simple and elegant C++. I'd advise a newbie programmer against becoming a C++ expert. It's not worth the time and effort to learn all the stupid cases and to learn when to use which feature and to what degree to avoid falling into the swamp of C++. It's worth knowing C++ well enough that you can hack systems code though. I wouldn't say "only learn C and not C++ for systems hacking!"
- thomasptacek 19y agoI reverse engineer and audit systems software for security flaws (OS kernels, hypervisors, filesystems, drivers, and higher-level stuff like client-server and message passing systems). I've looked at a lot of other people's systems code. Most of it is C, not C++. It's mostly C on Win32. It's mostly C on Solaris. It's mostly C running in VxWorks. Most systems code is C. Knowing both C++ and C, my counsel (worth what you paid for it) is that C++ is a waste of time for systems work. If you want to allocate a year of your life to minutiae, learn X86 runtime code generation; it'll help more with systems work, and you can write your own DSLs in C.
- dfranke 19y ago> learn X86 runtime code generation It's much easier just to embed LLVM.
- thomasptacek 19y agoThat counts. LLVM. Better than C++.
- barty 19y agoLinus shouldn't talk about something he doesn't understand. He couldn't have found a better way to advertise his ignorance about C++ to the whole world than this. He is telling the whole world that "Hey, here I am, you know, the guy who created the linux kernel, the best designed piece of software in the whole universe(don't listen to Tanenbaum though, he didn't learn OS fundamentals), so you better listen to me when I say that C++ _sucks_. Don't give me the BS about how so many large applications have been created in it, because they would have been only better had they been created in C(it's a magical language btw, solves _all_ your problems in the blink of an eye). If you go and read about people like Stroustrup, Sutter, Alexandrescu, Koening, Thomas etc, take it from me that they missed lot of their CS clases, so they don't know a thing about programming. How do I know? They use C++!" Sage Linus at one point or the other has to wake up to the fact that he is not the guru of all things that is programming and his opinion of the C++ language is taken as seriously as that of my hair dresser.
- fsilber 19y agoI have must have learned at least a dozen programming languages in my time, and none was as difficult and as counter-intuitive as C++. (Compared to C++, Ada was simple.) I think C++ was just a bad idea, a clumsy attempt to merge two incompatible paradigms. In classical imperative programming (e.g. C, Algol, Fortran, Pascal, and Basic), procedures contain and copy data structures. The heap primarily exists when unusual flexibility is needed, e.g. when the number of data objects you need isn't known until runtime. so you manage them with a global heap-based collection. Generally, you try to avoid using the heap, and where you must use it, you build an API around your collection to hide the nasty ugly details. Compared with imperative programming, object orientation provides a kind of inversion of control. Instead of having procedures which contain and manipulate data structures, you have objects which contain methods (to handle the messages that other objects send it). Objects manage their own lifecycles and storage allocation. This sort of distributed control implies a level of abstraction well above concerns about storage management. Instances of subclasses tend to be larger than instances of their parent classes, but so users of these polymorphic objects are presumed to be above worrying about the storage they take up. But that makes us dependent upon that nasty heap -- is it any wonder that the vast majority of object oriented languages _presume_ automatic garbage collection? The very fact that the C++ programmer is responsible for storage management implies that C++ objects are not to be visualized as independent and cooperating entities that manage their own lifecycles -- because then it becomes unclear as to who will have responsibility for cleaning up. Systems programming is of necessity low-level; a reliance upon automatic garbage collection simply isn't appropriate for those kinds of problems. Therefore, instead of trying to add object orientation to C (and therefore an over-reliance upon the heap), I think we'd have been better off to begin by simply adding a strong, polymorphic type system. Then we could write systems programs with a manageable degree of genericity, without requiring every programmer to become a language-lawyer interpeting seemingly conflicting regulations, or an empirical scientist running experiments to determine what his programming language does in a given situation. If we could then create easy hooks by which an object-oriented language could make calls to low-level subroutines written in that systems programming language, so much the better.