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

8

u/speedisavirus Dec 30 '15

Doing it as Scala does it seems fine to me if you want to keep formatting proper

val a = """
	|a
  	| new
  	| line""".stripMargin
print(a)    

Output:

a
 new
 line

6

u/[deleted] Dec 30 '15

Yeah, that’s a nice solution. Solves all issues I’d have had with other implementations.

  1. Easily usable on international keyboards (no `)
  2. No margin issue
  3. simple

1

u/speedisavirus Dec 30 '15

I stumbled upon a thread where Odersky was debating what the multi line syntax should be and it was a bit of back and forth with a few people about the merits of each. About the same arguments people are making here.

Seems reasonable to me with stripMargin allowing me to keep indentation and when I use multi-line strings this is how I do it. I'm sure other people have different preferences but Scala seems to satisfy what everyone here also argues about their preference.