8 ms·
C++ in Coders at Work
- cturner 17y agoHave there been experiments with creating a pre-compiler that checked that you were using a subset of C++? What downsides would this have (other than longer compile time)?
- jacquesm 17y agoBut which subset ? When I program in C++ (and sometimes you have to) there are features that I'll avoid like the plague, once bitten, twice shy. In fact, my subset of C++ was usually try to stay as close as you can to C and use C++ when you have to. That seemed to be a pretty safe route. Most of my C++ stuff was using Borland C++ Builder or Microsoft visual C++, I'm happy to say I no longer have to support software for the windows platform, so no more C++ for me.
- rdtsc 17y agoI just use gcc to compile the code. That way I know what subset I am using and the rest of the code is using.
- coliveira 17y agoI try to stay as close to C as possible. But C++ has many temptations. If you start using boost, for example, you will be in no time using features of C++ that are not even in the standard yet :-))
- jacquesm 17y agoThe google style guide posted elsewhere in this thread links to this: http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py http://google-styleguide.googlecode.com/svn/trunk/cpplint/cp...
- aboodman 17y agoArgh. Not a very useful article. Start with an observation: "Everyone hates C++, and yet it is really widely used. That's odd." Next, 10 paragraphs of people hating on C++. End with: actually wait, no ending.
- jacquesm 17y agoWell, the 'everyone' he is talking about are some of the most respected people in the computer world, that should count for something. Also, they make fairly specific criticisms, and they have a track record of being right about such things. Java seems to be the C++ replacement of the future, with C# pulling the other way.
- slpsys 17y ago"with C# pulling the other way" Care to elaborate (I'm legitimately unsure what you mean, not being snarky)?
- jacquesm 17y agoI think that C# is an attempt at creating an alternative for enterprise level programming to Java, basically .net and C# are an answer to the whole Java ecosystem. They're competing for the same space, so a business that wants to implement some functionality from scratch basically has these two solutions to choose from. In the 'web' domain there are many many more choices, but for places like banks and such that were first dominated by COBOL, then reluctantly moved to C or C++, for the most part they are either looking at Java or C#.
- slpsys 17y agoA-ha, yeah. I read that originally as Java and C# pulling in opposite directions in a fundamental way, not as a mind-/market-share sense
- dtf 17y agoWell, the 'everyone' he is talking about are some of the most respected people in the computer world, that should count for something. And while they're busy bitching and hating and pontificating, humble unknowns are getting things done and making the world a better place. C++ is to systems programming what PHP is to web programming: the loyal packhorse that the A-list wouldn't be seen dead on.
- prakash 17y agoI noticed this as well when I read the book: http://www.cloudknow.com/2009/08/review-coders-at-work-by-peter-seibel/ http://www.cloudknow.com/2009/08/review-coders-at-work-by-pe...
- Oxryly 17y agoPart of how C++ is successful is that it retains C compatibility, and C accurately models how the computer actually works (at least computers of the 70s and 80s, which is all we know how to program well). Lovely languages like lisp, python, haskell may be nicer to work with, but they do not model the underlying machine properly, and for so many problem domains that is just not acceptable. It's not just a performance question. And then C++ implements several programming paradigms (object oriented, generic, etc) without compromising that machine model. Plus Bjarne was truly correct when he said: "there are languages people complain about, and there are languages nobody uses."
- amalcon 17y agoC is a portable assembler. Sometimes that's exactly what you want. C++ is C, except that it doesn't completely suck for higher-level projects.
- seiji 17y agoLLVM IR [1] is portable assembler. C is "portable" in the sense that: a.) you get direct access to your linear address space b.) gcc targets so many instruction sets that you don't have to worry about your backend unless you have a custom platform. C++ is the thing that screams "__gxx_personality_v0" at me because I always start off using gcc instead of g++. [1]: http://llvm.org/docs/LangRef.html http://llvm.org/docs/LangRef.html
- jacquesm 17y agoCalling C portable assembler is not to be taken literally, but in context of its usage, which was for the most part systems level stuff that previously would have been written in assembler, requiring expensive ports between platforms. C changed that dramatically and helped to cut down on porting effort tremendously.
- varjag 17y agoI would say C++ is somewhat less portable assembler than C, due to different linker semantics, which is not unified across platforms.
- sb 17y agoI think it's a very good article detailing the various flaws of C++; I particularly have problems with the complexity of the languages making it very difficult for compiler writers to generate usable error messages (not only true for gcc as mentioned in the article, but Microsofts C++ compiler generates many unusable error messages, too! [At least it did in 2004, never touched it again...])
- jacquesm 17y ago> Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to the language, to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair. > And he said “no” to no one. And that is the core of the problem.
- scott_s 17y agoI see this claim made frequently, but Stroustrup talks about several features in Design & Evolution that were rejected. The committee requires implementations before accepting new features; they don't say "We like that idea" and include it without evidence that it's both possible and useful.
- jacquesm 17y agoI think the main thrust of that argument has to do with trying to please too many people that were willing to put their support behind C++ if the language would support their pet construct.
- dkarl 17y agoIt was more the other way around, I think. Implementers had a lot of power to say, "No, this can't be done efficiently," and as a result, the burden was passed to programmers instead. Can you give an example of a "pet construct" (aside from major features like multiple inheritance and exception handling) that could have been left out?
- jacquesm 17y agoI think operator overloading, which seemed like a 'great idea at the time' with some forethought should have never been part of the language in the way it works right now. The times that I ran in to examples where it was used properly and elegantly I think it could have been done just as nice with a properly named function call. I think the way it workd came from the DSL camp arguing that you should be able to make it look as though certain bits where native to the language, even if they weren't, and then the only uses we get are things that have nothing to do with DSLs but everything with children handling power tools (as in: bad idea). Show me a single example of where operator overloading was necessity to make a function work, and I'll show you a more cleanly coded version using a function call. The interesting thing is that after the compiler is done with it you'll be calling ::operatorX anyway. Plenty of times there are naming issues as well, what does it mean to add two items of 'X' together, most times such a statement would be meaningless in the real world, but if you were forced to use a named function instead of an operator that function would have a name that matched what really happens. Naming stuff is one of the great powers of computer languages, use of operators should be reserved to those situations where the outcome is predictable, and where operator precedence rules are the same as they would be when adding numbers. So, it's fine to add an instance of a class called 'area' to another instance of that class, but you can't add one instance of 'boat' to another. That one should be done using: cargospace = add_carcospace(boat1,boat2); or something to that effect.
- timr 17y agoThis is a disappointingly flamey article: roughly 90% of the comments are from people who got a bad impression of C++ during the pre-standardization days (which were admittedly horrible, but long since past). Most of the rest are from people who just skipped straight to Java, or who are so young that they never had to learn C++ at all. The comments that really drop my jaw are the people who seem to hold up Java as a "better" C++. Java is okay, but from its sketchy real-world performance, to its crappy generic programming support and poor ability to enforce such type-safety basics as const-correctness, I've never been impressed. Take the time to learn C++ for what it is, instead of "C with objects" and you'll find that it's far more elegant than the backlash would suggest. I think that what most people really hate about C++ stems from the widespread use of legacy compilers that incorrectly implement the spec, or implement older versions of the spec. This problem exists for every programming language in the universe (e.g. Ruby 1.8.6 vs. Ruby 1.8.7 vs. Ruby 1.9), but since C++ is widely implemented by multiple vendors, the problem appears worse. If Python or Java were implemented by Microsoft and GNU and four other smaller companies, you'd see the same horrible compatibility problems with those languages, too.
- deleted 17y ago[deleted]
- coliveira 17y agoThe problem with C++ is not just bad implementation. Nowadays we have excellent, standard-compliant compilers for C++ but there are still rough edges. For example, the amount of garbage you get from template errors. You can "learn" to live with that, but it is something broken in the language, which won't be solved quickly. The amount of care you need to to write correct exception-based programs is another. And the failure of exceptions on method signatures show how we should really avoid some of C++ features.
- icefox 17y agoI would have to agree. I have no doubt that anyone in the early days of C++ probably had a real bad experience and was right to tell people not to use it at that time. I personally still use C++ because of the libraries and tools. With Boost, Qt, WebKit, valgrind, gdb, and others I am simply too productive in C++. If someone told me I could only use the c++ standard library and no other libraries I could probably switch languages pretty quick. I can only imagine what it must have been like before when you got nothing.
- rams 17y ago"Yet C++ is also frequently reviled both by those who never use and by those who use it all the time." I was once listening to RMS speak at a conference. One guy got up and said that this was one of the n great talks he had been to.He mentioned that Stroustrup as another speaker who had impressed him upon which RMS said "You need to get your head checked". Sometimes a great hacker community can help overcome the shortcomings of a language. Trevor Blackwell makes that point here: http://www.tlb.org/faq.html http://www.tlb.org/faq.html. "Besides their intrinsic characteristics, languages define commmunities of programmers. You want to choose one that lets you communicate with good programmers, because you'll learn from them. They tend to prefer powerful languages like Python, Lisp, and C++. So for example, although Visual Basic is actually a powerful and complete language, few good programmers use it. C++, on the other hand, is a rather poorly designed language, but for historical reasons a lot of smart people use it so at least you'll be in good company."
- alrex021 17y agoIts really fascinating to me. We had Lisp and then the road for many lead to C/C++, Java, and related and then we needed a way to express data in more human-readable form so some genius came up with XML. XML was to cumbersome (close tags, how attributes are expressed, etc.) and then JSON came into the picture. So all that to just come back to where we were in the first place. Now I clearly understand what some of the veterans in "Coders at Work" really meant by "Very little progress, if any, has been made in the Programming space".
- haberman 17y agoJSON is not a programming language.
- jimbokun 17y agoWhich just goes to show we still have not made all the way back to where Lisp was a few decades ago.
- haberman 17y agoConsider that JSON has features Lisp does not. Like a tiny implementation, very wide language interoperability, being purely a data language (sandboxed by design), and not being Turing-complete (time to interpret is automatically bounded).
- jacquesm 17y ago> (time to interpret is automatically bounded). Well, at least for that particular set of cases I think you've just solved the halting problem ;)
- alrex021 17y agoYou are absolutely right. My point exactly. Now you need "two hammers" to get a single job done. Your current programming language of choice and a data expression language. For example: In C, C++, Java, or related, you "first" have to build you structure to represent a Person with first_name and last_name and then you have to write it to JSON: Java: class Person { String firstName; String lastName; } JSON with JavaScript evaluation: var names = [{"firstName": "John", "lastName": "Smith"}, {"firstName": "Bob", "lastName": "Jones"}] eval("(" + names + ")"); Lisp handles both naturally. You don't need intermediary human-readable data expression language. It comes natural to the language itself. Lisp ver: (defvar names '((:firstName "John" :lastName "Smith") (:firstName "Bob" :lastName "Jones"))) (eval names)
- psranga 17y agoThere are parts of all languages that I find confusing, but I'm a little puzzled by the general criticism of C++ (e.g., the __getitem__ feature of Python seems to be similar in spirit to operator overloading. Do people criticize Python too?). IMHO, C++ is an amazing extension to C which managed to increase productivity for those tasks for which C would have been the right choice (modulo non-standard compilers). If I were writing a performance-critical system-level program today, using C++ would be no brainer. You can fake a lot of what C++ offers with macros and function pointers in C, but lose type-safety and/or performance. I am very thankful to all the people who have brought C++ to the state it is in today.
- nearestneighbor 17y agoC++ sucks, why do all those idiots at Google use it? /sarcasm
- messel 17y agoIt's the only language I really feel comfortable programming in, and everything else seems 1) slow or 2) alien in comparison. I'm digging scala's design, but have yet to really compare it for number crunching, and big library building. By the way, the article didn't really dig into any specifics besides saying there was feature bloat in C++. Which languages don't have feature bloat? How much use can I get out of them?
- sshumaker 17y agoC++ is pretty awful to develop in, especially compared to many other languages. Some of these issues have to do with poorly designed features in the core language (templates), static variable instantiation, no good way for declaring complex data structures in the language (a'la JSON), multiple inheritance, etc. But this isn't just a problem with the core language itself, but with the compilation model and linkage model - and the compilers and linkers. You need include guards on the top of your header files to make sure the code doesn't get re-included. You have to aggressively forward declare to work around declaration dependencies. And you have to trim the files that you include to keep compile times under control, because here's the fun thing about C++: For every .cpp file in your project, you will end up reading in and parsing the same damn header files again and again. In a large project, that might mean recompiling the same header files 1000s of times. Precompiled headers aren't a good solution, either - because when you have to touch the header, you pay a huge cost in recompiling the PCH. In every other language I've used, I haven't had to worry about carefully restructuring code (sometimes at a cost in performance) to reduce compile times - because the core include and dependency mechanism sucks so badly. Finally, C++ as a language is very poorly extensible. By this, I mean in compared to languages like LISP (with macros), or Ruby / Scala, which both make writing DSLs very easy. This is especially unfortunate, given that is so heavily used in a lot of very specific domains. And don't get me started on templates - I couldn't dream up a more backwards and awkward way of doing generics if I tried.
- tptacek 17y agoI'm liking these Seibel digest posts more than I'm liking the actual book, which, even in the Norvig chapter, drags a bit. I think the book might have worked better if it was organized topically, instead of by person.
- known 17y agoIsn't C++ Compiler written in C?
- danbmil99 17y agothe point about everyone making their own sub-language is exactly right. In fact, I've heard programmers say that's exactly what they love about it. Problem is, every shop is inventing their own subculture. When programmers who haven't worked together look at each other's C++, they're basically learning a new language. I do think this has changed a bit in the last few years. The whole 'design pattern' meme exists primarily to create nexuses of style that programmers can gravitate to. It just seems like such a slow way home, especially in comparison to a language like Python, which goes out of its way to restrict the number of ways you can skin the cat. Has any serious programmer ever looked at a Python file and said "wtf?" for more than a minute or two? And, has any experienced programmer not had the experience of looking at a new batch of C++ (say at a new job) and thought to him/herself, jeez, this is going to be a lot of work just to understand the basics of what they're doing?
- c00p3r 17y agoHow could people complain on c++ when so many daily useful tools were written in it? Even their beloved JVM is a mere C++ program. Consider very successful and really cross-platform Webkit, V8, Mozilla's Geeko and so on. And there are thousands successful proprietary projects like Informix and even this popular MySQL. If Google, Mozilla and many others can productively use C++ why other people can't? They even published guidelines how to use stable and portable subsets of language.
- Jeema 17y agoOf course it's going to be more convoluted then newer languages like Java: Java doesn't have to maintain backwards compatibility with a 35+ year old programming language. That's just stating the obvious. Yet for some reason people still use it. The question is 'why'. For many cases (not all though), I think the reason is largely just institutional inertia - you stick with the devil you know rather than the devil you don't know.