String delimiter policy (was Re: Python Gotcha's?)

Chris Angelico rosuav at gmail.com
Thu Apr 5 21:20:12 EDT 2012


On Fri, Apr 6, 2012 at 11:03 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> KISS is a reason *for* allowing multiple string delimiters, not against
> it. The simplicity which matters here are:
>
> * the user doesn't need to memorise which delimiter is allowed, and
>  which is forbidden, which will be different from probably 50% of
>  the other languages he knows;
>
> * the user can avoid the plague of escaping quotes inside strings
>  whenever he needs to embed the delimiter inside a string literal.
>
> This is the 21st century, not 1960, and if the language designer is
> worried about the trivially small extra effort of parsing ' as well as "
> then he's almost certainly putting his efforts in the wrong place.

KISS and the Python principle of having one obvious way to do things
say that it's illogical to have utterly different ways to accomplish
the same thing, UNLESS they are justified. Allowing multiple string
delimiters makes it easier to hand-craft JSON; it makes it marginally
harder to parse JSON; and it makes it significantly harder to output
optimal code - you have to make a judgment call on which delimiter to
use, instead of just outputting a string according to the obvious
rules. Of course, you could always ignore one of the options and use
the other, but then somebody's going to file a bug saying "When my
strings contain double quotes, some-encoder-library escapes them
instead of using single quotes for delimiters".

ChrisA



More information about the Python-list mailing list