News for hackers. Stuff that matters.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by rcoveson on Friday March 03, 2023 @07:13PM (#35016745)
> We could have unsigned integers but we're choosing not to because on the whole their disadvantages outweigh their advantages.

You (collectively) have this wrong; C, C++, C#, Rust, Go, et al. have it right. As long as we're just stating our beliefs outright instead of justifying them, that is. (That's not a request to justify your opinion; I'm sure it's been argued to death already.)

> security experts quite simply vetoed adding string interpolation as it's just too dangerous

Laughable. In an alternate universe where it didn't already exist, this could have been a JEP for StringBuilder and they would have vetoed that too.

> As to `STR.` -- which you won't need to use most of the time

Except for when you're trying to... make a String? Which is what ~everybody who ever asked for string interpolation in Java wanted to do?

What year would you estimate it will be when, at the average Java job, I can expect that most of the library APIs available to me which were often invoked with the form `func(String.format(...))` will have similar APIs that behave as JEP 430 template processors? Maybe after it's been full release for 3 years? 2, optimistically? Because during those years, in order to use this thing at all, people will be using `STR."\{}"`

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by pron on Friday March 03, 2023 @08:31PM (#35017226)
It's not a matter of what's right or wrong, but what's appropriate for languages with different audience size. Our experience is at evolving a language for a certain audience size, and perhaps if Java's popularity declines sufficiently to reach the more modest market share of the languages you mentioned, their choices would be appropriate for Java, too.

As to your other points, like I explained to someone else here, even three decades of experience evolving a language that's achieved a measure of success is still no guarantee that every feature will work well, which is why most big new features, string templates included, are first released as preview, which allows us to test our hypotheses against the problems people actually encounter rather than those people speculate they'd encounter, and adjust the feature accordingly before it is finalised. To the best of my knowledge, all preview features have undergone some adjustment before becoming permanent, but usually the changes required were relatively small.

Also, we try to think more long-term, because in ten years no one is going to care or even remember if a feature arrived five or seven years prior.

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by kaba0 on Saturday March 04, 2023 @02:25AM (#35018974)
Java still sits very close to JVM byte code, which is typed - adding unsigned ints would duplicate a huge deal of instructions.

So this feature has to wait for primitive classes, where it can be as simple as

  primitive class unsigned {
    int value;
  }
(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 )
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)

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by imtringued on Saturday March 04, 2023 @05:11AM (#35019730)
The problem with unsigned is the ridiculous underflow behavior. Unsigned integers are inherently unsafe without underflow checking at runtime. When you are using signed integers for a positive number, then seeing a negative number tells you everything you need to know (the program is wrong and it will most likely crash soon). However, when you are using unsigned to mean a number that can never be negative, then you can't just expect people to never underflow it even just to -1 because it will turn into a large positive number by accident. There is a semantic gap between the meaning of the type and what invariants it guarantees at runtime and that means having no unsigned integers is better for most code unless the unsigned Integer is fully underflow checked at runtime.
Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by yxhuvud on Saturday March 04, 2023 @08:27AM (#35020610)
> unless the unsigned Integer is fully underflow checked at runtime.

Sure. That doesn't mean the datatype wouldn't be nice to have even with such checks. There are languages out there that fully check over- and underflow. Java could too.

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by zarzavat on Saturday March 04, 2023 @10:13AM (#35021327)
I think you are confused. Unsigned arithmetic is modular. Unsigned integers are both positive and negative.

0b1111_1111 is congruent to both -1 and 255 (mod 256). We simply choose the value 255 as being the principle value for coercions, but you could equally well choose -1.

Is 3pm tomorrow or yesterday? Yes.

Unsigned != non-negative.

Re:JEP 430: String Templates (Preview) Proposed to Target Ja... by VagueMag on Monday March 06, 2023 @03:32PM (#35047166)
My favorite example of this was the major outage at a Swedish futures exchange in 2012 where the system wound up treating an unsigned order quantity as "negative" and placed an order for 4 billion futures contracts: https://www.reuters.com/article/markets-sweden-bug-idUSL5E8M...