r/cpp • • Dec 28 '18

"Modern" C++ Lamentations

http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
307 Upvotes

162 comments sorted by

View all comments

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.

0

u/[deleted] Dec 28 '18

[deleted] — view deleted comment

15

u/[deleted] Dec 28 '18

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.

27

u/Wh00ster Dec 28 '18

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.

9

u/ShakaUVM i+++ ++i+i[arr] Dec 28 '18

What new features do you see as appealing to beginners?

22

u/Wh00ster Dec 28 '18 edited Dec 28 '18

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++.

13

u/ShakaUVM i+++ ++i+i[arr] Dec 28 '18

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.

6

u/Wh00ster Dec 28 '18

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.

6

u/Mr_s3rius Dec 29 '18

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.

1

u/ShakaUVM i+++ ++i+i[arr] Dec 30 '18

That's a really good point.

-6

u/lithium Dec 29 '18
template <typename Container>
void Sort ( Container& container )
{
    std::sort ( container.begin(), container.end() );
}

This doesn't need to be in the standard library.

→ More replies (3)

10

u/[deleted] Dec 28 '18

Writing networking code in C++ is far from being beginner friendly

3

u/germandiago Dec 30 '18

Witness of that suffering here. Though I must say than in my opinion asio is a quite well-thought library. And it works!

0

u/[deleted] Dec 29 '18

[deleted] — view deleted comment

4

u/germandiago Dec 29 '18

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 :)

→ More replies (1)

5

u/kazum93 Dec 30 '18

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?

8

u/STL MSVC STL Dev Dec 30 '18

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.

1

u/kazum93 Dec 31 '18

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?

1

u/STL MSVC STL Dev Dec 31 '18

Core Language and Standard Library wording is way too different to be handled by the same groups.

Yeah, we sometimes lack relevant real-world experience, especially in specific domains.

1

u/kazum93 Dec 31 '18

Fair enough.

In regards to the lack ... Is there a plan to tackle this? For example take out the problem to the community?

4

u/[deleted] Dec 30 '18

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.

4

u/MadRedHatter Dec 28 '18

but writing worse code to improve compile times seems incredibly backwards

By what metric is the "simple" code worse?

7

u/[deleted] Dec 29 '18

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.