12 ms·
I've been programming for money for over 20 years and I grew up professionally writing C and then half-migrating to C++, because the latter very naturally captu
by huhtenberg 10y ago
I've been programming for money for over 20 years and I grew up professionally writing C and then half-migrating to C++, because the latter very naturally captured lots of C patterns and allowed for more succinct expression of the same. It was lean, expressive and elegant. Just needed a bit of Lisp-y closures and it would've been perfect.
And then things got completely out of hand. Elegance was nuked from the high orbit in favor of "power features" and abstraction. Fucking Boost (I can't tone it down, sorry), move semantics, ass-backwards closures, meta-template programming - C++ that was easy to understand became something that would normally come out of self-indulgent academic research.
Again, I've been using C/C++ for all my professional life, so it pains me to say this, but what it has become, it's... it's just horrible. Anything - C, D, Python, Rust - is cleaner and more elegant than C++ and just as powerful. If nothing else, I feel sorry for Bjarne. What could've been a gem of programming languages became http://i.imgur.com/1oGHYqi.jpg http://i.imgur.com/1oGHYqi.jpg
- utopcell 10y agosome of the pain points you refer to, esp move semantics, bring a lot of additional performance to the table. Would you feel the same way about C++ if you started now and only had to learn a clean C++11 subset going forward ?
- maxlybbert 10y agoI've often wondered how anybody manages to teach C++ today. I love working with the language, and I understand the reason behind many of the features, but I can't help but feel like it would be impossible to teach to beginners.
- speedkills 10y agoMaybe they don't bother. PSU is still teaching C++98.
- maxlybbert 10y agoThat was the thing: starting with C++98, I was able to pick up C++11. But starting from scratch? I'm not sure.
- izacus 10y agoWe have a rather lagerish codebase of C++11/14 and we manage to get people coming from other languages (Java / ObjC) to start working with it just fine. Modern C++ is pretty decent and readable (excluding some quirks of STL naming). Of course good code reviews and testing is a must to help people to get up to speed and stop shooting themselves in the foot :)
- cmrdporcupine 10y agoWow I feel the opposite. Because C++98 and earlier were so deficient in a lot of ways, people who got clever with it often ended up down a rabbit hole of template metaprogramming, boost:: bloat, custom classes for callback stuff, custom classes for reference counting or other smart pointers, etc. etc. Unlearning all that took me some time. In my 5 years at Google, I've watched many developers start from scratch on our subset of modern C++. There doesn't seem to be a huge challenge with it.
- acqq 10y agoIs the subset of boost in Google still the same as the public one? https://google.github.io/styleguide/cppguide.html https://google.github.io/styleguide/cppguide.html It it is, I consider Google very lucky to have these who decided not to allow everything.
- _delirium 10y agoThe norm in the game industry is usually to expect some kind of background in low-level programming (maybe C, maybe some version of C++), and then teach new employees a very specific, restricted subset of C++ that's the in-house dialect (and every company has its own, different subset).
- baq 10y agothat's because it is impossible. it takes years to master the language and that was before i lost touch with it around 2010 back when C++11 was TR1 or whatnot. i understand that what is usually considered good form is trying to completely forget about C features like pointers and arrays and use their STL counterparts like unique/shared_ptr, std::vector, std::array and iterators. this gets you a nice modern subset of the language that makes it relatively difficult to shoot yourself in the foot.
- maxlybbert 10y agoI didn't use C-style string functions for the longest time. If I had a char*, perhaps because I got it from some C library we were using, I would turn it into a std::string and use it's functions and operators. One day, I realized how silly that was: I'm sure I was causing gratuitous memory allocations (not all strings qualify for the short string optimization). Perhaps part of my hangup is the expectation that you would teach the difference between, say, enum and enum class. There are good reasons to use enum, and I believe there always will be. There are good reasons to use pointers (in fact, one of the main reasons I use pointers is to point to the payload of a std::unique_ptr, and I use std::unique_ptr when I have an obvious owner, even if I might need other functions to access the payload while the owner is still around). So I don't think that it's possible to ignore "the old ways" completely.
- baq 10y agoit isn't possible if you're doing real work, but it is possible if you're learning or teaching, especially if stdin and stdout are the only ways your program will do IO. it's actually pretty nice and code is surprisingly concise, especially if you use stream iterators.
- kire456 10y agoFwiw, I followed this course at my university[1]. The 'schedule' and 'setup' links provide an idea of what is treated, and the full book is available[2]. The full course took slightly over six months, so yes, it takes a while :) 1. http://www.icce.rug.nl/edu/ http://www.icce.rug.nl/edu/ 2. http://www.icce.rug.nl/documents/cplusplus/ http://www.icce.rug.nl/documents/cplusplus/
- JackdawX 10y agoHere is the course I was taught by at university: http://www.dcs.bbk.ac.uk/~roger/cpp/ http://www.dcs.bbk.ac.uk/~roger/cpp/ Lots of value came from the lectures with roger. Sadly he has retired, it would have been nice to have them up on youtube.
- ant6n 10y ago"...but I can't help but feel like it would be impossible to teach to beginners." So a relatively easy way to learn C++ is as an 'upgrade' to C, starting of with picking the parts of the language that help you the most: * you start by already knowing C, but maybe not feeling super productive, using it as structs + functions * you set up the C++ compiler (most modern version available), and just continue writing C * you start using streams to print (because it can be more convenient than printf) * you start using std::vector and std::string, arrays being one of the big pain points of C * you start using `auto` and for-in loops * you start using simple classes, without any inheritance. just structs with methods * you start adding operators - so much fun! * you start learning about references and const, and suddenly all your method arguments become `const T& v` * you learn about not using pointers (as much on stack as possible), move semantics, shared/unique pointers. This means you'll also use more templates. * you deepen your understanding of writing your move/copy constructors. Learn RIAA, and become a fan of `}`. * you learn about constexpr and constexpr functions * this is already a pretty happy subset of C++, and as you learn to use templates, you may at some point start writing one yourself. Same with lambdas - if you need them you learn them.
- mlvljr 10y agoRAII, not RIAA :) RIAA (https://www.riaa.com/ https://www.riaa.com/) is the ebil music recording capitalists :)
- groovy2shoes 10y agoOne of C++'s most glaring problems is that everybody only ever uses some subset of some version of the language, but you still need to know basically the entire massive, monstrous language because not everybody uses the same subset and you need to be prepared for anything. On top of that, you're lucky if your employer or potential recipient of contributions (e.g., FOSS project) or whatever has actually codified the subset they want to you to use: most of the time, you need to infer the allowable subset from the existing code.
- pjmlp 10y agoIt applies to most mainstream languages, even Python has subsets.
- groovy2shoes 10y agoI've written code in over 50 different programming languages at this point (though only about a dozen or so professionally, including Python), and the only languages where I've ever been asked or required to work with a subset in lieu of the full language have been C++ and Perl. I've never worked on a project or for a company that allowed unrestricted use of all of C++.
- mmargerum 10y agoI would say Go is the first language since C where there is not really a subset to use. Every construct has a distinct purpose.
- groovy2shoes 10y agoI would say that's cute.
- deleted 10y ago[deleted]
- santaclaus 10y ago> move semantics Move semantics have been great, in my experience (enabling things like unique_ptr). What is causing issues here?
- fauigerzigerk 10y agoMove semantics are very useful, but there's also something wrong if articles like this are necessary or even possible: https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers https://isocpp.org/blog/2012/11/universal-references-in-c11-...
- bsaul 10y agoOh gosh... how come does anyone not realize what a dead end a language has become once this kind of article needs to be written ?
- jasode 10y agoScott Meyer's articles (and numerous video presentations) on Universal References are educational but he doesn't make it clear to the audiences the bigger picture of where and why they'd need to really learn it. The Forwarding Reference (aka Universal Reference) is for programmers writing generic templates. A lot of C++ programmers can do a ton of productive work and get by for years without writing any templates from scratch. Yes, they use others' templates (such as STL/Boost libraries) but they don't necessarily write their own. I have no survey data but I'll take a wild guess that less than 1% of C++ programmers need to memorize template Forward References. As an analogy using the plain C Language, it's as if someone created very prominent blogs about the complexity of "char ∗(∗(∗a[])())()" with long paragraphs explaining how it's "an array of pointers to functions returning pointer to function returning pointer to char". If that type of essay had a lot of visibility, people might think that "Wow the C Language is difficult and too complicated!" In reality, a lot of C programmers don't write complex declarations like that. The more common pointer-to-function for something like qsort() is very easy to write.
- HelloNurse 10y ago
- athenot 10y agoWhat you paint as a fault might be an asset: C++ is multi-paradigm. There is more than one way to look at something and there is a joyous chaos of varied abstractions from which to choose from. Yes it takes a certain openness of mind and a long learning curve. But then, you get to operate at a level that other platforms can only dream. In full disclosure, I do NOT consider myself a good C++ programmer. But I've always respected the fact that it's one environment which fosters using the whole toolbox instead of just a hammer... no matter how elegant that hammer may be. In that respect, it reminds me a lot of Perl.
- segmondy 10y agoHow well has Perl fared? How about Lisp and Scala that are multi-paradigm, how well are they doing?
- GFK_of_xmaspast 10y agoPerl was doing just fine until they fell in the perl6 hole and stagnated. Scala's getting its data science niche, and lisp has a lot more problems than just being multi-paradigm.
- gpderetta 10y ago> Perl was doing just fine until they fell in the perl6 hole and stagnate i.e. backward compatibility is king. Paraphrasing Stroustrup, there are two kinds of languages, those that are full of old cruft and those that are too green to have been proven in the field.
- GFK_of_xmaspast 10y agoThe perl6 problem wasn't 'backward compatibility', the perl6 problem was 'this thing doesn't exist at all but it's sucking up all the momentum.'
- huhtenberg 10y ago> C++ is multi-paradigm Yep, here it is - http://i.imgur.com/1oGHYqi.jpg http://i.imgur.com/1oGHYqi.jpg :)
- arximboldi 10y agoInteresting that you mention Rust... I am one of those "modern C++" kinds and I am quite curious and excited about Rust (haven't quite jumped boat yet though). I feel that there are quite a few others in such position. And precisely the reason we like Rust is because it is like the new C++ (moves, lean lambdas, templates, on-the-stack values, borrowing) without so much of the old stuff. What do you think? What do you expect from Rust?
- blub 10y agoThat pocket knife is a collector's item. It includes most if not all the individual tools available in different models from Wenger. Victorinox also has one. The problem is that it's not useful as such and I guess most people wouldn't buy one. I wouldn't mind receiving one as a gift though :) Regarding C++, if I remember my programming language history right, there aren't many languages that are that old, popular, available in so many domains and still evolving to keep up with the times. Language design has progressed a lot, the hardware has advanced at an exceptional pace. Today's context is very different. I say we wait another 20 years to see how Rust & D are doing. Python might be old, but it only really became popular this century, as Perl declined. I estimate that C will continue its slow decline with time.
- ytugiuyghvk 10y agoWhat's wrong with C++'s closures?
- spoondan 10y agoThis is perhaps one of the more unexpected opinions on C++ I've encountered. When I picked up C++ with Turbo C++ 3.0 in the early '90s, it was already widely regarded as an over-complex behemoth. Donald Knuth said of it in 1993, "Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said 'OK, we'll do them both'. So the language is too baroque for my taste." The last twenty years, there's no C++ that I would call lean, expressive, and elegant. You give the example of template meta-programming as something added more recently, but Erwin Unruh was printing the primes in compiler error messages not long after Knuth was knocking C++ as baroque. It makes me wonder if perhaps the issue isn't simply that over time you've become more aware of how complex the language has always been? The language has continued to grow, but it's growing in a rather different direction (or rather in a clear direction): towards a modern, preferred subset that _is_ lean, expressive, and elegant. While C++ is still far from my favorite language, I find C++ today to be far simpler, more expressive, and more elegant than at any other point in the past.
- cmrdporcupine 10y agoArguably the std::move stuff and the semantics around it have added uncomfortable complexity to the language, even if it might have been necessary. Other than that I think other advances in C++11 and beyond have made for a quite nicer language to work in. I love C++11 and use it every day, but I think putting references in the language was an 'original sin'. They should have stuck with C's model: it's either a value or a pointer to a value. References just added a pile of complexity and pontificating about whether something was being copied, moved, or passed by reference.
- JoeAltmaier 10y agoSurely references have intrinsic value to the programmer? They're a pointer that can't be moved or rebased. Other languages have only references, and in C++ you can use that convention and not have any extra confusion.
- makecheck 10y ago
- sandeatr 10y agoThe things you are complaining about are what make the language worth using-
- hacker_9 10y agoI agree. The other day I had to dive into the libigl [1] matrix structure (for those that don't know, a matrix is basically a 4x4 grid of numbers). What I found was over 10 levels of inheritance, along with rampant template use and macros _everywhere_. It actually took so long to parse I ended up just changing my algorithm completely to avoid having to use it. I have utmost respect for anyone that can work with C++ day to day, but I'll be staying away thanks. [1] https://github.com/libigl/libigl/ https://github.com/libigl/libigl/
- rkangel 10y agoThe problem is that you can find bad code in any language. It's difficult to tell how much that is the fault of the language, and how much is the fault of that particular author. I'm not defending C++ here, I actually agree with you, but it's difficult to provide decent evidence for its failings.
- cbsmith 10y agoOdd. I wonder why they didn't just use Boost uBLAS or similar.
- dimatura 10y agoDoesn't libigl use Eigen for matrices? Eigen is a full-featured matrix library with a pretty decent API. If you just need a 4x4 grid of numbers, then you don't really need a library, sure. But once you need to do matrix arithmetic, basic linear algebra, various forms of indexing, mixing matrices of different types (e.g. float/double/int/etc), things get complicated, fast. A complex library like igl needs all this and more. I'm guessing this is why there's so many matrix libraries - everyone prefers rolling their own, after all, how hard can it be? (I'm guilty of this, so I'd know. But I reach for Eigen most of the time these days).
- KKKKkkkk1 10y agoBut C++ was never easy to understand. For example, can you tell me off the top of your head, what are the conditions to get the compiler to generate a copy constructor and an assignment operator for a class? I have trouble answering that question even with the help of Google, and you're talking pre-Google times.
- sqeaky 10y agoThe rules really aren't that hard for practical use. Of course pedantic rules in the standard are much more complex and corner cases can bite us. If you define no constructors then the compiler will generate a default constructor with no args, a copy constructor, a move constructor and an assignment operator. If any class data members don't have one of those then the class you are writing won't have one either. The simplest practical rule is define none of them or define all of them. It is not often, perhaps one in ten classes, that you should do something else. If wind up using C++ for more than a small project, than you ought read up and not use simple heuristics like this.
- andrepd 10y agoTemplate metaprogramming is not something new, it's old, and indeed much of Modern C++ (e.g. constexpr) is made to replace the complicated TMP with simpler and just-as-powerful abstractions. Can you name another language that supports the many high-level abstractions that C++ supports (OOP, generic programming) while being just as fast? Only D and Rust come to mind, and they are neither as fast nor, crucially, as well-developed as C++. The amount of resources and existing code in C++ is staggering. Newer languages such as D and Rust simply can't compete.
- waynecochran 10y agoAda.
- steveklabnik 10y agoIf Rust is slower than the equivalent C++, that's a bug. Please file them.
- groovy2shoes 10y agoModula-3. Bonus points are awarded to Modula-3 and Rust for safety.
- kitd 10y agoI returned to C++ 3 years ago, having previously used it in the mid-1990s. I tend to agree with you, but I found that it was necessary to forget my old C mindset (pretty easy since it was 20 years old) and start learning modern C++ idioms from scratch. Eg, back in the days, I could fling raw pointers around with abandon. Now they need to be handled with care, and there are many tools and patterns available for you not to have to deal with them at all.
- VodkaHaze 10y ago> fling raw pointers around with abandon. Jitters in seat
- shmerl 10y agoC+11 is a different language. Learn it ;) And move semantics is a good thing. If you are fed up with C++ though - try Rust.
- zwieback 10y agoI feel your pain but the canonical response is that you don't have to use the new features if you don't want to. If you have to work with other people's C++ code you may be in trouble. I have the same arc as you, but every time I come back to C++ (from C# or Python) I'm surprised how much I enjoy it. I look at the new stuff more as a way to bring features from scripting or functional languages to a real language - makes me happy.
- gpderetta 10y ago> ass-backwards closures that's very surprising. I would say that C++ lambda expressions have been an incredible success and probably the best thing to come out of C++11. For example, rust started with boxed closures, because that's what all the 'proper' languages do. They were forced to switch to distinctly-typed, unboxed closures with similar capture modifiers to be competitive with C++ [1].
- steveklabnik 10y agoYour link got eaten, but we don't have capture modifiers anymore. Captures are inferred, and you can override this with a keyword to take all captures by value instead. This still lets you get the same effect as C++, but we find that it's generally less verbose. It depends though!
- gpderetta 10y ago> you can override this with a keyword to take all captures by value instead that's what I meant by modifiers :). It is not unlike [&] and [=] I guess (except for the "tiny" detail that lifetimes are checked). BTW, I'm not sure what the [1] reference in my comment was supposed to point to though.
- otabdeveloper 10y agoC++ occupies the same mental space that languages like Haskell, Scala or OCaml. Compared to its real competition, C++ is very elegant and a joy to use. These languages are meant for enjoying the maximum out of compile-time type abstractions, not as an easy-to-use tool for simple enterprise apps.
- jimktrains2 10y agoI've come back to learn C++14 and it's _really_ nice. I love how lambdas, move semantics, templates, type inference, &c work. It leads to much cleaner and elegant code. I'm still not so sure I like how iterators are designed, but maybe it'll grow on me?
- kazinator 10y ago#include "parent-comment" Me too, exactly. C++ has turned to baroque junk. The last useful new feature C++ acquired was to make string literals const. (When was that, 2005 or 6?) If you're using C++, it's best to stick with C++03. The rabid experimenters who run the ISO C++ committee should have started their own language 15 years ago, rather than hijacking an industry standard to everyone's detriment.
- cbsmith 10y agoThe mistake is looking at C++ as just an enhanced C (understandable given the name, the marketing, etc.). It's kind of like when they marketed Windows as a DOS upgrade... In reality, C++ is an entirely different language that provides partial C compatibility (in fairness, it is more compatible than just about any other language out there) in order to improve adoption and minimize the impedance mismatch with systems interfaces (which, at least back in the day, were predominantly C, and largely still are). If we called "C++" "NotC", and then wrapped all the C compatibility features (type coercion, malloc()/free(), C strings, etc.) with a "unsafe mode" flag, it'd all make much more sense.
- alpineidyll3 10y agoThe less I use C++ the happier I am.
- MichaelMoser123 10y agomove semantics helps you to get rid of temporary objects. otherwise Object a,b,c; ... a = b + c; will create a temporary for b+c before it is assigned to a. The elegance of operator overloading got us there - no need for it without operator overloading. Me too thought that template meta-programming is just a waste of time; i was surprised that std::tuple uses this stuff.