3 ms·
Sometimes I wish there was a site like "C++ for API-using dummies" which focused on explaining these fancy new features to someone like me who's probably going
by pavlov 3y ago
Sometimes I wish there was a site like "C++ for API-using dummies" which focused on explaining these fancy new features to someone like me who's probably going to encounter them in header files, but won't be actively writing code with these features.
Don't get me wrong. This article was very helpful because now, when I eventually see auto&& ...x in a function declaration, I'm hopefully going to remember that the feature is called "parameter packs", and will find this article again with a search if I can't remember what it means.
But realistically, I'm not clever enough to write code that makes use of the various implementation specifics discussed here (stuff like "init-capture packs" that let you efficiently capture a parameter pack into a lambda, and dozens of other similar cases). Having a summary article that omits all that would be more readable for me.
I've had this same feeling about most C++ features lately like coroutines and concepts. Authors take great pains to explain how I might write a library that uses coroutines, but as an app developer I'm never going to do that — I'll be using somebody else's higher-level library because that's how it works in companies with these modern C++ codebases. OTOH, that also means it's hard to write generic documentation from the user point of view because it's often so tied to specific libraries.
- gpderetta 3y agoYou should not be going around looking for ways to use new features; the point is not to use the features per se. But if you know about them, maybe next time you have a problem that it is awkward to do without, you'll reach out for them. Or not if there is a simpler solution.
- jandrewrogers 3y agoI think it is fair to say there are two different versions of modern C++ you can learn: one for library designers and one for everyone else. The difference in complexity between the two is not small and you can use libraries without ever learning how they work. The library version of C++ is very powerful but also not something you pick up casually.
- foofie 3y ago> I think it is fair to say there are two different versions of modern C++ you can learn: one for library designers and one for everyone else. I get what you're trying to say, but this assumption that only a subset of developers need to know how to write code intended to be consumed by third parties is the reason why stuff needlessly breaks all the time for no good reason. We can't have modularity without having code consumable by other components, and knowing how to write reusable components and reusable interfaces is a core competency in software development.
- pavlov 3y agoMy possibly Luddite opinion is that using the most amazing and surprising new C++ features is not the best way to build code consumed by others. It’s good for internal APIs if you have a library team and active quality control, but if you involve third party users, more conservative is often better for everyone. For a lot of use cases, a plain C API wrapper is still very useful because it’s so easy to call from practically any other language. It can be better for maintenance to have a very narrow C API than to expose all the bells and whistles from C++ wonderland.
- Night_Thastus 3y agoI agree fully, and this is what I do personally. (Though we have to use a C wrapper API for cross-platform compatibility and name mangling reasons) But honestly, people seem to get all hung up on C++ having weird features. No-one is being forced to use a feature just because it exists. I use the sub-set of C++ that I'm familiar with and grow it when it looks like it'll save a lot of effort relative to cost of learning it.
- jujube3 3y ago"Building code to be consumed by others" is literally all programming languages are about though. So... time to move to Rust then?
- foofie 3y ago