Multiline string literals

Llewellyn Falco isidore at setgame.com
Sat Aug 6 09:03:39 PDT 2011


> 

> Peter bring up an interesting point about line returns being dependent on platform.
> 
> I believe there are 5 choices
> 1) all multiline strings are _____ (either "\r\n" or "\n")
> 2) it depends who compiled it
> 3) it depends who runs it
> 4) it must be stated
> 5) combination of 1&4 ( it can be stated )
> 
> I just wanted to explore these options.
> 
> 1) this is consistent, which I like, but also religious which I don't like. However it would also allow for things like ""hello"".replace( "\r\n", "\n")
> 
> 2) this might be confusing when compiled on different platforms, which is weird. But I also believe it would less likely to have multi-platform compiles.. This would be intuitive for new programmers. I believe this favors strings that are not spilt afterwards
> 
> 3) these bugs would not only be confusing, they would be hard to reproduce. I believe this favors things that are manipulated after.
> 
> 4) it could be like <string(windows/unix/platform)> blah blah blah </string> or
> @LineBreaks( "\r\n")
> Public void foo(){
> string s =""blah blah blah"";
> }
> 
> 5) I think this is self explanatory 
> 
> Llewellyn.
> 
> Ps. Java syntax is hard on an iPad :-(
> 
> 
> Sent from my iPad
> 
> On Aug 6, 2011, at 8:12 AM, Per Bothner <per at bothner.com> wrote:
> 
>> On 08/06/2011 03:41 AM, Peter Reilly wrote:
>>> Now that jdk7 is released and there will shortly be a process for
>>> asking for new small features in jdk8, I would like to ask that
>>> support for multiline string literals be considered.
>>> 
>>> This is a long standing request and a specific proposal is contained in:
>>> 
>>> http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000087.html
>> 
>> I think it would be a mistake for multiline string literals to have
>> the ending delimiter be the same as the starting delimiter.  It seems
>> lie it would make things more difficult for IDEs.  Using """ also seems
>> prone to syntax errors with possibly-confusing error messages.  And it makes
>> it harder to scan the text (visually or with tools) for matching delimiters.
>> 
>> I also think this is a questionable idea:
>> 
>> String platformDepended="""q
>> """;
>> is 'q\n' if compiled on Unix and 'q\n\r' if compiled on Windows.
>> 
>> This make the meaning of a program depend on which platform
>> it is compiled on.  Probably not something we want.  You could
>> change it to depend on the program it is *run* on, by defining it
>> in terms of line.separator - that would make more sense.
>> -- 
>>   --Per Bothner
>> per at bothner.com   http://per.bothner.com/
>> 



More information about the coin-dev mailing list