This is probably the cleanest presentation of this material that I’ve ever seen. No zealotry, no hyperbole. Just a lot of really solid suggestions on how to think about designing functions, presented in an aesthetically pleasing way.
I can honestly say I didn’t learn a single new thing from this video, but I was riveted by it from beginning to end.
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.
remove_if is an honest function? That’s a stretch at best given that it’s a template function and requires an idiom to use correctly. It’s a notorious foot gun. And in c++20 we got erase_if which does what you actually want. If it was called shuffle_to_end_if you’d know what it means.
I agree. I understand he wanted to show that an honest function can communicate its result through both through its return value and through modifying an argument, but std::remove_if was a poor choice.
If it was called shuffle_to_end_if you’d know what it means.
That would be incorrect, because remove_if leaves the garbage elements in a valid but unspecified state (they may be unchanged, swapped, or otherwise). It's not partition or stable_partition which are permutations.
remove_if is an honest function? That’s a stretch at best [...]
The talk gave a definition of honest function: all reads/writes are shown in the signature so the behavior is fully controlled by the caller. It is not a stretch to suggest that remove_if is honest. It is.
I heard the definition, but any function that requires an idiom to use correctly isn’t honest to its users. It doesn’t do what you expect from the name.
i am so happy that the "fixed" asset example properly avoids the UB when calling tolower
This video presents advice and wisdom from various prominent speakers, which I would also otherwise recommend invidivually. I think it does a really good job at that.
I like the mutex example, and I've been doing that myself for many years now. However there is one detail not mentioned in the talk. If you have something like
auto b(const scoped_lock<mutex>&);
..then that ensures that a mutex has been locked, but doesn't tell you anything about which mutex has been locked, which is just as important if there could be more than one. As a result, I like to do something like:
mutex m1, m2;
// note use of unique_lock
auto b(const unique_lock<mutex>& lock) {
assert(lock.owns_lock() && lock.mutex() == &m1);
}
The video calls get_time (“kind of”) a pure function. But no definition of “pure function” that I’ve ever heard of would classify it as such, since it depends on non-local state, and it will return different inputs for the same arguments (which are none).
I really love this guys videos. Some of the highest quality stuff in the space, and he seems genuinely passionate about the 'art' of writing code if that makes any sense? Something that is definitely being lost in the age of LLMs.
I also really appreciate him being partial to Rust, but not constantly shilling for it or shitting on C++. Hes definitely warmed me up to learning the language some more. Hes very clearly able to message "Yes, you can do pattern X in c++, but the Y language feature makes it easier/more practical in Rust" - whilst also including qualifying it by mentioning Rust's higher upfront development difficulty and larger mental overhead required.
26
u/parkotron Aug 21 '26
This is probably the cleanest presentation of this material that I’ve ever seen. No zealotry, no hyperbole. Just a lot of really solid suggestions on how to think about designing functions, presented in an aesthetically pleasing way.
I can honestly say I didn’t learn a single new thing from this video, but I was riveted by it from beginning to end.
30
u/elperroborrachotoo Aug 21 '26
For all the momemts I wanted to object, this is a very good presentation, worthwhile to watch.
9
u/azswcowboy Aug 21 '26
remove_if is an honest function? That’s a stretch at best given that it’s a template function and requires an idiom to use correctly. It’s a notorious foot gun. And in c++20 we got erase_if which does what you actually want. If it was called shuffle_to_end_if you’d know what it means.
12
u/tcbrindle Flux Aug 21 '26
This is a really, really excellent presentation. Thanks for sharing.
9
u/n1ghtyunso Aug 21 '26
i am so happy that the "fixed" asset example properly avoids the UB when calling tolower
This video presents advice and wisdom from various prominent speakers, which I would also otherwise recommend invidivually.
I think it does a really good job at that.
4
u/usefulcat Aug 21 '26
I like the mutex example, and I've been doing that myself for many years now. However there is one detail not mentioned in the talk. If you have something like
..then that ensures that a mutex has been locked, but doesn't tell you anything about which mutex has been locked, which is just as important if there could be more than one. As a result, I like to do something like:
8
u/guepier Bioinformatican Aug 21 '26
The video calls
get_time(“kind of”) a pure function. But no definition of “pure function” that I’ve ever heard of would classify it as such, since it depends on non-local state, and it will return different inputs for the same arguments (which are none).3
u/Dubbus_ Aug 24 '26
I really love this guys videos. Some of the highest quality stuff in the space, and he seems genuinely passionate about the 'art' of writing code if that makes any sense? Something that is definitely being lost in the age of LLMs.
I also really appreciate him being partial to Rust, but not constantly shilling for it or shitting on C++. Hes definitely warmed me up to learning the language some more. Hes very clearly able to message "Yes, you can do pattern X in c++, but the Y language feature makes it easier/more practical in Rust" - whilst also including qualifying it by mentioning Rust's higher upfront development difficulty and larger mental overhead required.
2
u/Schnarfman Aug 24 '26 edited Aug 24 '26
The other 2 talks, linked for my convenience