Lately I’ve reached to Concepts and Algorithm Intuition episode of CppCast in my podcast listening routine. Which also expanded into watching two subsequent CppCon 2019 talks Algorithm Intuition (part 1 of 2) and Algorithm Intuition (part 2 of 2) given by Conor Hoekstra.
While the ideas and lines of thinking behind “Algorithm Intuition” listed there are sane. I still got an odd aftertaste after going through them. In a few words, the author makes a claim that C++ STL takes on algorithms and data structures fields is the right one. He also claims repeatedly that usage of STL is superior to direct language constructs, specifically emphasizing algorithms usage. And while I agree that C++ standard template library is a great tool. I don’t necessarily think that there’s the single right approach how to support developers to write code inside a programming language.
C++ STL originally designed and implemented by Alexander Stepanov with generic programming style. Generic programming itself is a programming style based on type concepts, and inspired by functional programming, enabled by templates in C++. Among other things, the library provides around 100+ named generic algorithms not counting all parameters and modifiers permutations.
One of the key ideas of “Algorithm Intuition” talks is that embracing, memorizing and using most of named generic algorithms from C++ STL generally yields better solutions and cleaner code. And that any good programmer should be starting to think in terms of them when designing their solutions. While this could happen to be true in some specific situations, I don’t think it is quite a generic rule. The same or better performance results could be reached without STL, while code clarity is somewhat preferential and subjective. Don’t get me wrong, I still think that having a variety of common algorithm building blocks inside standard library helps. However, the price of maintaining a common dictionary of hundreds of algorithms in the programming language community might be too steep. Which in return makes newcomers unfriendly C++ even more unfriendly. Also I don’t feel that thinking in terms of common algorithms blocks provided by C++ STL is universally simpler than thinking in terms of more traditional conditions, loops and states. I think more often than not it’s quite the opposite.
I don’t claim to know about all popular programming languages for sure, but from what I know outside of the modern C++ community thinking in terms of procedural programming is much more common than thinking in terms of generic programming. To verify this let’s quickly take a look at the list of most popular technologies provided by stackoverflow 2020 Developer Surver. To my knowledge, none other general-purpose programming language from that list has such verbose and complex standard algorithms library as C++ does. With all of that said, I also understand that STL is a rock solid piece of code that has been present in C++ standard library for a long time. Which is indivisible from C++ at this point in time and could be treated as first-class citizen in the language. So I don’t argue that it could and should be used when appropriate. What I don’t undersantd why we need to blame people for the preference of writing code in more conservative styles which historically has been proven to be as successful.