Why does Scala not have the \s escape code to mean space? It seems to have all the other escape codes.
I never saw \s
and, from some quick tests, it doesn’t seem to be that common:
- C: No
- Javascript: No
- Python: No
- Java: Yes
- Kotlin: No
- Clojure: No
Other than Java, I couldn’t find any other language that supports that, including the other JVM competitors.
I also have to admit that I don’t understand the use case… Isn’t " "
shorter and easier to read?
But maybe I’m missing something.
It was a late addition in Java for text blocks.
I’m pretty sure there is a ticket to add it in Scala.
Oh right, now we have two issue trackers to check.
Oh, I see: This is useful in Java because of the multiline string trimming, which differs from Scala.
I do see how that could be also useful in Scala, though. That makes more sense.
I like “\s” because it is instantly clear that a space is needed. Using “ “ always makes me wonder what precisely is between the quotes.
As I just saw, someone suggested a test with regular offsets
"some code // end of code"
"more code // end"
where
"some code \s"
is more descriptive.
The “terminal space” indicates exactly where the text block ends. A “strip margin” interpolator could also leverage that terminator.
Is this intended for all string literals, or just multi-line ones?
I’m thinking of folks whose unquoted regexes that use \s
subtly change in meaning once this is rolled out.
No doubt there would be unsubtle warnings at every stage of migration.
The purpose of warnings is to make everyone unhappy with a change in behavior, whether or not they endorse it.
Hmm.
I’m overdramatising now, but when somebody’s library with their Acme Regex gets deployed in production, then some bright spark decides to upgrade the Scala distribution to pick up the latest bug fixes and there is no corresponding new version of said library to go with it, then won’t the only warning seen be the sudden volume of support requests as to why Form B30 doesn’t work anymore?
EDIT: Having stated that, why would any sane and responsible person deploy to production without running an assiduous set of automated tests first? No tests? Then they deserve all they get.
You have my blessing!
EDIT #2 The penny just dropped, the string interpolation occurs at compile time, so one would have to rebuild Acme Regex in order for this to be of consequence. At which point you get a warning. Doh!