Suggestions to triple quoted strings proposal

Brendan Eich brendan at mozilla.org
Tue Dec 12 11:40:51 PST 2006


On Dec 12, 2006, at 11:24 AM, Stepan Koltsov wrote:

> 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".

This is not what Python does:

 >>> s = """
...   hi
...   there
... """
 >>> s
'\n  hi\n  there\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.

This is a different kind of quoting than what " or """ means in JS or  
Python.  It seems to me to warrant a different syntax, if it's worth  
doing at all.  The counterargument besides "don't diverge from  
Python" is: "just don't indent or add extra newlines you don't want  
in the literal."

Literal means verbatim, quotes mean verbatim. Stripping leading  
uniform indentation (or did you mean any leading whitespace, even if  
the first line has three chars and the second has seven, etc.) is not  
verbatim.  Chomping leading and trailing newlines is not verbatim.  
The "KISS" principle favors the minimal, What you typed is what you  
get (WYTIWYG? sorry) approach.

My two cents, anyway.

/be




More information about the Es4-discuss mailing list