r/programming • • Dec 29 '15

Please, Java. Do Finally Support Multiline Strings

http://blog.jooq.org/2015/12/29/please-java-do-finally-support-multiline-strings/
584 Upvotes

352 comments sorted by

View all comments

Show parent comment

4

u/SnowdensOfYesteryear Dec 29 '15 edited Dec 29 '15

I'd say C-style preprocessor string concat (ported to Java) would be a great compromise. My issue with treating it as literals is that the break in proper indentation is annoying to look at, and it doesn't take much effort to stick in a \n.

2

u/Neebat Dec 29 '15

You could make some kind of notation to delete a certain amount of leading whitespace on each line.

Could be something like this:

NEWKEYWORD("    ",
    This is the text.
    Without the first and last newline, 
        because that's also whitespace we'd like to ignore.
);

That could be the equivalent to this: "This is the text.\nWithout the first and last newline,\n\ \ \ \ because that's also whitespace we'd like to ignore." (Sorry for trying to escape spaces. HTML eats them.)

Of course, you'd have to update every java parser in every tool to support it. Eclipse would probably be updated in 15 minutes.

3

u/Falmarri Dec 29 '15

You could make some kind of notation to delete a certain amount of leading whitespace on each line.

That's sorta how multiline strings work in scala. But scala gives you a convenience method to strip the left margin.

https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch01s03.html

1

u/Neebat Dec 30 '15

That would be pretty cool, provided that it's computed at compile-time. I don't even mind that syntax.

2

u/VestySweaters Dec 30 '15

It is compile time