7 ms·
C++ and the Culture of Complexity
- wheaties 13y agoBeing a recovering C++ programmer who wrote some very clever code while younger and very dumb code while older, if you think Java gets out of your way perhaps you should try Scala or Clojure. Talk about getting out of the way, these LAn guages are something of a wonderment. Every day I get to code in them is a good day. It's true, you won't have the "power" of C++ but if you need that there's C.
- thebear 13y agoAuthor of blog post here: I haven't found the time to do much with Scala or Clojure, but my impression so far agrees with what you say. Thanks for reminding me: I need to seriously try out Scala and Clojure!
- bnolsen 13y agoI've seen some programmers get fancy and try to overengineer what they are doing. It's the temptation of premature optimization. They just need to be forced into doing some maintenance and refactoring work for a while to realize how much fancy code really sucks.
- kartoffelsack 13y agothe wow effect in c++ 'yeah i can do this cool stuff i read about in another language also in in c++. i just have to use this fancy lib and its really cool what you can reach with templates.' i foud always stunning. anyway it is no good for efficiency - but having worked with c++ for some years makes you vety efficient in more simple languages. i ser following drawbacks of c++ - the default is very often not what you should do. this is the price for backwards compatibility this makes it hard for the novice but you get used to. - the incredible long build times esp when working with modern libs. how many hours did i spend waiting for the compiler and how many for optimizing ny precompiled headers. this is really a produxtivity killer. its has also historical reasons but i dont understand why no proper module system gets depeloped - the lack of support for runtime errors. for 7 years i have not seen a crashing java program without giving me a hint where it crashed. and actually i have seen far less total crashes. in c++ you do one small thing wrong and the whole program ends with an abnormal program termination and you dont have any clue what happened.
- kartoffelsack 13y agothe wow effect in c++ 'yeah i can do this cool stuff i read about in another language also in in c++. i just have to use this fancy lib and its really cool what you can reach with templates.' i foud always stunning. anyway it is no good for efficiency - but having worked with c++ for some years makes you vety efficient in more simple languages. i ser following drawbacks of c++ - the default is very often not what you should do. this is the price for backwards compatibility this makes it hard for the novice but you get used to. - the incredible long build times esp when working with modern libs. how many hours did i spend waiting for the compiler and how many for optimizing ny precompiled headers. this is really a produxtivity killer. its has also historical reasons but i dont understand why no proper module system gets depeloped - the lack of support for runtime errors. for 7 years i have not seen a crashing java program without giving me a hint where it crashed. and actually i have seen far less total crashes. in c++ you do one small thing wrong and the whole program ends with an abnormal program termination and you dont have any clue what happened.
- PommeDeTerre 13y agoC++, Java and JavaScript each have their own different kinds of complexities. The complexities of C++ almost always arise out of the extremely high degree of power and flexibility it offers programmers. The complexities of Java end up having to do with hyper-"architected" class libraries, rife with excessively-used design patterns to the point of being incomprehensible. JavaScript's complexity arises due to core functionality that's missing (such as proper class-based OO, namespaces, and proper support for modularity), or core functionality that's limited in practice (like it's prototype-based OO), or core functionality that's unjustifiably broken (its comparison operators, semicolon insertion, its scoping, its type system, its awful standard library, among others). Out of those three, JavaScript's complexities are by far the worse. The flaws are outright stupid to being with, and there's nothing that can really be done to avoid them in many cases. At least Java programmers can choose not to create and use bloated class hierarchies, for instance. And at least C++'s complexity offers superbly powerful features and excellent performance, and at least it's understandable how and why this complexity thus arises.
- mwcampbell 13y agoYou seem quick to denigrate JavaScript, and programmers who willingly choose it, wherever you can. But with regard to the kind of complexity the OP discusses, which roughly translates to added cognitive load, it's not at all clear that JavaScript is worse than C++ -- and I have real experience with both. To avoid dismissing C++'s complexity too easily as simply the price of flexibility and performance, let's review what C++'s complexity looks like in practice. For example, read this: http://simpleprogrammer.com/2012/12/01/why-c-is-not-back/ http://simpleprogrammer.com/2012/12/01/why-c-is-not-back/ Memory stomping bugs; all the ways to initialize a variable of a primitive type; copy constructors; overloaded assignment operators; move semantics; smart pointers; value versus reference semantics; the list goes on. Against the cognitive load imposed by complete control over memory management, and lack of verifiable memory safety, JavaScript's warts seem quite minor to me. I imagine that many programmers who work in "managed" languages would agree.
- thebear 13y agoAuthor of blog post here: Thanks for your lucid remarks. JavaScript certainly has its share of annoyances, but likening those to the complexity issues of C++ seems inappropriate to me.
- betterunix 13y ago"Few people would disagree that assignment between variables is part of the design of a language" Perhaps so, but those that do disagree might be worth listening to: https://en.wikipedia.org/wiki/John_Backus https://en.wikipedia.org/wiki/John_Backus
- swinglock 13y ago> Trying to impress people with your code rather than with your software is a sign of immaturity and bad engineering. That depends on what you think is impressive. A project that has clear and simple code is impressive, in any way needlessly complex and difficult to understand code is not.
- thebear 13y agoAuthor of blog post here: Thanks, good point! What I meant was, "Trying to impress with the complexity of your code..." I'll change that in the blog post.
- dkirkman 13y agoTo be fair, the c++ programmer can also use reference semantics via pointers. Granted, garbage collection is not built into the language, but if desired, we can always write java-style code by using pointers for everything and using the Boehm collector. I don't know why we don't do this more often, most c++ codebases seem to have large sections that would benefit from such a style. But when we want to use value semantics, for whatever reason, the more complicated value copy is, to some extent, just intrinsically complicated. In java, Object.clone basically has all of the same problems -- you sort of know what you'd like it to do for any given object in any given context, but you've got to read code to figure out what is actually going to happen.
- pcwalton 13y ago> I don't know why we don't do this more often, most c++ codebases seem to have large sections that would benefit from such a style. Because you will sacrifice performance over Java's GC. For maximum performance you really want precise garbage collection on both stack and heap, with generational concurrent operation and a two space copying collector in the nursery. Boehm can't provide this, because the language is not designed for GC.
- adamnemecek 13y ago> you really want precise garbage collection on both stack and heap This might be a dumb question but what run-times have a garbage collected stack? I Googled around but did not really find anything.
- pcwalton 13y agoI don't mean a garbage collected stack per se (though since you asked, SML/NJ has this, as do several Schemes). What I mean is that precise stack maps or register tagging is used so that the roots can precisely be found on the stack.
- jandrewrogers 13y agoA lot of the nominal complexity of C++ is the result of the very precise control it offers over software behavior. In many programming languages this level of control is not even expressible. That extra level of control only seems like unnecessary complexity until you are designing software systems that require this level of control. At a minimum, precise control of memory management is absolutely essential for things like servers and database engines if performance matters at all. That the author thinks C++ is competing with Go betrays a narrow perspective. There are many important things you can do in C++ that are not possible in Go, in part because of the features that make C++ "complex" that simpler languages do not have. As an obvious example, the renaissance of C++ for high-performance server systems is based in part on the fact that garbage collectors are a major drag on performance for these kinds of codes. Which is not to say that C++ is not excessively complex, just that the author seems to lack an understanding of why some of that complexity is essential functionality.
- cmbaus 13y agoPersonally I think the notion that C++ offers "precise control" as you call it is overrated. For instance flexible memory allocation is touted as an advantage, but in practice this is limited by the fact that there is only one global implementation of new the operator. Over the long term I think Go is going to offer a much more sane environment for implementing high performance servers.
- mpyne 13y agoC++ does allow overriding the new operator, actually. It also allows for running just the constructor in an area of already-allocated memory, if you're particularly crazy. With that said it's hard to argue that Go makes concurrency easier at this point, which can certainly make it more useful for many of the types of problems programmers are seeing today.
- cmbaus 13y agoI realize this, but you can't provide multiple global implementations of new. It is difficult to implement multiple allocation strategies in the same application. In another time, I actually did quite a bit of work in this area: http://accu.org/index.php/articles/1308 http://accu.org/index.php/articles/1308
- pcunite 13y agoGiven what we know today, yes a new language is warranted. The reason I've stuck with C/C++ is because everything I've ever written still works. Meanwhile my friends are playing with new languages every year (and all the books, classes, and conferences to go along with them). All the new syntax's seemed driven by corporations vying for mindshare (money), not the betterment of our industry. Give us a real alternative that is community driven and standardized. It needs to compile everywhere, have the option of a great IDE, and have libraries that make sense. We don't need another cute or toy language (JavaScript's 10 day incubation that I'm stuck living with now). Until then ... C++ is what we have.
- PommeDeTerre 13y agoRust has the most potential at being a true successor to C++. But it's not very usable at the moment (it suffers from far too much change within the language and standard libraries), and it will still take a lot of work before it is a production-grade language.
- thebear 13y agoAuthor of blog post here: Interesting that you say that. I came really close to saying in the blog post that Rust could be the alternative to C++ that I am looking for. But then I decided that I know way too little about Rust at this point to make that statement.
- mpyne 13y agoThe one thing with Rust is that it seems to me to also offer so much fine control on memory ownership that it would start to develop its own set of "gotcha"s. With that said I'm looking forward to seeing progress on the language as I think we've been needing a systems programming language where you can express ownership semantics as part of the language itself, and have the compiler check those for you.
- mpyne 13y agoD seems like a pretty good candidate as well (and even has some development effort from Alexei Alexandrescu, who has authored many good C++ programming volumes).
- nicholassmith 13y agoC++ is hard and complicated, but it's very useful if you're strict with it. I agree with the authors post though, there's a lot of inherent complexity that's non-trivial to solve and often leads developers to try and be clever rather than building strong software.
- zwieback 13y agoThis is one of those articles that really resonated with me although I feel a little uncomfortable admitting it. I think C++ is a great language but what Becker says rings true to me. Of course I've always been of the "safe-subset" mindset, e.g. the project and team should dictate how fancy your C++ should be allowed to get.
- alextingle 13y agoTotally agree. C++11 was a huge disappointment to me - rather than taking to opportunity to make changes that would help attract new C++ programmers, the committee decided to allow the "C++ nerds" to pile on even more complexity to their already overwrought libraries (cough boost cough).
- PommeDeTerre 13y agoC++ is a tool for power users, not a popularity contest. Changes to the language should not be done just to attract more users. This is especially true if these new users would be today's PHP, JavaScript and Ruby users. The C++ community is much better off without these kinds of programmers. It's much better for people to use C++ when they realize that they need the powerful functionality it offers, rather than dumbing down C++ in a way that'll make it attractive to less-skilled developers.
- betterunix 13y ago"It's much better for people to use C++ when they realize that they need the powerful functionality it offers" Relevant anecdote: I know a number of C++ programmers who said they would use Haskell / Python / etc. to "prototype" a system, then switch to C++ when they needed what C++ has to offer. None of them made the switch back to C++ and their "prototypes" became finished products.
- PommeDeTerre 13y agoLanguages like Haskell and Python being suitable for many applications in no way changes the fact that there are many other situations where they would not be suitable, and a language like C++ would be needed. Keep in mind that there are also many cases that are the opposite of what you describe. I've worked with many systems that were initially implemented in a non-C++ high-level language, yet the developers had to go back and start incorporating C or C++ code at some point for various reasons, if not re-writing the entire system in C++. The hybrid approach that Python allows for is extremely powerful, given how it makes calling down to C and C++ code from Python code quite trivial, or embedding a Python interpreter within existing C or C++ code.
- comex 13y agoI'd like to see a language with the power of C++ without some of its complexity. As noted elsewhere in the thread [1], there are a lot of features that just aren't necessary for the combination of performance and expressiveness C++ offers; on the other hand, while C is simple and can usually offer equal or better performance, its lack of templates hurts its expressiveness badly. But Java or JavaScript? If your performance needs are satisfied by those languages, great, but you're not the target audience - not today, anyway, now that those languages exist and are reasonably fast. But if not, good luck trying to beat the JVM into doing what you want. [2] [1] https://news.ycombinator.com/item?id=6266633 https://news.ycombinator.com/item?id=6266633 [2] http://marc.info/?l=git&m=124111702609723 http://marc.info/?l=git&m=124111702609723
- javert 13y agoIf C++ was originally "C with classes," has anyone invented a "C with templates"? Might not be a bad idea.
- vilya 13y agoI got the impression that's what the Clay language [1] was aiming for, but progress on it seems to have stopped around a year ago. [1] http://claylabs.com/clay/ http://claylabs.com/clay/
- seanmcdirmid 13y agoThere are plenty of use cases where Java is too complex and performance is even less of an issue, so Python and Ruby become viable. There are plenty of points up and down the perf/productivity gradient. I didn't think anyone uses Javascript unless they had to because the code needed to run in the browser.
- comex 13y agoYou must not have heard of node.js :)
- 13y ago
- ExpiredLink 13y agoThe problem with C++ isn't complexity but unnecessary complexity. As the author points out this is a cultural and not an 'inherent' problem (people who claim that a language like C++ must be complex are simply wrong). C++ did not start out as complex language, though. Quite the contrary. Just take a look at early C++ books. The turning point happened in 1995 when Stroustrup switched the C++ paradigm from object-oriented to the functional inspired 'STL paradigm' (remember 'multi-paradigm'?). Afterwards a clique of 'Boosters' (nomen est omen) took over the language development and bloated C++ to the current mess. In evolutionary terms: C++, a versatile mammal that developed into a dinosaur.
- claystu 13y agoThat quote by Bjarne Stroustrup: "I--and my colleagues--needed a language that could express program organization as could be done in Simula...but also write efficient low-level code, as could be done in C." in Masterminds of Programming, p.2 (Interview with Bjarne Stroustrup) O'Reilly Media, Inc. (2009) A truly great read...
- thebear 13y agoAuthor of blog post here: Thanks! I'll add that to the blog post.