3 ms·
Oh god, it's c++ all over again!
by wredcoll 1y ago
Oh god, it's c++ all over again!
- quotemstr 1y agoIs that supposed to be a bad thing?
- toolslive 1y agoIMNSHO: Yes. It's a sign of the design quality of a programming language when 2 arbitrary features A and B of that language can be combined and the combination will not explode in your face. In python and C++ (and plenty of other languages) you constantly have the risk that 2 features don't combine. Both python and C++ are full of examples where you will learn the hard way: "ah yes, this doesn't work." Or "wow, this is really unexpected".
- Joker_vD 1y agoWell, there is also a question of attitude. Most of the Python programmers don't overload << or >> even though they technically can, while in C++ that's literally the way the standard library does I/O ― and I suspect it leaves an impression on people studying it as one of their first languages that no, it's fine to overload operators however quirkily you want. Overload "custom_string * 1251" to mean "convert string from Windows-1251 to UTF-8"? Sure, why not.
- toolslive 1y agoI've seen >> being overloaded in several libraries/frameworks. From the top of my head: - Airflow: https://airflow.apache.org/docs/apache-airflow/stable/index.html#dags - Diagrams: https://diagrams.mingrammer.com/docs/getting-started/examples
- IshKebab 1y agoYes. iostreams overriding << and >> was pretty much universally seen as a bad idea and they eventually abandoned it in C++20/23 with std::format and std::print. It's usually a good idea for operators to have a specific meaning and not randomly change that meaning depending on the context. If you want to add new operators with new meanings, that's fine. Haskell does that. The downside is people find it really tempting and you end up with a gazillian difficult-to-google custom operators that you have to learn.