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,
class MyNum(int):
def __add__ (self, other):
return super().__add__(other) * 10
n = MyNum(12)
a = 45
print(n + a) # oops
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.
Re:Should I choose Ada, SPARK, or Rust over C/C++? (2024)
by pjmlp on Monday October 06, 2025 @09:31AM
(#45491241)
It is only one pip install away, if anyone bothers to make on such set of overloads.
Re:Should I choose Ada, SPARK, or Rust over C/C++? (2024)
by boxed on Tuesday October 07, 2025 @05:02AM
(#45500911)
People don't though. That's the big difference. There's a certain taste in the Python community.
Re:Should I choose Ada, SPARK, or Rust over C/C++? (2024)
by boxed on Monday October 06, 2025 @07:43AM
(#45490306)
It's the exact same thing except in Python the community largely has taste. In C++ `cout >> "foo"` exists in the standard library.
Re:Should I choose Ada, SPARK, or Rust over C/C++? (2024)
by quotemstr on Monday October 06, 2025 @11:15AM
(#45492312)
I love how among a certain set the word "taste" has become an all-purpose substitute for having an argument or making a case. It basically means "I have more social media follows than you do, so I'm right"
In C++ operator overloading can easily mess with fundamental mechanisms, often intentionally; in Python it is usually no more dangerous than defining regular functions and usually employed purposefully for types that form nice algebraic structures.