4 ms·
I won’t be able to address all the points. But in my experience, C++ has been going in the wrong direction in terms of simplicity or productivity. Modern C++ is
by mlthoughts2018 8y ago
I won’t be able to address all the points. But in my experience, C++ has been going in the wrong direction in terms of simplicity or productivity. Modern C++ is drastically more complicated and riddled with deep esoterica. The flexibility benefit modern Python gives is probably more like 1000x, further mitigating many cases when there are concerns about the flexibility/performance trade-off.
Just for one example about what I mean with modern C++: < https://bitbashing.io/std-visit.html https://bitbashing.io/std-visit.html >.
This example is relevant because you mentioned you feel you never need Python’s flexibility in the day to day. But in Python (much like in many functional languages), the entire idea of the visitor pattern can be boiled down to map() —- just one function call! If you want to specialize this for your own data type, you can very easily implement the iterator protocol, often simple __iter__, __getitem__, and __next__, which themselves could use e.g. numba to iterate some homogeneously typed tree class with pure C performance characteristics, or a sum type (like with Cython fused types) as in the std::visit example, etc.
The point is that the data model’s flexibility makes this trivial, rather than convoluted. In the cases when I’d care about this pattern, it would be no contest that Python offers hugely improved productivity.
So it’s not just naive flexibilty of modifying object instances, but the bigger picture of flexibility in the data model overall.
- dkersten 8y ago> The flexibility benefit modern Python gives is probably more like 1000x In my personal experience, this hasn’t been true for me. Granted, I’ve been mostly ignoring C++17 because I like to give compilers a little time to catch up, so I haven’t been exposed to std::visit beyond reading about it, but C++11 (and 14 to a lesser extent) have been really productive for me. It’s more verbose for sure, but that’s largely a non-issue especially with editor support. I also find it easier to manage and localise state in C++ (I’m a Clojure developer at heart so carefully management of mutable state is important to me) simply because in Python everything (including method dispatch) is mutable and in large codebasrs it can be very difficult to know when things are being changed behind my back. C++ allows you to mutate things too, of course, and since you have low level memory access you can do some truly horrific things, but most of the time it doesn’t happen outside of isolated performance optimisations so it hasn’t been an issue for me. TL;DR: Python is great and productive, but I personally am really productive in C++ too. EDIT: you edited while I was writing, so in response to the latter part of your message: std::visit, at least from my understanding of it, is really rather misnamed. It’s not a generic visitor pattern that you might apply over a collection but a tool for applying different functions on a variant, based on the type contained in the variant. Your example of Python visitor pattern boiling down to map() and a few dunder functions isn’t really different from C++ where it boils down to iterators. You have a lot of the flexibility available at compile time with templates too, my comment about not needing the flexibility was directed specifically at runtime modifying of objects (messing with its dispatch dict), stuff like overriding dunder methods is akin to templates in C++ in many ways and that flexibility exists in both languages. Btw to be clear, I’m not saying it’s not easier in Python, because it obviously is easier, I’m just saying that for me the productivity gap isn’t thaaaat large for most code, I don’t need the runtime flexibility in most code and C++ doesn’t pay a performance premium. I should add that I’m nitpicking a bit and not suggesting people use C++ over Python at all. I agree with a lot of what you’re saying, my disagreement is really over the productivity gap, since if you truly need the performance (most use cases don’t), then going directly to C++, at least for me, is often a sensible choice.
- stochastic_monk 8y agoIt primarily depends on the size of the project. Past a certain size, I am definitely more productive in C++ than in Python. Though the compile-time checking of Cython might balance things out and make scaling a Python project easier. std::visit is broken, sure. std::vector<bool> is a mistake, too. You don't have to use it. Select a subset of the language which gives you what you need. That's part of what's great about having so much in the language.
- jchmbrln 8y ago> You don't have to use it. Select a subset of the language which gives you what you need. That's part of what's great about having so much in the language. This is the precise reason I've not yet devoted the time to learn C++. I'm a little scared off by having to learn the biggest programming language and also which large sections of it to avoid before I can be productive.
- cpitman 8y ago> The flexibility benefit modern Python gives is probably more like 1000x If true, that would mean that a 1 year C++ project could be done in 2 hours, and a 10 year project in half a week.
- mlthoughts2018 8y agoDevelopment time is not the same as flexibility, particularly because, as others have pointed out in comments, the lack of flexibility in C++ usually manifests itself by the choice to exclude huge swaths of feature sets. I see this Python advantage meaning in C++ I have to give up more possibilities if I want to restrict myself to a subset whose complexity can be reasonably managed. Just think of how often people even suggest C++ without exceptions. This is a mark of inflexibility that people view the complexity cost of these techniques as too high, and so must write code that intentionally cannot use them (and so you have to contort even more to imitate their intended behaviors). This is a much more important thing than mere developer time, which is a shallow way to look at it.