Multiline string literals
Peter Reilly
peter.kitt.reilly at gmail.com
Sat Aug 6 12:48:51 PDT 2011
Along with, ruby, python, perl, bash.
The only problem is handling of new-lines. The proposal
http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000087.html
suggests using a trailing U (for \n) or W (for \r\n) to identify
which line ending to use. so
String tablecreate = """
CREATE TABLE device (
addr INTEGER UNSIGNED NOT NULL,
name VARCHAR(255) NOT NULL,
descr VARCHAR(255),
snmpver TINYINT,
snmpcomm VARCHAR(255),
location VARCHAR(255),
PRIMARY KEY(addr)
) ENGINE=INNODB;
"""U;
for \n endings.
Peter
On Sat, Aug 6, 2011 at 7:31 PM, Serge Boulay <serge.boulay at gmail.com> wrote:
> I'm curious how Groovy and Scala do this because they both have multiline
> string literals.
>
> On Sat, Aug 6, 2011 at 12:03 PM, Llewellyn Falco <isidore at setgame.com>wrote:
>
>>
>> >
>>
>> > 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