r/cpp • • Aug 25 '21

Experience C++ developers: do you enjoy using C++ (even for personal/hobby projects?)

Do you actually enjoy using C++, or do you only use it for work, or purely for performance? This question is aimed at people with years of experience, who've worked on large projects in C++. I see people who dislike the language, but use it purely for performance reasons. This sort of discourages me from learning it. I don't want programming to feel like work.

204 Upvotes

327 comments sorted by

View all comments

Show parent comments

3

u/[deleted] Aug 25 '21

if performance is a problem then I'll run perf to see if (...) passing by reference might help.

Outch... I understand that you are not writing C++ every day and then it my be difficult because you need to ask yourself each time if you need to copy or reference (or move... don't forget the move please). But actually it is the very basics of C++.

Actually, the default (if any) should be to const ref when speaking about complex object like std container, not to copy. Ask yourself when you need to copy.

1

u/ohell Aug 25 '21

So, I have teammates who do worry about this stuff. And for a laugh I have changed the code for a long running task to use references, unordered_map etc. For a task that runs on the cloud in 2 hour, saving is < 2 minutes. At AWS prices that is 4c. I am happy to say that all of us are paid well enough that spending even 1 extra hour refining code this way will only pay off if our program was run ~5000 times :)

Having said this, I can't wait for the dream to become reality

1

u/[deleted] Aug 25 '21

in : X (by value) if cheaply trivially copyable (defined by platform ABI) Otherwise, X*

Oh no please, it is completely unmanageable!

I am happy to say that all of us are paid well enough that spending even 1 extra hour refining code this way will only pay off if our program was run ~5000 times

It depends, for the reference case just write it by ref by default. It doesn't take time at all. For map and unordered map, I agree with you.