14 ms·
C++17 – better than you might think
- alextooter 10y agoThe only problem of C++, it has a wrong Standards Committee.
- koja86 10y agoWhy so? Genuinely curious.
- geezerjay 10y agoC++'s standardization committee is known for being enthusiastically pro-Microsoft. IIRC, C++'s thread support is essentially the option that Microsoft forced upon the standard, in detriment of ISO's very own pthreads library which was already an ISO standard. IIRC, the same problem also plagues C's committee.
- Scea91 10y agoC++'s thread support is basically boost.thread with some differences. Can you explain in which way is it Microsoft over pthreads?
- octoploid 10y agoBuild-in sum types and pattern matching are the major missing features. Instead C++17 will have library hacks like std::variant, that almost certainly will be deprecated for C++20.
- hellofunk 10y agoThey would be deprecated only if the features you are missing are actually on their way into the language. Are they? I agree those features would be nice, but I've never seen any mention of them actually planned.
- octoploid 10y agoSee: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0095r1.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p009...
- revelation 10y agoModules seem much more important than either of those. You know where you include a platform header and suddenly you can no longer call a variable "min" because said platform header decided that should be a macro and it's giving you cryptic errors because what you see isn't what the compiler sees. I've written too much C++ to be dumbfounded by that stuff but that doesn't mean I'm not still bitter about it.
- gpderetta 10y agoWhat platform would ever put a three letter macro in its base headers! That would be stupid. /s
- maccard 10y agoIn fairness, It's a well documented problem with a ery easy solution. I wonder how much code would break if they removed it..
- loup-vaillant 10y ago> Modules seem much more important than either of those. Modules solve an immediate and obvious pain: unacceptably long compile times. Sum types are more profound. Anyone having tasted an ML derivative (as I have) would dearly miss them. Seriously, once you've tasted sum types, you'll want to use them everywhere: option types, error returns, abstract syntax trees (JSON, XML, compilers…), you name it, sum types probably solve it. Sum types are no panacea, but if you squint your eyes just right they're pretty damn close.
- revelation 10y agoI've tasted sum types and if I was trying to be snarky I'd say so have millions of Java enterprise developers who fill their code with a healthy dose of instanceof and null :) It is somewhat anathema to the OO idea and brings lots of (runtime) implementation concerns so I can understand the delay.
- tines 10y agoWhy would variant be deprecated for C++20?
- gurkendoktor 10y agoMore features, more libraries, but is there a working group that looks back at C++98 and tries to reduce complexity by removing mistakes from the language? My pet peeve is Argument-Dependent Lookup. It's a hack that breaks the encapsulation of namespaces, increases compile times and still makes it harder to write code - try swap()ing two values of type T in a template function. But like any of C++'s warts, it will be with us forever.
- rl3 10y ago>More features, more libraries, but is there a working group that looks back at C++98 and tries to reduce complexity by removing mistakes from the language? Then you break backwards compatibility. What about static analysis to enforce a particular subset of features deemed idiomatic or otherwise best practice? Granted, reducing complexity does make the job of future compiler authors far less miserable.
- ktRolster 10y agoWhat about static analysis to enforce a particular subset of features deemed idiomatic or otherwise best practice? I like that idea.
- koja86 10y agoYou might find this project kind of interesting: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC... As a day-to-day C++ practitioner I like it. ...Yet I am not fully convinced that the general idea of language evolution implemented as ruleset outside of the language itself is the way to go. Seems more like band-aid to me and made me start to think about concept of programming language's life cycle in context of Darwinian evolution - once either legacy compatibility burden is too big or that particular biotope of specific problems the language solves better than others vanishes/changes the language dies out. My particular issue with C++ is that it's complexity, longevity and evolution made possible for widespread bad-practices as not every C++ developer evolved as much as the language itself and it's general public understanding. (Some current best-practices were simply not always widely known or accepted.) I would even go as far to say that most of existing C++ code is crap (at least from standpoint of today "modern" C++). And that's why I am both eagerly looking to "next generation" being shaped up by people who has (hopefully) learnt from past mistakes and used by people who care (itching to give Rust a ride once it stabilizes just a bit more) and also occasionally digging in the history for possible gems that I might not able to see without my current experience (platonic weekends-only relationship with Haskell, Lisp being right there at top of my TODO list). EDIT: Removed the sir.
- mlvljr 10y agoHas the issue behind http://scottmeyers.blogspot.ru/2016/11/help-me-sort-out-meaning-of-as.html http://scottmeyers.blogspot.ru/2016/11/help-me-sort-out-mean... been hardened? As obviously wouldn't count otherwise :)
- daurnimator 10y agoThe thing I want most is for them to deprecate misfeatures. C++ code can be impenetrable as the language is so large and complex.
- TillE 10y agoI never, ever hear this as a priority from fellow C++ programmers. It's always just on HN. If you're actually working with C++, old "misfeatures" simply aren't something which gets in your way very often. You can just code in the modern way and be happy.
- Doctor_Fegg 10y agoBut if you're not already working with C++, just trying to learn it, it does make C++ harder to pick up.
- daurnimator 10y agoNot everything is a new cleanly constructed codebase. I regularly have to jump into and fix/debug existing C++ projects. Often issues are due to accidental interaction between poorly understood features, or a misunderstanding of what a given syntax/idiom does. Every feature/syntax added to C++ is one more place mistakes can happen, and one more thing to watch out for when debugging. I wish there was someone in a position of C++ power pushing to remove a feature for each one added.
- DougBTX 10y ago> Not everything is a new cleanly constructed codebase. This is true, in lots of ways. Lots of code is rushed, corners cut, so was bad the moment it was written. Other code is written in a particular style, and would need to be cleaned up to match a more modern style. One benefit of backwards compatibility within one language is that these pieces of code can be improved incrementally, without having to switch languages. So, a road to improvement, rather than a source of mistakes. The key is to make the new code better than the old code!
- gpderetta 10y ago
- ktRolster 10y agoI used to write C++ for a living, but now it's changed enough that I feel like I don't even know the language anymore.
- mlvljr 10y agoI used to write C++ for a living, ...but then got a variadic template in the knee :)
- sanatgersappa 10y agoC++: an octopus made by nailing extra legs onto a dog.
- 0xFFC 10y agoVery nice expression! One of the best expressions i have heard about C++ is "C++ is feature adding contest, they add ao much feature in every cycle it seems they are in hurry"
- gpderetta 10y agoAnd we like it that way :)
- pjmlp 10y agoJust like any other language of similar age and industry adoption.
- ue_ 10y agoI doubt you could say much the same about C, which is not only older than C++, but with similar industry adoption (albeit at a different place in the stack nowadays).
- pjmlp 10y agoHave you ever tried to make a portable C application using multiple C compilers (not gcc or clang) across multiple OSes (not only POSIX)? It is lots of fun with extensions not covered by ANSI C and compiler specific behaviors.
- ci5er 10y agoI have - although POSIX covered a fair number of them and POSIX-ish or pretend-to-be-POSIX made up some more. That could all usually be covered with a pretty thin utility layer, and the compiler-of-the-day for whatever the platform was. (and, sometimes, a whole lotta #IFDEFs!) You must be talking about something more extreme, maybe in embedded land? Do you happen to have a small number of f'rinstances?
- eb0la 10y agoThere is a good free eBook from O'Reilly about C++14 worth reading: "C++ The Beast is Back" http://www.oreilly.com/programming/free/c++-today.csp http://www.oreilly.com/programming/free/c++-today.csp
- alkonaut 10y agoI want a list of things removed not a list of things added. Backwards compatibility is a strength, up to a point.
- Qantourisc 10y agoMaybe we need a standard C++17-depricated/old ? In which the standard defines which features should no longer be used ? This should be optional for compiler to implement though.
- geezerjay 10y ago> Backwards compatibility is a strength, up to a point. That point being actually having to build software that was already written.
- alkonaut 10y agoI can always just build my legacy code with a compiler that supports it.
- loup-vaillant 10y agoSomeone downvoter may not have understood that several compilers can still produce object code that can be linked together. Reminds me of C++ itself. Stroustrup posited that it needed syntactic compatibility with C. People had to be able to compile their own code with the new compiler, else his new language would never have been used. I'm sad to admit he was probably right. He could have settled for linking compatibility, where old modules can be used from new code (and conversely). But that probably wouldn't have worked, if only because nobody wants to deal with 2 compilers and 2 slightly different languages. Also, macros and header files. Seriously K&R, what were you thinking? Still, this is a possible path forward. To hell with syntactic compatibility, the ability to link the object files should be enough. That would at least let one use legacy libraries with the old compiler, and write the current project with the new stuff. There's just one hard part: the FFI must be seamless.
- zanny 10y ago
- fauigerzigerk 10y agoThere is one real problem with "modern" C++ that I would have hoped they would focus on: Compile times. All the new stuff is heavily template based. As more libraries are written in that style, compile times go through the roof. I wrote some code recently that required high precision monetary calculations. So I used boost multiprecision. It turned out to be completely impossible as most compilation units ended up depending on that library directly or indirectly. Already slow compiles became unbearably slow. Facing a tight deadline I quickly wrote an extremely ugly, slow, error prone, pimpl based wrapper around boost multiprecision. Many calculations now require dynamic memory allocation for no good reason. This is just terrible, because I know I can't leave it like this. I'm going to have redesign the whole thing or look for other libraries or look a lot more deeply into the calculations to see if they really cannot be done with large integers. It's a productivity disaster. You could say I made wrong choices, which is true, but I think the C++ standards committee has been making wrong choices in not prioritizing a fix for compile times (modules?). What's the point of having nice new features if you end up spending half your time on carefully cordoning off any code that uses them?
- my123 10y agoAnd existing compilers that do not support them and that you still have to support...
- melling 10y agoModules are suppose to help with compile times. They never seem to make it into the standard. Must be a few outstanding complications.
- koja86 10y agoThere are others who feel like us. Fingers crossed: http://clang.llvm.org/docs/Modules.html#problems-with-the-current-model http://clang.llvm.org/docs/Modules.html#problems-with-the-cu...
- jzwinck 10y agoTo speed up parallel compilation, use icecc. It's great if you half even two or three computers on your LAN. For high precision currency, use int64_t (perhaps in a simple POD class). This, with an 8-digit implied decimal part, is enough to represent the finest price unit in any market today, with a max of 92 billion. If you are dealing with more than 92 billion of any currency in a single place, don't complain!
- NKCSS 10y agoI wonder why it feels like I can't move at the same pace with C++ compared to C#; want to have a file copied to your output dir? Create a post-compile task; with C# you can just set a property to 'copy always'. Want to add a reference? Set up which dir's to look for, type names, etc. with C#: add reference, choose your dll/whatever and you're done! And those are just a few. One of the biggest hurdles with C++ is type conversion; I recently wrote a small app; most time was spent writing functions to cast/convert all the 9000 ways to define numbers and strings... It's when you start to appreciate the System.Object model that makes sure everything can be represented as a Unicode string that everything knows how to work with.
- koja86 10y agoYou are comparing apples to oranges here. I also agree that type system in C++ is not perfect and is rarely used in a sensible manner. Yet I would rather look for inspiration in functional statically-typed languages rather than in specialized "multi-paradigm" dynamically-typed ones.
- NKCSS 10y agoI know it's not fair, but because I write identical apps in both languages, it's one that comes to mind frequently and it becomes very apparent how powerful C# is when it comes to Rapid Application Development.
- nicolapede 10y ago> dynamically-typed ones Why you consider C# to be dynamically-typed?
- blakeyrat 10y agoJust as an FYI, C# is more strongly-typed than C++.
- psyc 10y agoOn the flip side: Want to read a file of records into an array of structs?
- faragon 10y agoPlease, KISS, professor Stroustrup.
- deleted 10y ago[deleted]
- pklausler 10y agoYou're asking somebody who makes money selling thick expensive self-obsolescing books explaining an obscenely complicated programming language to simplify the language?
- creo 10y agoThis is why in TLDR fashion: "[...] if you take them (promised big language features) all together - or even just two or three of them - they have the potential to change the language[...]"
- tempodox 10y agoWhat's a “TS”?
- bborud 10y agoTo be truthful: the older and more experienced I get I can't help but wonder why on earth people get so stuck in C++. To me the sheer weight and complexity of C++ appears meaningless. We know better now than we did in the 80s. Yet people spend their lives trying to fix C++. Why?
- Klockan 10y agoBecause there are many billions of lines written in C++ out there that we still want to maintain.
- IshKebab 10y agoUntil Rust there was no real alternative. All other 'better' languages use a garbage collector which is a no-go in most of the situations where C++ is used.
- the_why_of_y 10y agoNot all - Ada, Modula-2, Object Pascal tried to compete in that space, but developers were more interested in C++ because it allowed them to just #include their existing C headers. Also, before GNAT became available around 1995, Ada vendors invoiced several limbs for a license.
- swift 10y agoObjective C probably also deserves to be on that list.
- dom0 10y agoThere were some comparable languages, but they usually made it harder to use C code.
- loup-vaillant 10y agoC++ is often used in situations where a GC would have been perfectly fine. I'll go as far as to guess that most C++ projects are like this. In my little corner of the world, C++ is one of the most overused languages.
- tmsh 10y agoccache and forward declarations / isolating classes that require use of large header files to implementation files. Ie, spend 80% of your time working on classes without deep header dependencies. It's amortized O(k).
- daly 10y agoBack in the 70s IBM used a language called PL/I (aka "Pig Language for Idiots). It had EVERYTHING. Every idea from every language showed up in PL/I. Compiling on a 6Mhz IBM mainframe took a LONG time. The language was, for its time, very complex. We had one person in the building who was the PL/I guru. If you really needed to understand something he could work out the answer. Everyone else chose a simple subset of the language and never used the fancy features. Unfortunately everyone chose different subsets so maintaining other people's code was a pain. C++ has the same problem; big, slow, and a collection of ideas imported from other languages. For example, "concepts" have been proposed for the next "standard". They appear to be lifted from Axiom's Spad language. The C++ committee seems to feel that "importing" ideas is a way to make C++ into a better, newer "standard". Unfortunately that is simply causing havoc. Forty year old code that no longer compiles because some bright spot decided to change the semantics of "inline" is a huge waste of time. Forty year old code in Common Lisp, which also has a standard, a single standard, just works. The code is fast because there are years worth of optimizations by the compiler writers. C++ isn't a language. It is a laboratory where some people work out ways to do poorly what other languages do well. C++ isn't a language. It is a parade of languages with "standards". Do you really want to have to "fix" legacy working code because it no longer works in C++21? Programming is hard enough. Fixing old code because it "no longer conforms to the standard" is a huge, unnecessary cost in both time and money. Use it at your own peril. Just be aware that the code you write today won't compile next year.
- overgard 10y agoI don't know, every feature added to C++11 and 14 made my life easier. I do think it's a pig of a language, but all the current features and all the upcoming features are things I want. I view C++ a lot like the english language; complex and inconsistent: yep! Incredibly useful: yep!
- jlg23 10y ago> Forty year old code in Common Lisp, which also has a standard, a single standard, just works. Mostly. If not, just (pushnew :symbolics *features*) or whatever the code was created on. Especially the very old lisp code regularly needs some coercion to be made run on a standard compliant cl. The "just works" part is proven wrong by the regularly reoccurring attempts to agree on extensions to the standard and the myriads of libraries out there that provide generic wrappers around implementation specifics. > C++ isn't a language. It is a laboratory where some people work out ways to do poorly what other languages do well. "Lisp isn't a language, it's a building material." -- Alan Kay and "A poor coder can write poor code in any language." -- me
- charles-salvia 10y agoSo-called "modern C++" (basically C++11 and beyond) is really immensely more pleasurable to work with than C++03/C++98. The confluence of automatic type deduction, closures, and move semantics turned C++ into the language that it really ought to have always been, given the vision of Alexander Stepanov's STL. I mean really, before lambdas, using the STL was often really clunky. But even before C++11, the main "killer features" of C++ has always been RAII (deterministic destruction of resources) and compile time duck typing (templates.) These features together have always made C++ an incredibly powerful language that lets you code at a high level of abstraction with zero runtime penalty (at the cost of longer compile times). Nowadays, C++ can be almost Pythonic in its expressiveness. But I agree that the most urgent problem facing C++ is huge compile-times, which often result from a combinatorial explosion of new types created by templates that instantiate other templates, etc.
- nnethercote 10y agoMove semantics are so useful and powerful, but so complex. I've read multiple tutorials on them (all of them very long) and I still keep forgetting minor but critical details. (You could probably replace "move semantics" in that sentence with multiple other C++ features and still have a valid statement.)
- lngnmn 10y agoThere is a nice way to realize how deeply wrong everything is with C++.. Suppose, I have a silly idea - I could recompile my mplayer+ffmpeg and, perhaps, emacs with clang4 with all the cool optimizations for my cheap crappy i3-6xxx CPU of my crappy Lenovo laptop. Seems like nobrainer. Now movies are less laggy. Why then wouldn't I recompile my mysql server with -stdlib=libc++ and -std=c++1x, -rtlib=compile-rt, using lld and -lomp? Oh fuck...
- AndyKelley 10y agoCan you elaborate?
- lngnmn 10y agoThe c++98 code cannot be linked to libc++ which is c++11. C++ is a set of standardized kludges incompatible between standards.
- bfrog 10y agoIt's still C++ with all the baggage that comes with. Every company/project seems to have their own subset they use. C++ isn't one language, it's dozens.