Suggestions to triple quoted strings proposal

Bob Ippolito bob at redivi.com
Tue Dec 12 22:27:44 PST 2006


On 12/13/06, Stepan Koltsov <stepan.koltsov at gmail.com> wrote:
> Hi,
>
> I've read proposal of triple quoted strings at
>
> http://developer.mozilla.org/es4/proposals/triple_quotes.html
>
> And I have two suggestions. I've sent them to Brendian Eich, and he
> redirected me to this mailing list.
>
> I suggest to change interpretation of triple quoted string.
>
> First,
>
> I suggest to ignore first character of string if it is newline. So statement
>
> messageTemplate = """
> Hello,
> I've just...
> """
>
> should be equivalent to
>
> messageTemplate = "Hello,\nI've just...\n"
>
> , but not
>
> messageTemplate = "\nHello,\nI've just...\n".
>
> And second: to ignore same number of spaces as number of spaces in
> the line where triple quoted string started. Example:
>
> function query() {
>     return """
>     SELECT * FROM people
>     WHERE date_created > ? AND disabled = 'N'
>     """
> }
>
> should be equivalent to
>
> function query() {
>     return "SELECT * FROM people\nWHERE date_created > ? AND disabled = 'N'\n";
> }
>
> but not as now:
>
> function query() {
>     return "    SELECT * FROM people\n    WHERE date_created > ? AND
> disabled = 'N'\n";
> }
>
> I think that these improvements would make triple quoted string more
> useful and easier. Hope, these suggestions will be added to proposal.

Eh. String should just grow a method to do that. Literals are literals
and should be treated as such.

In Python you do that with the textwrap module.

>>> textwrap.dedent("\n    foo\n    bar\n        baz")
'\nfoo\nbar\n    baz'

The leading newline needs to be stripped manually (e.g. lstrip('\n'))
or more commonly the opening triple quote is followed by a line
continuation backslash.

-bob



More information about the Es4-discuss mailing list