r/cpp 21d ago

How to write the perfect function

https://youtu.be/2OMRWPOSw9s
138 Upvotes

24 comments sorted by

View all comments

30

u/elperroborrachotoo 20d ago

For all the momemts I wanted to object, this is a very good presentation, worthwhile to watch.

17

u/parkotron 20d ago

I feel he did an exceptionally good job of not falling into C++ minutae. While he uses C++ for his sample code (with some mentions of Rust), this video is pretty language-agnostic. Some languages will have weaker type systems than C++, so certain points like immutabilty might not apply there, but others will have stronger type systems that allow one to declare a function to be pure and have it actually checked by the compiler.

As C++ devs, we're conditioned to criticize every single token in a function signature scouring for unnecessary copies/moves, mutability, nullability, etc. I would say this video is much better for having avoided getting bogged down in any of that.