Re:Should I choose Ada, SPARK, or Rust over C/C++? (2024)
by pjmlp on Monday October 06, 2025 @07:10AM
(#45490090)
I hardly see the difference, given the capabilities of operator overloading in Python,
[ Parent
| on HN ]
Re:Should I choose Ada, SPARK, or Rust over C/C++? (2024)
by HelloNurse on Monday October 06, 2025 @07:53AM
(#45490382)
This type confusion would have been identical with a plain function, __add__ is only syntactic sugar:
class MyNum(int):
def ten_times_sum (self, other):
return (self+other)* 10
n = MyNum(12)
a = 45
print(n.ten_times_sum(a))
Compare with, for example, fouling the state of output streams from operator>> in C++.
Re:Should I choose Ada, SPARK, or Rust over C/C++? (2024)
by pjmlp on Monday October 06, 2025 @08:30AM
(#45490641)
Hardly any different, trying to pretend Python is somehow better.
Operator overload is indeed syntactic sugar for function calls, regardless of the language.
By the way, you can overload >> in Python via rshift(), or __rshift__() methods.
Re:Should I choose Ada, SPARK, or Rust over C/C++? (2024)
by HelloNurse on Monday October 06, 2025 @09:22AM
(#45491138)
Of course I can overload >> in Python, but I cannot foul up output stream state because it doesn't exist.
Formally there is little difference between C++ and Python operator overloading and both languages have good syntax for it, but C++ has many rough edges in the standard library and intrinsic complications that can make operator overloading much more interesting in practice. For instance, overload resolution is rarely trivial.