News for hackers. Stuff that matters.
Re:Modern C++ gamedev: thoughts and misconceptions by HelloNurse on Saturday May 16, 2020 @08:07AM (#23202736)
C++ fold expressions, the main C++ feature the article covers, are simple and dumb (at least, enough to use them) but not verbose, and definitely harder to get wrong than a much more verbose for loop.
Re:Modern C++ gamedev: thoughts and misconceptions by MauranKilom on Saturday May 16, 2020 @09:03AM (#23203046)
I love fold expressions, but if you're inside a variadic template, you've long left the realms of "simple and dumb". IMO.

I mean, they're only readable to people who have dabbled in variadic templates in their free time. That's how many people on your (future) team?

Re:Modern C++ gamedev: thoughts and misconceptions by hhmc on Saturday May 16, 2020 @09:43AM (#23203302)
> I mean, they're only readable to people who have dabbled in variadic templates in their free time. That's how many people on your (future) team?

This line of reasoning is vacously true for any syntax and semantics though. Move semantics and rvalue reference are only readable to people that have taken the time to understand them -- they're undoubtably useful though.

Re:Modern C++ gamedev: thoughts and misconceptions by jfkebwjsbx on Saturday May 16, 2020 @10:52AM (#23203832)
Move semantics and rvalue references are too complex and error prone to be useful in general code.

It is best to use them only in performance sensitive places and containers.

Re:Modern C++ gamedev: thoughts and misconceptions by neutronicus on Saturday May 16, 2020 @01:29PM (#23205397)
I strongly disagree. Move Semantics allow you to communicate ownership information at API boundaries with the type system.

C APIs come, of necessity, with tons of documentation about who is deleting what, when. Or, you know, maybe they don't and you have to learn the hard way. std::unique_ptr (implemented with move semantics) largely solves this problem.

And you can imagine notions of ownership more complex than "I'm deleting this at some point" (maybe "I'm versioning this object now, don't worry about it"). If you want to encode these transfers of ownership into your API, that's Move Semantics!

Re:Modern C++ gamedev: thoughts and misconceptions by jfkebwjsbx on Saturday May 16, 2020 @09:38PM (#23208729)
If you read carefully, I said use move semantics to implement containers. That includes std::unique_ptr (a container for pointers with a deleter).

The point is that you shouldn't be using rvalue ref parameters, std::forward, etc. in most of your code. Even std::move should be fairly rare.

Re:Modern C++ gamedev: thoughts and misconceptions by neutronicus on Saturday May 16, 2020 @10:22PM (#23208947)
Any time you want to pass a named unique_ptr across an API boundary, you'll need to std::move it
Re:Modern C++ gamedev: thoughts and misconceptions by jfkebwjsbx on Sunday May 17, 2020 @01:00AM (#23209714)
...which you should avoid as much as possible do.

Passing std types across API boundaries is a code smell.

Re:Modern C++ gamedev: thoughts and misconceptions by MauranKilom on Sunday May 17, 2020 @08:55AM (#23211646)
What? That's one of the primary motivations!

"I have created an object and will pass its unique ownership to you." -> std::unique_ptr

"This routine needs a function that takes two ints and returns a float (without putting all my code into headers)." -> std::function<float(int, int)>.

Can you elaborate in what circumstance you should not pass std::types across API boundaries?

Re:Modern C++ gamedev: thoughts and misconceptions by jfkebwjsbx on Sunday May 17, 2020 @04:45PM (#23215296)
The heap allocation is an implementation detail.

std::function is useful in some situations, but "without putting all my code into headers" is not a good argument.

Re:Modern C++ gamedev: thoughts and misconceptions by plorkyeran on Saturday May 16, 2020 @02:44PM (#23206021)
Or you know, anyone who has used them in their day job writing C++. Just like literally every language feature.
Re:Modern C++ gamedev: thoughts and misconceptions by eska on Saturday May 16, 2020 @08:41AM (#23202920)
I just fixed a segfault the other day because one of our new hires fresh from college is eager on using modern c++ and didn't put parentheses at the correct place in his fold expression.
Re:Modern C++ gamedev: thoughts and misconceptions by HelloNurse on Sunday May 17, 2020 @05:35AM (#23210830)
It sounds like an interesting bug, can you elaborate? On the surface it sounds like your new hire merely used fold expressions to call functions and operators that were already treacherous on their own.
Re:Modern C++ gamedev: thoughts and misconceptions by eska on Monday May 18, 2020 @07:33AM (#23221069)
Sorry, I can't look it up right now, but trying to reconstruct it in my head it must've been something like

    y = (f(x1), f(x2), f(x3))
vs

    y = f(x1, x2, x3)
Not entirely sure anymore though. But it was something about causing side effects but throwing away return values with the ,-operator and involved function calls, I think
Re:Modern C++ gamedev: thoughts and misconceptions by renox on Tuesday May 19, 2020 @04:03PM (#23239476)
Nothing in templates is 'simple and dumb': it may look so but it isn't: try to write some, you'll inevitably makes some mistake and the errors are really awful!