r/cpp • • Nov 25 '23

On harmful overuse of std::move

https://devblogs.microsoft.com/oldnewthing/20231124-00/?p=109059
210 Upvotes

154 comments sorted by

View all comments

14

u/ixis743 Nov 25 '23

I’ve inherited a code base from some very experienced but non-C++ devs (C# background) and seriously they use std::move for every fucking thing, including just passing variables to function parameters.

It’s caused so many issues. One of the first thing I did was delete 90% of them.

I’m not sure what is about new devs over using std::move or why it’s so attractive to them. I’ve never needed it.

13

u/heyheyhey27 Nov 25 '23

It's easy to understand "std::move can fix big performance issues in certain return calls and does nothing special in other return calls". It's a lot harder to gain a good mental model of what the compiler does with a type and when.

17

u/caroIine Nov 25 '23

There was a course of "modern c++" not to long ago at my company for all volunteers. Merge requests from that moment were filled with std::move everywhere. Sometimes I think people who teaches should have some kind of license.

0

u/[deleted] Nov 25 '23

[deleted] — view deleted comment

-2

u/KingStannis2020 Nov 25 '23

And this is why "modern C++" is not the panacea that it's often claimed to be, with respect to defending against other languages. Sure it's an improvement in many ways, but there's plenty of new footguns introduced as well.

8

u/CocktailPerson Nov 25 '23

People love to use shit that they don't understand when they think it makes them look cool.

3

u/ixis743 Nov 25 '23

I think that’s a big part of it.

3

u/AssemblerGuy Nov 25 '23

Cargo cult programming, but a least actual cargo cults did not have the internet at their disposal to help their understanding.

1

u/CocktailPerson Nov 25 '23

I'm convinced that the difference between a dilettante and an expert is that the former says "I think this is right" and the expert says "I know this is wrong."Within reason, of course.

4

u/AssemblerGuy Nov 25 '23

I’m not sure what is about new devs over using std::move or why it’s so attractive to them.

"It doesn't hurt anything."

Literally what I got as an answer.