4 ms·
You can also use: s"The width is $width"
by edko 10y ago
You can also use: s"The width is $width"
- kbenson 10y agoWhich is good, but interpolation is really just a specialized case of concatenating string literals and variables, not variables to other variables, which is where some ambiguity is introduced.
- edko 10y agoYou can also do s"$varOne$varTwo" and that concatenates two variables.
- kbenson 10y agoYes, as an alternate syntax, interpolation works well to disambiguate your intent, which supports my point. It's really just a highly specialized form of a different operator, which says I work on strings, so anything I see that isn't a string coerce to a string. For example, in Perl $varOne . $varTwo Is entirely equivalent to "$varOne$varTwo" The question is why Scala chose to use + when it had other, non-ambiguous options, like above.
- airless_bar 10y agoTo be more familiar to Java developers. There are some thoughts about migrating people away from + toward string interpolation. But automated conversion tools are required before this can happen.