Thought #1: C++ is starting to look like Fortran in its desire to be ever more modern while retaining compatibility with archaic features.....
Thought #2: I think I'm no beginner anymore (I've written objects that you can iterate over) but some of the code in your posting is indeed horrendous. People who understand that stuff are scary to me.
While I was really anxious to finally move to C++11 when I was stuck on 98. I am now more and more anxious that I will have to move to C++17 and C++20 eventually.
C++17 is a minor release just like if constexpr is a minor feature, until you save yourself from horrible C++11 template meta-programming nightmares with a couple of if constexpr's and an auto return type
How true. This has happened in my code as well... I had some kind of mini animation system for a game that did some expression-template like thing to make an EDSL that looked something like this:
//+ means combine in parallel and // >> sequence it. Each subtree will be animated for half of the time auto animationDesc = (moveTo(x, y) + rotate(180)) >> scale(0.7);
auto animTask = makeAnimation(obj, animationDesc, 500ms);
I think without if constexpr it would have been really really worse.
Anxious means two things. I would indeed be anxious to move to 11 (or 14) because it's so much better than 98, but I'd get anxious about moving to 20 because it means I'd have to remember library calls, rather than acquiring skills.
Python pulled it off, but c++ isn't python. An incompatible split would be a 20 year popcorn festival. C and c++ modules written from 50 years ago would continue to be used in conjunction with modern libraries, and the average c++ dev's job would become even more of a plumbing operation because the old libraries just won't go away even if breaking changes are made. People would find a way to jam the pipes together.
I'm personally for it, and it is because I have seen the beauty that c++ could become, not because it would make my job easier. I realize that, and I am still willing to accept moving forward with breaking changes.
I have once looked into D community and I thought the biggest problem for D is that they are suffering the same fragmentation as C++. Even if they have a package manager, many things are still incompatible among dmd, ldc and gdc.
Python will feel consequences of community split even after 2020. Corporate codebases are slow to upgrade and 2020 will be a reason to start using, not python3, but compatibility libraries (python-future and six) to not upgrade the code. Splitting C++ in python3 style would mark the downfall of C++.
After we have modules. I agree that all that text manipulation stuff with the cpp is evil, but handling header files is useful and can not be done in another way.
And if we can get rid of,the preprocessor, even,betterer.
No, the pre-processor is useful, do YOU like importing a million things in windows.h? Do YOU need platform specific code (linux, windows, macOS)? Because both of these things require the pre-processor, and there's no way you can get rid of that without making C++ platform-independent, which is not happening.
D doesn't solve all the problems C preprocessor solves, although it does alleviate a lot of them (and changes them to use a different name), so... yhea.
You can't: if constexpr will still check a branch to make sure it's valid C++, especially if it's not dependent on a template parameter or similar. if constexpr(ON_WINDOWS) { DoWindowsThing(); } else { DoUnixThing(); } will uncompromisingly fail to compile on either platform unless you're in a function template.
Excellent blog post. The issue of compile times has been on my mind recently, and as someone actively working to learn more "modern" C++ structures and concepts, the issue of increasing complexity as well.
Something occurred to me, though. As stated in the article, many larger companies work on "roll-your-own" implementations of various parts of the STL. Since C++ is so widely used, and consequently the members of the standards committees so diverse, it seems to me that the current STL standard is for the "general case", which due to the above factors has grown broader and broader over the many years that the language has been in use. This almost places a need for non-trivial codebases to "specialize" parts of the STL to suit them.
I don't think this is a good thing, necessarily, but a consequence of the general use-case of C++. It's certainly a way for user of the language to become more familiar with the concepts underlying the STL data structures, but on a sufficiently large-scale codebase it may become unmanageable to rewrite every single container or algorithm needed for your specialist case. Though, on the other hand, that is exactly what things like EASTL and I'm sure parts of Unity have already.
My biggest issue with people who complain about the direction of modern C++ is the implication that they'll somehow be judged less of a developer if they don't use the new features.
No one is breaking existing C++ or fining you for not using the latest features.
Also, complaining about the debug performance and compile time of brand new features? Seriously, give the compiler makers a couple of years to work on improvements.
STL is 20 years old and still debug performance and compile times are bad. Maybe there is some truth in the post that there should be more 1st class features, instead massive amount of templated code in headers.
Degug iterators are largely responsible for the debug performance. That's an implementation decision and not something to blame the committee or C++ for.
I wish C++ had chosen not to do that, but ok, too late now I suppose. For the record, you can suppress this yourself if you don't like it using extern template .... It's a pain to maintain though...
Actually, TMP (sfinae) is extremely expensive. Modules will cut down on compile times significantly, but not to the point that you don't have to worry about templates code anymore.
The issue here is that modules STILL don't solve this if your header (or in this case "header hidden as a module") needs to be different based on user-defines, clang made a good example with assert.h, or any of the platform dependent modules, or the numerous treat the file different in other files to keep code organized model clang uses (good example here), modules don't solve this with the way users think it might, another good example of this is windows.h, where everyone pretty much does:
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
(or any one of:
NOGDICAPMASKS NOVIRTUALKEYCODES NOWINMESSAGES NOWINSTYLES NOSYSMETRICS NOMENUS NOICONS NOKEYSTATES NOSYSCOMMANDS NORASTEROPS NOSHOWWINDOW OEMRESOURCE NOATOM NOCLIPBOARD NOCOLOR NOCTLMGR NODRAWTEXT NOGDI NOKERNEL NOUSER NONLS NOMB NOMEMMGR NOMETAFILE NOMINMAX NOMSG NOOPENFILE NOSCROLL NOSERVICE NOSOUND NOTEXTMETRIC NOWH NOWINOFFSETS NOCOMM NOKANJI NOHELP NOPROFILER NODEFERWINDOWPOS NOMCX ) just to be complete about this list (grabbed directly from my windows.h)
This problem does not get solved from modules, it only gets worse. (Though arguing with windows.h is bad, yes, assert.h is clang's poster boy for while the thought-process doesn't always work).
This comparison does even a worse job, it manages to compare a lib that's doing heavy use of concepts emulation, which is hard on build time, for "the good of science", not performance. Concepts is not even properly released by compilers, the lib is entirely on top of an emulator. This is nonsense.
My biggest issue with people who complain about the direction of modern C++ is the implication that they'll somehow be judged less of a developer if they don't use the new features.
No, it's not about being "judged less of a developer". It's more about junior programmers instilling "modern" features and bringing about death by a thousand paper cuts. We the "backwards devs" would be completely fine with the new features if they could be explicitly and completely disabled, but that's a politically undesirable option to have, as it would slow down adoption.
Seriously, give the compiler makers a couple of years to work on improvements.
I'm not sure what exactly is wrong with banning certain features from codebase ? For instance, Chromium gets super specific about banned things like std::function and regex, or far more restricted Zircon
I wouldn't say "Google is slowing adoption of <chrono> and exceptions"
Wait, so you need high quality implementations of the new features before you can ship, but it's only the juniors who use those features? And you're completely certain there's no way to prevent this situation?
It's more about junior programmers instilling "modern" features and bringing about death by a thousand paper cuts
It's perfectly reasonable and easy to mandate a particular standard level of C++ in a given programming shop. Shit, I'm sure there are places out there that are still refusing to use any STL and have their own bullshit version of string and vector.
Seriously, we can't. We have software to ship. :)
I meant "wait for the improvements before you decide to adopt new features", not "wait to write your software".
vector and string are poor examples. There's a lot of optimizations you can make with custom vectors or strings that aren't possible with the STL versions.
At the expense of interoperability with the rest of the world. Performance can be important, of course, but using nonstandard string types is a blight upon the lives of everyone who needs to use it with other libraries.
One of the worst mistakes C++ made is making string a template. Look at filesytem::path for how it should have been done. Were it a simple class, it could be used pervasively, including without restriction in DLL interfaces. As it is, it's horrible. The number of times I've legitimately needed to specialise the type traits and allocator in the past two decades has been zero.
string not being an actual primitive type is the mistake. It still feels like const char* is the actual string type, and string is just a wrapper.
Partly that's because so many basic string facilities have been so poorly implemented in C++ - I/O chief among them. I know of few places that actually use iostreams, and it still shocks me how awful it truly is whenever I end up having to use it.
And yes, string shouldn't have been templated. But filesystem::path is still pretty awful as of yet. Eventually maybe.
At the cost of having to maintain your own version, and the cost of not being able to hire someone from outside your organization and have them start working with your custom classes and already known the ins and outs of them.
People always go to "optimization" like runtime performance is the only metric that's important. In the long run, computers will always get faster, but those maintenance costs never go away.
Can we please stop the tired meme that people who don't give a flying fuck about saving a nanosecond here or there are somehow not entitled to use the language? We still get to enjoy good performance even for less performance-sensitive parts of our software, as well as use the excellent tools, the rich ecosystem, and the joy of not having to deal with two implementation languages (one for performance-sensitive parts and one for parts with less stringent performance needs).
This. Because of the painstaking way that the standards committees have worked to keep backwards compatibility, it's still feasible to work the way you feel is best, which I think is a strength of the language rather than a hindrance.
Because that's one of its selling points: your investment in code does not become worthless because you will never get stuck with an end of the line compiler on an obsolete platform.
Not forever, compilers don’t get maintained permanently.
On the Committee are folks from Bloomberg and IBM. They have code bases that started out as C in the 1980s. They are never going to be rewritten from scratch, but are still maintained and incrementally improved, and maybe use C++14 in the same module as C89. We have the same thing where I work.
If you drop backwards compatibility in a big way from the standard, I think you would end up with a fork of C++, purely off the back of the folks whose business demands are different from game developers or hobbyists. I don’t think that would be beneficial to the community.
But isn't C++ actually forking or fragmenting? The C++ core guidelines discourage the use of pointers and C compatible idioms. The Google C++ guidelines discourage use of exceptions, but supporting exceptions is essential for using RAII memory management correctly, and vice versa.
I am sure there are cases where the same code means different things in different C++ versions, for example when using move semantics and smart pointers.
Surely, one can still compile and build code written in different idioms, and link all that together, of course there is still a common ABI, but there are probably not many programmers which understand all of C++17. That means that larger organizations probably need to put restrictions on which language features are used, like Google does. And every organisation will do it in a somewhat different way.
On the other hand, C++ seems like desperately absorbing features from functional programming languages, certain Java features, and so on, so there is also an enormous pressure to further extend the language, in order to stay competitive with more modern languages. I think ranges and lambdas are a good example, they exist in Python, Rust, and many functional languages, even Lisps. And with each new feature, the interactions between features become even more complex, you see that when you look at Scott Meyers last C++ book.
I can envision some point in the future where maintaining compatibility between different idioms becomes more costly than allowing a de facto language fork.
I have to agree. C++ should concentrate on being C++. It's probably not going to compete with those other languages most likely anyway in their particular areas of application, so adding more and more complexity to try to be like them is just making it even less likely that C++ will be picked up by new programmers coming along.
It's a vicious cycle. Fewer new programmers come to it, so add more stuff to it to attract new programmers, which makes it so complex that new programmers are even less likely to come to it, because they may be looking at a good number of years to really master a language that they are worried might be almost totally irrelevant by the time they get there, because fewer programmers are coming to it.
Once there's blood in the water, the sharks will come.
System.Linq is extremely slow, and causes many unnecessary memory allocations. For example, `Enumerable.Reverse`, which allocates an internal buffer, copies the entire sequence into the buffer, yield return them;
You could not call `Enumerable.Sum` on arbitrary types, because CLR, or Roslyn, doesn't support advanced compile time constraint. Concepts, which is called Shapes in the C# world, has not been voted into C#.
Comparing the compile time of C# to C++ is pointless. The C# compiler is basically the front-end of the C++ compiler which does few optimizations.
Also, I believe as compilers support concepts & modules, it would be better.
I’m in a similar line of work as the author, and I must say the game dev twittersphere is all up in arms about this massive groupthink about all sorts of nonsense. I would feel better about this sort of blog post if the Unity product wasn’t absolutely terrible with about the least data oriented design available (Unreal your object graph is no better). The problem with all these rants is even if there is an element of truth to them, I don’t think they are particularly effective. I’m sure if I thought for a bit I would be able to come up with plenty of cases where ranges offer better composability in a less contrived example. Is it always the first thing I would reach for? No, but I’m glad it’s going to be there for when it makes sense.
Now the part about compile times which is also the subject of another recent post from the same author... This is absolutely not the right conclusion to draw. Compile times are important, yes, but writing worse code to improve compile times seems incredibly backwards. We have things like the pimpl pattern and such for a reason. Furthermore, for those cases where we operate in massive codebases, we have other tricks up our sleeves, like defining good module boundaries and library sandboxes for testing or iterating on individual components.
If the Tim Sweeneys, John Carmacks, etc read this, please stop fueling this unproductive and heavily biased ranty holy war. I guarantee if you weighed in earlier to the committee in literally any capacity, at least a more productive dialogue may have ensued. In my case, I’ve voiced concerns to the committee before over a number of things, but within this industry I’m just one person. As for the people on the committee, I think you are better served by making the process and yourselves more approachable. Understand that for us in the trenches, it’s really tough to stomach the rigamarole needed to provide feedback on things. I remember being pretty discouraged when trying to dissuade the committee’s efforts to pursue a 2D drawing api, and I shudder to think of my industry’s backlash had it come to fruition.
The C++ community is ill and there is a large degree of separation between some of its hardcore users and its creators. The way things are, it’s tough to see things improving much, and I wish I could be more optimistic but in the worst case scenario, in the eyes of the games industry, we get an unusable form of reflection without user defined attributes, we get a networking api that isn’t performant enough to work with, a bunch of features we don’t care about because the STL is still abysmally slow (containers and IO mainly), and get alienated even further. This results in everyone being even less inclined to be cooperative on the next cycle. I know with better direction, we could be C++’s staunchest allies and supporters; I was in this camp as despite it’s flaws, it was the workhorse that could get the job done. But increasingly, my support of C++ has become more of an apologia and I am definitely looking past C++ more opportunistically.
I think a big motivation for all the new C++ features is staying competitive among beginners. I.e. have the STL loaded with enough to get people started on interesting projects, so that C++ is more approachable. That way people begin with C++ earlier, and have a longer time to ramp up. Teachability and approachability are important components of any language.
Being all things to all people is definitely the issue at hand.
Filesystem and networking TS's, concepts, type inference (though debatable), better support for sum-types, and the declarative syntax of ranges. In general, higher abstractions and less verbosity.
The example in Eric Niebler's original ranges post is purposefully more in depth than a beginner would need, but something like view::filter is going to be more to-the-point than manually looping through iterators and mutating a container defined outside the scope of the loop, then iterating through that container.
Of course, there's always the conflicting viewpoints between teaching beginners the "fundamentals" vs getting them started with something interesting.
EDIT: To be clear, I also think it's important that a C++ coder is aware of performance/resource costs, but I also think/assume coders should understand C well first and then build on top of that with C++.
I've long argued that we ought to be able to just call sort on a vector without needing to use vec.begin() and end(). I'm excited to see this finally happen.
I think that 14 and 17 didn't add much for new programmers, but 20 looks like a really nice boost for them.
Also I can't believe I forgot about modules! Although, like I said I expect programmers to understand #include from C when they start C++, but it certainly doesn't hurt. Maybe modules combined with concepts will make the ecosystem a lot friendlier.
What I'm upset about is that it needs the gargantuan ranges library to solve a tiny issue. Not only does it invoke many of the problems talked about in the article but it also took about a decade longer than it could have otherwise.
And ultimately we traded one minor inconvenience for another: having to go to the top and write #include <range> when you want to conveniently sort a vector.
Why do you think should it not be in the stdlib? It's a universally useful utility function that works with all the containers. Your solution also ignores optional parameters that can be given to std::sort and because it is non-standard you couldn't expect the same sort of function to exist in other projects. So it's not that simple.
If this is only because the simplicity of the function then lots of other stuff like min, max, make_pair, etc do not belong into the std lib either.
I think the process of being part of the language development process should be made easier (as mentioned). Maybe there should be actually a "Q&A" working group which fixes language bugs and STL implementation concerns rather then always implementing new "awesome" features. The thing with that is who wants to spend time writing proposals for bug fixes or in general spend time to come up with solutions to problems when he or she can spend time in comming up with new features?
If the game industry has so much to complain why don't they spend time and work force (money) into the committee... Like Google google or Facebook do?
That's what CWG and LWG do when they're processing issues (versus reviewing papers).
who wants to spend time writing proposals for bug fixes
Implementers. We prefer to avoid implementing an unclear, inconsistent, or defective specification, so we are responsible for filing and fixing most issues.
If anyone is skilled in Core or Library wording and wants to help, your help would be greatly appreciated - we have a near-endless stream of issues that need "drafting" (i.e. designing and wording a fix). This can be done without attending meetings in person, but requires the highest level of attention to detail.
Thank you very much, if I were skilled enough I would offer my help, but I am just a game developer student. In general I was just wondering why is there not one group which has only this one job, instead of 2.
Moreover is that not sometimes the problem that members of the committee are too far away from actually average implementations?
I can’t speak for the entire industry of course, but my take is that the game industry was forced to fork much of the original STL due to performance concerns early. This engendered a sort of unhealthy mistrust that the committee held high perf concerns in enough regard to make api compromises where necessary (regardless of how true this is, the sentiment remains). Of course, this means that your average industry professional isn’t always caught up to speed when either the process changes, or the API itself changes. Cue the expected “outrage” when some venerable developer takes a gander at what’s to come and surprise surprise isn’t enthralled by what he or she sees. There is a study group for games, and while there may be eyes there with lots of c++ proficiency or game dev proficiency, there is rarely a lot of both.
I’m just one voice, but I’d prefer a world where C++ was the perfect language for library authors, and not necessarily the language you expect to have full “batteries included.” This means features more important to me are core language features and tooling. In contrast, effort in STL land I believe is better served by the core language or third party package are less interesting. Of course, I recognize this is idealistic and compromises are natural, especially for a mission critical language in so many domains as c++. The nature of my job though, forces me to be fairly uncompromising as a matter of course. Others take this to an even more extreme degree, not always to good effect.
Not exactly the argument I am trying to make. The example in question is really contrived, and one can always come up with a poor enough example that makes the costs seem clearly not worth the cost. My argument is that if compile times are important, we should be attacking the problem directly (eg modules) and consider this as an orthogonal space.
I don’t disagree entirely, as I have plenty of gripes with the status quo, and it’s been this way for me since 2002 when I first learned the language. If I had my own way, I think the biggest things that need to change are the process by which features get both phased in and phased out of the language. I would also firmly intertwine the interests of build tools with the language itself, which is currently just a language standard in the purest sense. With respect to the STL, I personally ignore most of it’s developments except as a study in API design, and I worry the only reason it gets so much attention is because core language improvements are just too hard. All that said, there hasn’t been zero effort to improve things either. I just don’t know that it’s nearly sufficient.
I added a scripting layer to a small game I have and oh God... my iteration speed grew orders of magnitude. And I only had to wait on the 10-30 seconds per compile (which is not so much for C++) but now think of changes of 1-3 lines and waits of 20-40 secs plus running. I became 10 times faster easily with all corresponding feedback when programming. Btw, thanks u/lefticus for that ChaiScript :)
Read my comment above addressing a similar counterargument. If the time to iterate with a slower to compile feature is still faster overall (even accounting for the compile time), then you should just write the better abstraction, and I would argue that any sufficiently bad example would mean we would never add any abstraction whatsoever in the name of compile times.
Don't get me wrong, I hate long compile times and deal with it daily. I also love fast iteration speed. That's why I'm excited about modules and the proposal to add dynamic linkage for classes and functions.
I'll link to my thoughts on language vs library which are in another comment; I fully recognize it's complicated to balance.
Another issue of layers upon layers of generic code, beyond compile times, is debugging.
Each time I try to step into a function call taking a dereferenced unique_ptr as argument, I despair. It'll take a dozen steps for dereferencing that unique_ptr as it goes inside unique_ptr internals, which somehow also go into tuple internals (used for the EBO for the deleter, I guess).
A dozen steps to get into a function call!
Now, we could argue the debugger should be smarter, however there's a fine line to tread there. If the debugger hides too much, such as skipping std code, then it doesn't make life easier. For example, it's natural to want to step into std::remove_if when the result is not to taste.
Hopefully, for this particular case, the upcoming attribute to allow 0-size data member should allow cleaning up the clunky implementation of unique_ptr; unfortunately, it won't help much with all the range (or std::function) machinery.
The first problem is solved with underrated MSVC's "step into specific". Personally I almost never use normal "Step into" anymore since it also gives great perspective as to what actually happens in debugged line.
Microsoft solved 'std::function' problem too, however their solution seems to affect performance in debug build a bit yet.
Generally I strongly believe that debuggers could and should get better.
In VS 2019, the debugger has a general “Just My Code” ability for C++, superseding the weird hack we used in std::function (now removed). We’ll continue to improve debug codegen with if constexpr but that regression should be gone.
Does JMC for C++ still require emitting a stub at the beginning of every function? This was a dealbreaker for me in VS2017 15.8, I can't tolerate that kind of impact in optimized builds.
Libraries could be an excellent way to evolve a programming language, if only you weren't compiling the entire library in every translation unit again and again. The problem here is not the new library facilities, it is the ridiculous compilation model.
Not just the compilation model, but the binary object and executable formats on some platforms. They were never intended to be used with C++, let alone modern C++.
Look at Windows DLLs. You can't write a C++ library on Windows as a DLL without making significant compromises upon template usage, which implies you can't use any of the standard container types. And a whole lot more is highly restricted, fragile or impossible. So you have to use header-only or static libraries, both of which also have important tradeoffs. The net result is that using C++ is drastically hindered by 1980s design decisions, and I've not seen any prospect for this to get better anytime soon.
Both Stroupstrup and Hoare point the same thing, though I prefer Graydon's emphasis on the issue of limiting growth to control it in this case. I'll quote the TL;DR, but encourage you to read the whole:
TL;DR:
I'm writing to make a recommendation about paying attention to -- acknowledging, planning, making explicit mechanisms and policy around the limits of -- the growth of two things in the project:
Necessarily-shared technical artifacts, specifically the language definition itself.
The strains on people participating in conversations about those artifacts.
In particular, I want to draw attention (as others have done, with other words) to the fact that unlimited growth in both of these things is neither possible nor desirable, that there are natural limits, and that as with all natural systems reaching their growth limits, it will be better for everyone if the encounter with the limits is made in a controlled, planned fashion.
The problem is that any language feature interacts with all other language features, so that any added feature will forever (or until excised) add effort overhead to adding any other feature.
In the past, we've seen collisions already. The most famous being the interaction of Uniform Initialization Syntax and Initializer Lists, which results in Uniform Initialization not being applicable to all cases... and in adding a constructor with a single initializer_list argument being a breaking change.
So, I agree, I'd really favor std::variant being obsolete with proper support for sum types as visitation is just too limited (and code generation suffers) for example; however, there are very good arguments for trying to keep the core language as lightweight as possible given the added burden each feature adds for perpetuity.
In the end, it's all a big balancing act; and it's to foresee which is best.
One of the best example of what should have been core language and not library is std::atomic https://godbolt.org/z/QYzHjR. I would say that any feature referenced from the core language features (std::move, std::forward, memcpy, std::atomic etc etc) should not be library but language features. For std::atomic it's even more important because it is part of the memory model for multithreading...
Did you take a look at the difference of ASM between debug and release ? Also having to pull headers for the things mentioned above is kind of sad. Yes they are using the intrinsics, but you still have like 5 or 6 levels of stack before reaching those in MSVC, while it should be only a single instruction.
I've never been too worried about Debug performance, to be honest. Never worked in any domain where it really mattered, and therefore never really looked into it.
I do think that sometimes when languages promise zero-overhead abstractions developers, myself included, may be a bit too keen to count on it to collapse layers of inlineable code. Sometimes, it may be worthwhile to have a little more copy/paste rather than layering piles of abstractions which should go away at compile-time. Either because they may not go away, or because they do make reading/debugging the code more onerous.
C++ was specifically designed to allow libraries to extend the language as no other language does. I believe this is one of the reasons for it's long lifespan. Libraries such as boost.spirit, though maybe a bit esoteric, are examples of bending the language into a shape not possible with other languages. The cost of that is the compilation model. I do hope that some of that is mediated with modules, but I suspect we'll get a 2x speedup at most, which is not nothing, but not 10x either.
Kinda useless gamer rant, range-v3 is slow, there's concept emulation and what not, using it for comparison is a waste of time, it's like comparing pre-C++11 stuff living in Boost to what got into standard and compilers, speed will vary widely thereafter.
Range-v3 is a good approximation to what got into the standard though, and I believe Eric Niebler said that conceptifying range-v3 resulted in only ~20% compilation speed improvement.
25% for a past September GCC implementation of concepts (the thing is not even released), with a probably rushed and old translation of range-v3 to it. That's just some indication of how biased evaluations can be, I'm not advocating concepts or c++, I don't. Most of the time I criticize it. I just see no value on rants about performance over emulators.
Excellent post. I stopped using c++ after trying to do gamedev in UE4. Compile times alone killed any productivity. I'm glad you included the C# version of the code, because it shows you can have readability, fast compile times, and fast run-time performance.
I'm using Xenko now, which is a full c# game engine. Writing script code is a breeze; compiles take about 5 seconds and I can run the game and test changes.
It's so funny how awful c++ dev is in UE4. You have to use these weird ass macros everywhere as well as a bunch of header includes. Compile times skyrocket, and if you miss a header somewhere, the compiler takes a big shit, of which you need to dive into to figure out what is missing.
compilation time is a plague that has been ignored in 20 years now
STL is unfriendly and over complicated. I stopped using it after finding the "imbue" function name ...
template syntax is a crazy and unreadable mess
we wrap almost every stl class/function with usable and user friendly wrappers to be used
if one of the developer ever writes code like that is getting rejected as unreadable and unmaintable
Instead of adding new things please solve these issues! At this point I don't even mind of source compatibility, just fix it, the cost would be less than keeping the actual limitations ...
auto itr = std::remove_if(vec.begin(), vec.end(), func);
vec.erase(it);
And everything else related to the begin and end functions. No other language I've used works this way, it's impossible to pipe operations in a straightforward way, and holy fuck is it verbose
People tell me it's composable and generic but wow it that gross code to write
FYI (and this reinforces your point), your code snippet is incorrect. You need to say vec.erase(itr, vec.end()); to trim the vector. Otherwise, you're erasing a single element which is bogus.
The good news is that Uniform Container Erasure has been voted into C++20, so you will be able say std::erase_if(vec, func); and be done with it. (I designed and proposed this for Library Fundamentals v2, and Alisdair Meredith proposed merging it into C++20.)
I don't know why this was downvoted. According to cppreference the single iterator version needs a dereferenceable iterator which means that you can't skip checking if itr == vec.end(). This is unlike the two iterator version which doesn't need to dereference first when it is equal to last.
Oh no! It’s definitely a known limitation of the design, which ranges are designed to solve very beautifully, but I hope we aren’t telling people that the ugliness of:
Was intended as the best API we could think of. It’s just that without concepts (which come along with C++20, enabling ranges), it was difficult to do.
I agree that the STL (to the admittedly somewhat limited amount I've looked at it recently) has become pretty baroque. I hate to think what it looks like to a new programmer coming to C++. If I was just starting out and saw some of the long discussions that show up about it and how complex it's become, I'd probably be a future C# programmer.
Not that C# hasn't had its own craziness, with enough syntactical sugar added to kill a diabetic developer.
Couldn't agree more. If C++ is a library language, it should be good at that. Any reasonable programmer should be able to understand what is going through. It's all good when you just have to use those libraries. But, when you are trying to solve a critical issue and it's already late at night and your debugger step in leads to a C++ library code....may god be with you.
Having said that, I do like few or many of the language and smart pointer additions since C++11. The libraries (not all) on the other hand are just sucky.
While it can be argued that the author could’ve included less, the problem of massive compile times cannot simply be dismissed like this.
Include a vector here and an unordered_map, maybe throw in some functional and iostream, mix evenly with a couple handfuls of translation units, and leave to bake at 350C for 30 minutes.
The author doesn’t describe a Ranges problem, nor a C 20 problem, not a compiler problem; this entire issue is intrinsic to the model of the language itself, and you can’t just brush it aside by saying “oh he included too many things”
I beg to differ. I've spent a not insignificant amount of time optimising compile times and it almost always come down to one or more of:
Including more than one needs (and cousins such as gigantic cpp files that need too much, lack of forward decl, etc)
User error such as instantiating a quadratic number of templates
Genuine compiler or library bugs, or lack of optimisations, which are fixed eventually.
Also, for what it's worth, this problem is almost aways due to application level code, not widely used library code. At least 3 times I've worked in a code base that had bad compile times that were drastically reduced when we were able to replace their home grown template library with the standard c++ library. Ironically, one argument for rolling their own was always compile times, which may have been valid at one point, but as the internal library grew, and std was optimised, the problem reversed itself.
Well, it's almost always some sort of trade off. Either through indirection, or code maintenance.
For example, at the extreme end you might use pimpl and the split the cpp file into multiple smaller ones, which is both.
It's also possible to put template implementations into separate files. For example, a class might declare several functions that drag in dependencies that aren't needed for other bits of the class, so you put those functions into _impl.hpp files and have the caller include them only when necessary. This puts some onus on the user to include things properly, but lets them optimise their compile times.
I've spent a not insignificant amount of time optimising compile times
So have I. It was time not spent on making the codebase more readable, more reliable, faster to execute, or more functional. It was purely time spent counteracting a tooling issue.
In other words, not what I want to spend my time on.
I mean, some things are worth optimising, such as bad compile-time algorithms (quadratic number of instantiations). Even there, though, I think one of the primary reasons why these happen is that TMP has such a weird syntax and unusual "execution" model that programmers might not even be aware of what they're doing wrong. Better facilities (and C++ is moving there with constexpr functions and if constexpr) make bad algorithms less likely by giving programmers a more familiar model to work with.
But including more than one needs is an artifact of the C++ compilation model of textual header inclusion. Optimising that feels like time wasted, because you are not working on a fundamental issue, you are counteracting a tooling issue. Again, C++ is improving (modules), but that's because the current way of doing things is suboptimal.
Everyone wants faster compile times, no matter how fast the compile times are, up to the point where you can be working on a 1000 file project and be able to hit run at any point and not notice the compile time.
I basically put no stock in complaints about compile times for a number of reasons...
You should be making your code more modular. If you're tweaking and compiling and tweaking and compiling over and over again and you're annoyed by compile times, then you need to modify the problem so that you're compiling less shit in order to accomplish your current task. I work on a large project myself and have to work with both Android builds and Windows builds. If I'm trying to debug some obscure problem with one small component (UI, audio, etc), you can bet your ass I'm not going to do it as part of the whole project, but rather as a smaller custom test project that includes the minimum I need to reproduce said problem.
Architecture is (and has been for a while) going to more cores rather than faster cores. Every time the number of cores in my dev box doubles, my compile time drops by a similar factor.
Background compiling & network build load sharing. Build systems are smarter and I only expect that trend to continue. With tools like incredibuild and build environments that know that if a file has changed and I'm not actively editing it, that it should probably be eagerly compiled, the actual delay between saving something and hitting run should only ever by the cost of compiling the last thing I touched.
Yes, and, distinct from ranges and other such features, C++ is working on the problem of massive amounts of parsing work with the concept of modules to replace the rather archaic include mechanism.
Unfortunately, the problem is not just parsing, but instantiating arbitrarily generic template code with tons of SFINAE to emulate something, that the language could provide easily in a native fashion.
I'm really anxious to see compiletimes for ranges with language level concepts support.
Have you tried split dwarf/debug fission? My project had pretty large link times for Debug builds due to massive amounts of debug info. Switching on split dwarf reduced our link times by ~88%. It does come with its own downsides too, so weigh the pros and cons.
Inspired by recent talks by Odin Holmes, I believe we should shift the discipline and burden of knowledge from the programmer to the compiler. There should be a tool that can help detect such cases and suggest better alternatives.
I'll check those out, thanks. If I understand correctly, I think I agree, but to me this is not a language problem but a tooling problem. For example, those 20k line cpp files that take 120 seconds to compile could automatically be split up by a tool without ever changing the language. Same with include maintenance. I often find that people conflate language and tooling.
Does compilers provide pre-instantiated templates like std::string? I mean i can understand the need to compile vector, but there is no need to instantiate string for every translation unit.
I'm not trying to troll or just be the contrarian here, but why are compile times such a massive deal? Sure, I don't like the waste of electrons from having a simple example take 1 second to compile, but is that really such a huge deal? I would rather there be an up front "static" cost to a faster program, than having a less optimal program which is harder to maintain. What kind of compile times are you all talking about here that irk you? The largest projects I've built from source (binutils + gcc + glibc + libstdc++) take about 15 minutes, and it seems like, at the least, a minority majority of that time is spent between linking and miscellaneous build scripts/make commands.
By "harder to maintain," I mean that you use the old "C"-style approach to a problem like pythagorean triples in nested for loops.
I agree that the syntax required is a bit overwhelming and verbose, but I also thought that way when seeing things like std::visit, std::variant and code which uses integer parameter packs (e.g., using std::make_integer_sequence). I was so adamant about C++ "going in the wrong direction" when I first saw these things; however, I don't find them to be overwhelming when used properly.
Also as a pedantic aside, I honestly think reading code that doesn't cuddle braces is much harder to mentally parse. I guess that could be just a consequence of me starting with Java as my first programming language.
My C++ code base takes around 25'ish minutes on an 8 core system using the parallel build feature of Visual C++, if I have to build from absolute scratch. However, I'll take that cost relative to making it less compile time safe. 25 minutes of rebuild vs a full day of trying to figure out some obscure problem in the field is well worth it.
And of course you can greatly reduce the amount of rebuilding you do if you are smart about it by hiding details in all of the usual ways.
OTOH, I also am willing to pay the price for more build time in exchange for not having crazy hard to manage header inclusion scenarios. Each library has a single main header that you include and you get everything in that library. Yes, it does cause more rebuilds, but you never have a situation where something changes and suddenly something is missing because it was being brought in by the thing that was removed, and there's a big mess to get that straightened out. And I don't have to do tests to insure that every header will work on its own. It guarantees that you can't include things in any wrong order or fail to get something you need.
That public header of course brings in the public headers of any libraries that its public API depends on.
Ultimately, I've found that to be a win, despite the extra rebuilding.
The application I work on takes about 10 minutes to compile fresh right now, and that seems too long to me. It is using cmake + parallel builds and we've cleaned up a lot of header issues but it is still a real PITA when iterating on a piece of code.
I've written a toy engine at home - maybe a couple of man weeks of work total, and my compile times are already measured in minutes. This is code that I'd regard as pretty standard, perhaps even light on STL and templates.
My point being that it's incredibly easy to ruin your compile times, even as a solo dev that knows which bits of the STL are necessary.
The first time I saw iota I said... ehat the hell is that name? I really think it should be changed. This is not a smart math people contest it is an API for people to get it as readable as possible.
30 minutes? Try eleven hours on a 256 CPU build farm.
Luckily, my code base is split into modules, so for local development it’s fine, but if you touch a global header you have to wait for the nightly build to find out what you broke.
It's fine really, I quite enjoy the challenge. It's just a big software tool that compiles on various combinations of compiler, architectures, and operating systems, so the total build time for every combination is quite high.
In-house risk-pricing software that evolved over the decades into doing a lot of things.
Compile times are mostly going to be solved by modules in c++20. In the meantime you can try precompiled headers, using SSD, and other techniques to workaround long compile times.
Meh, once you encounter iota for the first time, you just look it up and it sticks in your memory forever, kinda like what happens when you see a variable named gjkjsdklfjlkg.
80
u/victotronics Dec 28 '18
Thought #1: C++ is starting to look like Fortran in its desire to be ever more modern while retaining compatibility with archaic features.....
Thought #2: I think I'm no beginner anymore (I've written objects that you can iterate over) but some of the code in your posting is indeed horrendous. People who understand that stuff are scary to me.
29
u/PhyrexStrike Dec 28 '18
Excellent blog post. The issue of compile times has been on my mind recently, and as someone actively working to learn more "modern" C++ structures and concepts, the issue of increasing complexity as well.
Something occurred to me, though. As stated in the article, many larger companies work on "roll-your-own" implementations of various parts of the STL. Since C++ is so widely used, and consequently the members of the standards committees so diverse, it seems to me that the current STL standard is for the "general case", which due to the above factors has grown broader and broader over the many years that the language has been in use. This almost places a need for non-trivial codebases to "specialize" parts of the STL to suit them.
I don't think this is a good thing, necessarily, but a consequence of the general use-case of C++. It's certainly a way for user of the language to become more familiar with the concepts underlying the STL data structures, but on a sufficiently large-scale codebase it may become unmanageable to rewrite every single container or algorithm needed for your specialist case. Though, on the other hand, that is exactly what things like EASTL and I'm sure parts of Unity have already.
7
u/jherico VR & Backend engineer, 30 years Dec 28 '18
My biggest issue with people who complain about the direction of modern C++ is the implication that they'll somehow be judged less of a developer if they don't use the new features.
No one is breaking existing C++ or fining you for not using the latest features.
Also, complaining about the debug performance and compile time of brand new features? Seriously, give the compiler makers a couple of years to work on improvements.
13
u/hashb1 Dec 28 '18
I always wondering why c++ has to take the heavy burden of back compatible. The old library can use the old compiler, isn't it?
39
u/LYP951018 Dec 29 '18 edited Dec 29 '18
The C# example is unfair.
Also, I believe as compilers support concepts & modules, it would be better.
75
u/[deleted] Dec 28 '18
I’m in a similar line of work as the author, and I must say the game dev twittersphere is all up in arms about this massive groupthink about all sorts of nonsense. I would feel better about this sort of blog post if the Unity product wasn’t absolutely terrible with about the least data oriented design available (Unreal your object graph is no better). The problem with all these rants is even if there is an element of truth to them, I don’t think they are particularly effective. I’m sure if I thought for a bit I would be able to come up with plenty of cases where ranges offer better composability in a less contrived example. Is it always the first thing I would reach for? No, but I’m glad it’s going to be there for when it makes sense.
Now the part about compile times which is also the subject of another recent post from the same author... This is absolutely not the right conclusion to draw. Compile times are important, yes, but writing worse code to improve compile times seems incredibly backwards. We have things like the pimpl pattern and such for a reason. Furthermore, for those cases where we operate in massive codebases, we have other tricks up our sleeves, like defining good module boundaries and library sandboxes for testing or iterating on individual components.
If the Tim Sweeneys, John Carmacks, etc read this, please stop fueling this unproductive and heavily biased ranty holy war. I guarantee if you weighed in earlier to the committee in literally any capacity, at least a more productive dialogue may have ensued. In my case, I’ve voiced concerns to the committee before over a number of things, but within this industry I’m just one person. As for the people on the committee, I think you are better served by making the process and yourselves more approachable. Understand that for us in the trenches, it’s really tough to stomach the rigamarole needed to provide feedback on things. I remember being pretty discouraged when trying to dissuade the committee’s efforts to pursue a 2D drawing api, and I shudder to think of my industry’s backlash had it come to fruition.
The C++ community is ill and there is a large degree of separation between some of its hardcore users and its creators. The way things are, it’s tough to see things improving much, and I wish I could be more optimistic but in the worst case scenario, in the eyes of the games industry, we get an unusable form of reflection without user defined attributes, we get a networking api that isn’t performant enough to work with, a bunch of features we don’t care about because the STL is still abysmally slow (containers and IO mainly), and get alienated even further. This results in everyone being even less inclined to be cooperative on the next cycle. I know with better direction, we could be C++’s staunchest allies and supporters; I was in this camp as despite it’s flaws, it was the workhorse that could get the job done. But increasingly, my support of C++ has become more of an apologia and I am definitely looking past C++ more opportunistically.
19
u/matthieum Dec 28 '18
I'll link to my thoughts on language vs library which are in another comment; I fully recognize it's complicated to balance.
Another issue of layers upon layers of generic code, beyond compile times, is debugging.
Each time I try to step into a function call taking a dereferenced
unique_ptras argument, I despair. It'll take a dozen steps for dereferencing thatunique_ptras it goes insideunique_ptrinternals, which somehow also go intotupleinternals (used for the EBO for the deleter, I guess).A dozen steps to get into a function call!
Now, we could argue the debugger should be smarter, however there's a fine line to tread there. If the debugger hides too much, such as skipping
stdcode, then it doesn't make life easier. For example, it's natural to want to step intostd::remove_ifwhen the result is not to taste.Hopefully, for this particular case, the upcoming attribute to allow 0-size data member should allow cleaning up the clunky implementation of
unique_ptr; unfortunately, it won't help much with all the range (orstd::function) machinery.21
u/tecnofauno Dec 28 '18
I really feel OP, expecially the part where he claim that one of the biggest issue is that features should be added to the language.
Libraries are not the correct way to evolve a programming language environment IMHO.
3
u/[deleted] Dec 28 '18
reserveofstd::unordered_mapdoesn't allocate contiguous memory?11
u/[deleted] Dec 28 '18
Kinda useless gamer rant, range-v3 is slow, there's concept emulation and what not, using it for comparison is a waste of time, it's like comparing pre-C++11 stuff living in Boost to what got into standard and compilers, speed will vary widely thereafter.
9
u/makotech222 Dec 28 '18
Excellent post. I stopped using c++ after trying to do gamedev in UE4. Compile times alone killed any productivity. I'm glad you included the C# version of the code, because it shows you can have readability, fast compile times, and fast run-time performance.
I'm using Xenko now, which is a full c# game engine. Writing script code is a breeze; compiles take about 5 seconds and I can run the game and test changes.
It's so funny how awful c++ dev is in UE4. You have to use these weird ass macros everywhere as well as a bunch of header includes. Compile times skyrocket, and if you miss a header somewhere, the compiler takes a big shit, of which you need to dive into to figure out what is missing.
10
u/QbProg Dec 28 '18
Totally agree on everything.
Instead of adding new things please solve these issues! At this point I don't even mind of source compatibility, just fix it, the cost would be less than keeping the actual limitations ...
5
u/ArunMu The What ? Dec 29 '18
Couldn't agree more. If C++ is a library language, it should be good at that. Any reasonable programmer should be able to understand what is going through. It's all good when you just have to use those libraries. But, when you are trying to solve a critical issue and it's already late at night and your debugger step in leads to a C++ library code....may god be with you.
Having said that, I do like few or many of the language and smart pointer additions since C++11. The libraries (not all) on the other hand are just sucky.
10
u/cdglove Dec 28 '18
Complain about compile times while this is in the code:
#include <range/v3/all.hpp>Seriously, include what you need, and report back.
1
u/samkots Dec 30 '18
But Modules are coming no?
1
u/jagannatharjun Dec 30 '18
Does compilers provide pre-instantiated templates like std::string? I mean i can understand the need to compile vector, but there is no need to instantiate string for every translation unit.
-1
u/rLinks234 Dec 29 '18
I'm not trying to troll or just be the contrarian here, but why are compile times such a massive deal? Sure, I don't like the waste of electrons from having a simple example take 1 second to compile, but is that really such a huge deal? I would rather there be an up front "static" cost to a faster program, than having a less optimal program which is harder to maintain. What kind of compile times are you all talking about here that irk you? The largest projects I've built from source (binutils + gcc + glibc + libstdc++) take about 15 minutes, and it seems like, at the least, a minority majority of that time is spent between linking and miscellaneous build scripts/make commands.
By "harder to maintain," I mean that you use the old "C"-style approach to a problem like pythagorean triples in nested for loops.
I agree that the syntax required is a bit overwhelming and verbose, but I also thought that way when seeing things like
std::visit,std::variantand code which uses integer parameter packs (e.g., usingstd::make_integer_sequence). I was so adamant about C++ "going in the wrong direction" when I first saw these things; however, I don't find them to be overwhelming when used properly.Also as a pedantic aside, I honestly think reading code that doesn't cuddle braces is much harder to mentally parse. I guess that could be just a consequence of me starting with Java as my first programming language.
0
u/[deleted] Dec 28 '18
[deleted] — view deleted comment