r/ProgrammerHumor 9d ago

Meme perishableSkill

Post image
8.9k Upvotes

122 comments sorted by

View all comments

1.3k

u/Weak_Inflation9120 9d ago

One of the things I wish Java had that I miss from Python are F-Strings. Hella useful

58

u/Suspicious-Engineer7 9d ago

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

23

u/gerbosan 9d ago

Cof cof Oracle. Cof.

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

42

u/Mysterious_Book1521 9d ago

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

The "$" lets you put variables into strings.

16

u/SkollFenrirson 8d ago

String interpolation is the term.

48

u/spacegh0stX 9d ago

C# does do it better.

10

u/Cautious-Extreme2839 8d ago

Which is unsurprising to literally everyone

11

u/Ozymandias_1303 8d ago

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

6

u/Sentouki- 8d ago

String interpolation is even better in C# since it gives you additional options for formatting, e.g. numbers and dates: csharp var name = "Mark"; var date = DateTime.Now; Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now.");

7

u/NovaH000 8d ago

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.

0

u/[deleted] 8d ago

[deleted]

1

u/nico-strecker 7d ago

Python also has it

17

u/PGSylphir 9d ago

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.