Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by saagarjha on Saturday March 04, 2023 @03:04AM
(#35019144)
There is exactly one good reason against operator overloading, and that’s operator<<. People are mostly sane otherwise and it’s a good thing to have.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by kaba0 on Saturday March 04, 2023 @03:19AM
(#35019214)
Arbitrary overloading can be problematic, like !#< or whatever is quite hard to look up (scala, haskell), but I agree that implementing an interface/trait that will give you that syntactic sugar is mostly okay (like Rust, e.g. implements Add would give you + operator).
Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by vips7L on Saturday March 04, 2023 @07:39AM
(#35020377)
I remember working in some scala that used akka actors and seeing ! for the first time. Something like:
actor ! someData
It was just an operator to send the data to the actor. A named function would have been so much better.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by imtringued on Saturday March 04, 2023 @05:16AM
(#35019764)
Just take the operator overloading from Ceylon which has been designed to only allow mathematical use cases and harder to abuse for anything else. When you see an expression a + b it might not be two numbers but it will most likely be associative, distributive and commutative.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by gergo_barany on Saturday March 04, 2023 @08:48AM
(#35020730)
A lot of seemingly primitive Java syntax already expands to method calls: autoboxing, string conversions, string concatenation. Similarly, primitive arithmetic operators on unsigned integers could expand to calls to the corresponding Integer.{compare,divide,remainder,...}Unsigned methods. The compiler would turn these back into single machine instructions anyway. This would not need any new bytecode instructions.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja...
by kaba0 on Saturday March 04, 2023 @09:15AM
(#35020886)
Sure, though I do think that the currently existing rift between the primitive and object world should be healed first, to not leave behind another construct that will only be a backwards compatibility hindrance later.
(If I’m not mistaken, the existing unsigned functions already compile down to efficient machine code, so in the meanwhile that works)
So this feature has to wait for primitive classes, where it can be as simple as
(Though it would need operator overloading to be used as a+b, which is not really liked in Java designer niches (with many good reasons against it) :D )