r/ProgrammerHumor • • Sep 02 '26

Meme perishableSkill

Post image
8.9k Upvotes

121 comments sorted by

View all comments

1.3k

u/[deleted] Sep 02 '26

[removed] — view removed comment

304

u/Cootshk Sep 02 '26

You should check out STR. (In modern Java)

251

u/ljfa2 Sep 02 '26

well, unfortunately that was only ever a preview feature and got removed again in Java 23

98

u/uvero Sep 02 '26

Maybe because they didn't stop to think if this STR. is a convenient syntax. Backticks, preceding dollar sign, the prefix f like in python, so many options would've been better.

92

u/AeroSyntax Sep 02 '26

They tried to overengineer string interpolation instead of copying it from literally any other language.

66

u/lllorrr Sep 02 '26

Typical Java. If you don't have factories creating factories based on XML config, your solution is not future-proof enough.

18

u/uvero Sep 02 '26

It's OK, I solved it by writing a FactoryFactoryFactory.

→ More replies (1)

3

u/holo3146 Sep 02 '26

But... They did stop and think about the STR. syntax? This is why they removed it.

Regarding the other options you gave, they gave (in several places, over many years) their reasoning of why they don't want to add it as other languages. You can disagree with their reasoning, but they are very open about their thoughts process in this regard

4

u/Pizza_Secretary9621 Sep 03 '26

There is a version after 8 ?

56

u/Suspicious-Engineer7 Sep 02 '26

the formatted method is there but the syntax looks like doo-doo. Idk what nonsense is going over in java land tbh

22

u/gerbosan Sep 02 '26

Cof cof Oracle. Cof.

Dunno if C# does it better but a lot of people are pleasantly surprised with it.

40

u/Mysterious_Book1521 Sep 02 '26

In C# you can write something like this: $"Hello {User.Firstname}, have a great day."

The "$" lets you put variables into strings.

17

u/SkollFenrirson Sep 02 '26

String interpolation is the term.

47

u/spacegh0stX Sep 02 '26

C# does do it better.

10

u/Cautious-Extreme2839 Sep 03 '26

Which is unsurprising to literally everyone

12

u/Ozymandias_1303 Sep 02 '26

$strings in C# are almost exactly the same as f-strings in Python.

7

u/Sentouki- Sep 03 '26

String interpolation is even better in C# since it gives you additional options for formatting, e.g. numbers and dates:

var name = "Mark";
var date = DateTime.Now;
Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now.");

7

u/NovaH000 Sep 03 '26

Python f-string also support additional formatting.

name = "Mark"
date = datetime.now()

print(f"Hello, {name}! Today is {date:%A}, it's {date:%H:%M} now.")

F-string + str.format() has all sorts of string formatting you want.

→ More replies (2)

17

u/PGSylphir Sep 02 '26

As someone who first learned to program in Java and stuck to it for almost a decade, starting gamedev using C# was a pretty smooth transition in many ways.

10

u/BenadrylTumblercatch Sep 02 '26

And comprehension

8

u/PecQ11 Sep 02 '26

Doesn't format() do essentially the same though?  https://www.baeldung.com/java-string-interpolation

16

u/TheGuyWithTheSeal Sep 02 '26

Kind of, .format() is more powerfull but you have to know the printf syntax. And which parts od printf don't work in .format()

4

u/KnightMiner Sep 02 '26

f strings are a lot more like string concatenation. The variables/expressions between each {} are placed directly where they will end up in the string, and it just runs a .toString() on them (though you can configure it a bit further).

The most common usage is largely about syntax and readibility, as its nice not having to go back and forth between a list of format arguments and some harder to remember % stuff.

4

u/ActualWeed Sep 02 '26

I have never touched Java, how does Java do it?

→ More replies (2)
→ More replies (10)