C++20 Is Feature Complete; Here’s What Changes Are Coming
hackaday.com
hackaday.com
That's because it is. There is hardly a paragraph in it that is wholly correct, where they actually mean anything.
C++ itself is much easier to understand than the article.
The real purpose for all the constexpr-related apparatus, as well as much of Concepts, is to make it much rarer that anybody needs to do "template metaprogramming". Instead of writing Template Metaprograms to run at compile time (a very strange functional pattern-matching language practically nothing like C++) you can usually write ordinary C++ code.
Coroutines are a new flow control primitive showing up in lots of languages lately. The C++ version is the same as the others.
The main benefit you will see from Concepts is overwhelmingly better error messages when you misuse a library component, whether Standard or your own.
Modules is a big step toward enabling a modern build infrastructure, as already seen in lots of newer languages that got benefit of hindsight.
All the old stuff is still there, because billions of lines of old code still use it. You don't have to use it in new code, but it all still works.
The biggest difference between old and new C++ code is that good new code uses value types more, and reference types less, making everything safer.
Coding modern C++ is overwhelmingly more fun than coding C++98 was, but it is just as fast as ever, and better than ever for writing fast, powerful, nice-to-use, no-compromise libraries.
But holy smokes this is not your grandmother’s C++, is it just me or is the language trying to be all things to all people? It’s getting too big, no? I mean how long do you have to be writing C++ code to fully master the language? Or can you be a high level dev without ever touching the new features? I’m assuming production codebases are likely still stuck on older versions of the language and might never move on.
I hope golang doesn’t grow this large over time.
That is only a false meme spread by non-Lisp programmers.
My impression is that the C++ standards committee sees the standard like a pile of papers on a professor's desk, where most programmers only need to understand what's currently visible on the top. And so they keep on adding papers to the top, they're getting the least-bad combo of innovation and backwards-compatibility.
My experience has been different. These days I mostly deal with codebases that are about 50% original C++ code, and 50% third-party code pulled in via CMake "super builds".
Even within the first 50% that's ostensibly under the control of a single organization, I find a large variety of C++ coding styles in effect. Continuing with the papers-on-desk metaphor, I generally have to deal with code that draws from the entire stack of papers.
However, every one of the major features listed in this post replace an existing language feature with something that is easier/safer/less verbose. For new code you shouldn't have to use the old features, and you can just rely on the new ones. Existing code is trickier, which is already a problem for large C++ codebases. You'll find dramatically different styles depending on when the code was written.
All in all, though, the recent changes have made C++ much more pleasant to program in. They're mostly less complex for an application developer than the things they are replacing, and the really complex bits (concepts, etc.) are only needed for writing complicated template libraries.
That is the part that annoys the hell out of me in regards to C++. Nothing ever gets replaced, things just get added on top of everything. And to add to that there is generally very little indication which is the "new, safe and cool way" and which is "old, shoot yourself in the foot" way of doing things. Like std::string is cool and generally you want to use it everywhere... except you can use []char everywhere and be completely unaware that you are doing anything wrong (well, until you segfault on memory access). Or unique_ptr and shared_ptr and auto_ptr. Cool things, but you can use a regular pointer in their place and again, never realize something is wrong (again, until you segfault). And every C++ book I ever saw happily discusses raw pointers and memory allocation and []char strings without ever giving you any warning that under most normal circumstances you should not use any of this.
The "Nothing ever gets replaced" problem is a direct consequence of the committee's focus on backwards compatibility. That compatibility has been absolutely crucial for the language's continued success. Backwards-incompatible changes would result in even more divergence between the C++ dialect supported by various compilers and compiler versions, and would probably result in an even worse version of the problems that occurred in the Python 2->3 transition.
In my experience, the the ABSL "Tip of the Week" posts[1] are a great source for "best practice" info, but they aren't exhaustive, and some are specific to the ABSL libraries, rather than general C++.
The Python 2->3 transition is an example of what can happen when you make backwards-incompatible changes to existing language features. We're more than a decade in, and there are still huge volumes of code at major organizations that haven't made the switch. This happened despite the fact that the people proposing the change also controlled the change and release process for the major implementation of Python, a case which is not true for C++.
It's also difficult because many proposed backwards-incompatible changes or deprecations would break ABI compatibility, which would prevent a library and binary (or 2 libraries) that were compiled using different compiler versions from inter-operating. This breaks a core workflow for many C++ users.
To get a better understanding of the committee's priorities, I would recommend looking at "The C++ Programmer's Bill of Rights": https://isocpp.org/blog/2017/07/what-should-the-iso-cpp-stan...
It's not a formal commitment from the committee, but it will give you a sense of what their priorities are.
I am not sure I buy that argument. The problems with Python 2->3 were mostly about Guido and his management style rather than actual language. People were not sure how long Python 2 would be maintained and whether or not they would need to support both and how that would work and all sorts of things like that. And Python 3 was not very complete on release, with a lot of things changing rapidly and backward compat getting shoehorned back into P2. With C++ committee approach this is a lot less likely to be a problem.
I think the reason things never get dropped is because C++ is not well designed. It is basically C with OOP and generics bolted onto it. So low level C stuff like direct memory access is built-in. And since OOP is kind of an afterthought, there is a split between parts of language that do fall under the OOP system and parts that don't. So you can introduce something like std::string using the OOP system and make it super safe, but you cannot replace C strings with it simply because C strings (and direct memory pointers in general) are a core part of the language that is not connected to OOP in any way. Same goes for smart pointers and iterators and functor structs and what not. Most of the cool things in C++11 and C++17 are firmly planted in the OOP world and cannot affect anything that is the "original C" part.
I mean, look at all the angst around Python 2 -> Python 3. People don't want features to be replaced.
I'd argue that the each new feature adds on top of an existing one. 30+ years of existing knowledge won't vanish, and will cause decades of unintended Frankenstein codebases (followed by decades of even more Frankenstein ones).
To be honest I don’t think you can ever fully master the language.
I can't call myself a C++ expert anymore, and, in fact, find it hard for anyone to, because with a language so complex, idioms and best practices aren't evolving at the same rate that the standard is changing, especially in cases where one has to deal with a mix of modern C++ and legacy (C++03 and earlier) C++.
Sometimes I'll watch a talk by Scott Meyers or Jason Turner and realize how little I know, and how deeply complicated things can get. Then I go back to my code base and continue being productive writing useful code. I know it's probably not perfect, but it's still satisfying.
As for reaching perfection or mastery, that's an enjoyable journey, even knowing that the final destination is likely unreachable.
I had just finished my second year of college, and although I felt fairly confident in my C++ abilities I had no idea how to answer. I thought it would be best to be honest and said "4" based on the subset of the huge language I knew (honestly this rating was probably too high at the time!).
One of the interviewers was obviously unhappy with the answer, and was unpleasant the rest of the interview. I have always wondered what they expected from such an vague question.
>One of the interviewers was obviously unhappy with the answer, and was unpleasant the rest of the interview. I have always wondered what they expected from such an vague question.
I knew enough of C++ to know my knowledge on the subject is approximately close to Zero.
Basically no one on earth knows C++, they mostly know a subset of it.
*C++ here referring to Modern C++, Pre 2000 era C++ was still manageable.
Edit: On that thought it seems to me every PL in 90s were all manageable. Somewhere along the line things got ugly.
I’ve interviewed hundreds of candidates; HR has relayed to me that many candidates requested that HR tell me that they loved being interviewed by me, even though the interview was very, very hard; they say they were surprised to learn things, and also happy I was so interested in them as s person.
This always made me happy; I had to sacrifice a teaching career to program.
I often get this question from recruiters hiring front end developers: From 1 to 10, how well do you know Javascript? I've given 8 for as long as I remember but often I think to myself if the people who wrote the V8 engine are 10 by default, there is no way in hell I'm even close to an 8.
Technical skill is a bit irrelevant, as essentially no one does the sort of low level SW our team does, anymore.
I got a bunch of those once in an interview, but it was fine because they gave good guidelines for what they meant with the numbers and asked about a bit more specific areas.
Well yes, in the sense that it's a systems programming language designed not to be a single-paradigm language (you can write procedural, or somewhat functional, or classic OOP, or generic functions-based OOP) and to be very efficient at all.
Some of the features are seemingly arcane in order to preserve the zero-cost abstraction approach as much as possible.
> Or can you be a high level dev without ever touching the new features?
So some features are arcane as I wrote above but some are deliberately high level, designed to make it easier to write safe, efficient high-level code without getting into the weeds. Being able to type
for (auto& a_frob : from_manager) ...
and have it be fast, efficient and not leak memory is a feature, right?> I hope golang doesn’t grow this large over time.
Go's explicit design goals are the opposite: have only a few constructs, a specific "opinion" as to how things should be done, and to deliberately limit expressiveness in favor of other objectives. So I doubt it will come close.
Edit: I don't agree with go's design criteria, but I respect them.
Having said all that C++ is really in a need of a clean cut between legacy features and the blessed way. Backwards compatibility is a noble cause, but there is also the whole weight it pulls around. Maybe something like [[deprecated]] attribute could be extended to handle more cases. Maybe C++ needs it's own "unsafe" block, something like
[[unsafe]] {
*((void*)0) = 0xDEAD;
}
Essentially having an ability to clearly mark all those different styles of different versions of C++ really. So that compiler could help you to control it and in case of a green field project totally guide you to use only the most modern idioms with an escape hatch. Of course the problem is that to help with the complexity more complexity would have to be added.I am a bit on the crossroads. From one side I start to see, that there is some hope for C++. But on the other I feel like running away, especially since I'm looking for a job. In no particular order: C, Rust, Java, Kotlin, Scheme, Julia, Go, OCaml, Free Pascal, Swift, TypeScript, Lua/Terra, Zig.
I had a funny thing with C++. One project I worked on was used in the debug version all the time, to be able to drop to debugger when needed. At that point I started to wonder why not just use Java already, instead of trying to do a manual Java and fail at it.
Dumb question. Why isn't omitting 'return' always an error in gcc rather than just a warning?
That's very often the case when enhancing static safety guarantees. And that's often worth it.
Also the ABI specifies how to call and get the return value of a function. The long and the short if it is the execution thread doesn't go off the rails if there is a mismatch in expected behavior. Your data may be garbage tho.
“I= {I}”
Is much better and less error prone than
“I= {}”, I
Or am I missing something?
"Hello {} {}!"i, 2, "worlds"
Or with reminder operator as in Python: "Hello {} {}!"istr % istr(2, "worlds")
But yeah, enough of this.It's one of the reasons C++ takes so long to compile.
It's why the "modern" languages all seem to be converging on having an explicit token that signals "This thing is an identifier : this thing is a declaration".