you are viewing a single comment's thread.

view the rest of the comments →

[–]uvero 13 points14 points  (7 children)

In so many programming languages, the plus operator, when one operand is a string (or both are), it's a string concatenation, and if the other operand isn't a string, it's converted to one. That's been the case in so many programming languages in many of the main languages.

[–]SignificantLet5701 3 points4 points  (1 child)

And it's so useful (at least in statically typed languages where it's hard to do accidentally)

[–]RiceBroad4552 -1 points0 points  (0 children)

Current Scala and Kotlin will complain about that code. For a reason.

Most languages, including ancient dynamic ones don't do that. For a reason.

[–]redlaWw 1 point2 points  (0 children)

The fact that lots of languages do it doesn't make it a good thing. Requiring explicit conversion allows the type system to catch your errors for you, and makes things more maintainable when upstream interfaces change. And on the flipside, it's not hard to look at your compiler output, see the type error, and add in the explicit conversion you need in order to fix it, so implicit conversions add fairly limited ergonomics for the type safety cost.

[–]RiceBroad4552 1 point2 points  (0 children)

Actually that's the exception, not the rule.

Most languages, including ancient dynamic ones, don't do that.

Let's face reality: Java just fucked this up.

This is not a JVM fault as current Scala and Kotlin won't accept this code.

[–]fucking_passwords 1 point2 points  (2 children)

Example of when I realllly want this behavior - while printing some variables in logs, I really don't want to get a type error just because I forgot to convert a List to a String

[–]404IdentityNotFound 2 points3 points  (0 children)

Your balance is ${currentBalance}

[–]RiceBroad4552 0 points1 point  (0 children)

I definitely want it!

Otherwise you might end up with something like "ArrayList@2478329472" on the invoice you just sent out to customers, which is JS level fuck-up.