Tempers Erupt at Conference: Multi-Line Strings in Java
CodeToJoy Newswire
Satire City, CA
Jan 30, 2008
At a recent Java conference, tempers flared and developers ultimately took to the streets in protest over a controversial feature proposed for Java 7.
Prior to the conference, the proposition of multi-line string literals seemed benign: the concept is not new, and is found in many languages. An example:
String thePoint = """Unfortunately, the issue exposed deep philosophical divisions within the Java community, and civic unrest ensued.
i still
love
java""";
The School of Grafters
At the main presentation, one academic group pitched their proposal for multi-line string literals. Their thesis:
- "In another thirty years people will laugh at anyone who tries to invent a language without multi-line strings."
- This new feature will free programs of much of their accidental concatenationicity.
- Multi-line strings can be seamlessly woven/grafted into the language, without an extension to the existing Java type system.
- The implementation of multi-line strings could be a straight-forward application of Generics.
The Block Camp
From the outset, it was clear that this group was more conservative, and desired to block the proposition. The presenter made the following points:
- The usage of multi-line strings will encourage an exotic style of string concatenation, possibly fostering dialects and hindering string portability.
- A new feature should have a minimal addition to the lexical surface area: surely the + symbol has a higher power-to-weight ratio than """.
- James Gosling wrote, circa 1997, that Java is a "blue collar language" which modestly gets the job done. It's practical, not theoretical!
The Junkies and Dead-ends
Finally, the last speaker on the panel walked to the podium. In a quiet voice, he confessed that he was a feature junkie and that he represented a group of developers who were irrationally drawn to new features such as multi-line strings. He described the inner turmoil of being a junkie: living with both feature lust and also the burden of backward compatibility. His only solace was to consider Java a dead-end with respect to new features.
It was a tender moment, until his conclusion:
What's the big deal anyway? Why not use multi-line strings in Scala, compile the code down to bytecode, and just use that?At this point, the crowd erupted for the final time, streaming past the guards, and spilling into the streets. Soon, they carried placards and bull-horns, appealing for unity.
The mob protested for several hours until, finally, local police brought in staff from JetBrains to hand out free IntelliJ licenses.
10 comments:
You can take my StringBuilder.append().append().append() when you pry it from my cold, dead fingers.
This is a brilliant parody, very accurate.
Don't forget the scores of lesser multi-line string proposals.., and those who insist that single-line strings have worked for them for years, and multi-lines just don't work in the real world.
My favorite language of choice has had multi-line strings for years. This pathetic "me too" attempt by Java just shows how it's become an irrelevant, legacy language desperately trying to remain relevant.
PHP supports multi-line string 10 years ago. It even goes further with HEREDOC and NOWDOC, that may be included in Java 10.
@Ricky: thanks very much
Thanks to the others for the notes. I can't tell which comments are serious or not. At the risk of stating the obvious, this post is not really about multi-line strings.
What a wonderful word. 'Concatenationicity', it's got it all. Con as hustle or to trick. Cat a feline doorstop. Enation, it truly is the electronic age and Icity a reference to the information repositories of the world as the new cities. Great word and if you spell it backwards I've got no clue what it says. Go Cards.
To me this has always been an glaring omission in the language. I've always loved the way C and C++ lex strings, where string literals separated by whitespace are combined into one:
final static String code = "all "
"these chunks " "of string " "would be "
"combined. " "This is a contrived example "
"but it's very handy when formating chunks "
"of code, for example. "
// you can even skip lines
"and" /* embed comments */ " and "
" indent however you want "
;
Trivial to implement, easy to understand, doesn't complicate the compiler (trivial change to the lexer), no runtime overhead, and you're free to format strings over as many lines as you want, skip lines, embed comments, and use any indenting you want.
No clue why Java didn't adopt it, given how much else they borrowed from C and C++ syntactically. Oversight?
Wow, I thought forced decoration of multi-lined strings was an ill-conceived mistake of VisualBasic. What next? Every comment needs to begin with a // instead of using a block between a /* and */?
I really like the way this is done in C#. This would be so useful in my JAVA code when writing Hibernate HQL queries:
String query = @"
FROM User u
WHERE u.address.city = :City
ORDER BY u.address.zip";
Wouldn't that make the code so much more readable?
I'd like to see them expand on the C# concept and support syntax specifications:
String query = hql@"
FROM User u
WHERE u.address.city = :City
ORDER BY u.address.zip";
This would give IDEs the ability to easily and reliably apply appropriate syntax-highlighting and even code insight to multiline string blocks.
Such a syntax should also be easy to extend with other language syntaxes.
Post a Comment