5 ms·
So this is a long overdue QoL feature but the whole whitespace elision thing is unwelcome and unnecessary (IMHO). What's wrong with What You See Is What You Get
by cletus 7y ago
So this is a long overdue QoL feature but the whole whitespace elision thing is unwelcome and unnecessary (IMHO). What's wrong with What You See Is What You Get? This is a perfect example of added complexity to solve a complete non-problem just based on probably the unsubstantiated aesthetic view of a handful of key people. Stop. Just... stop.
Even stripping trailing whitespace is... risky. Why is the language trying to decide what whitespace is significant? Or even trying to divine the mind of the developer at all?
I didn't realize there was a raw string proposal in Java 12 using backticks (bleh). By now I'm pretty used to languages that use double-quotes for interpreted strings (including escape sequences, at a minimum) and single-quotes for raw strings. This is an incredibly useful feature. Of course, Java uses single-quotes for character literals so that's out, otherwise I'd like to see """ for interpreted and ''' for raw.
Anyway, let me point out just one reason why this is terrible: source control. Consider:
String s1 = """
<outer>
<inner>foo</inner>
</outer>
"""";
Now change this to:
String s1 = """
<outer>
<inner>foo</inner>
</outer>
"""";
It's only one line change but you have in fact changed what the previous lines do.
And of course (which the article mentions).... tabs!
I really want the option of pasting text into a block like this and knowing that's what I'll get. I don't want to process it usually (eg escaping characters).
- vbezhenar 7y agoHow do you propose handling the most common case, when I don't want leading indentations? String s1 = """<outer> <inner>foo</inner> </outer>"""; is ugly.
- kevingadd 7y agoIt's how C# does it. You can always put in a leading newline and strip it via an API call, or put the """ at the start of the next line.
- dfinninger 7y agoPython has the textwrap[1] module in the standard library. Calling “textwrap.dedent()” on the docstring (multiline string) will strip white space to the least-indented line inside the text. I’m personally a fan of having an easily-accessible method to call. That way you get indented text blocks and no “magic” formatting (at least, you explicitly opt-in to the magic formatting). [1] https://docs.python.org/3/library/textwrap.html https://docs.python.org/3/library/textwrap.html
- etaty 7y agoScala use stripmargin (default "|") https://docs.scala-lang.org/overviews/scala-book/two-notes-about-strings.html https://docs.scala-lang.org/overviews/scala-book/two-notes-a...
- sgift 7y ago> This is a perfect example of added complexity to solve a complete non-problem just based on probably the unsubstantiated aesthetic view of a handful of key people. Stop. Just... stop. This type of remark is the height of arrogance. The whole process of designing text blocks was in the open. It was a preview feature for two releases (three if you count the raw string proposal in JDK 12) and thousands of people gave their feedback what they wanted to be changed. That your preferred version wasn't chosen is not the result of "the unsubstantiated aesthetic view of a handful of key people", but of this process.
- vii 7y agoAgreed that the whitespace elision is overly complex and too prescriptive for a small issue. Either whitespace is important or not; if not it doesn't matter so there should be no special handling, and if it does - the special handling is very confusing. Scala has stripMargin, integrated into IntelliJ to explicitly indicate how to dedent the text block. Kotlin has trimIndent. Anything that takes this long to explain should not be a core language feature.
- somewhereoutth 7y agoFor me, it would feel natural for the significant whitespace to start aligned with the beginning of the statement that included the text block: -----String s1 = """ -----<outer> ----- <inner/> -----</outer> -----"""; this works fine when there is no final line end too, as the closing quotes are not used for whitespace significance.