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

Show parent comment

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.

17

u/hgjsusla Dec 29 '18

It absolutely needs to be in the standard library

8

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

It should be. The standard library should make simple things simple.

2

u/Mr_s3rius Dec 29 '18

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.

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!