Mandis Quotes (aka retiring """ and ''')

Michael Sparks zathras at thwackety.com
Tue Oct 5 23:10:38 CEST 2004


Max M wrote:

> Jeff Shannon wrote:
>> Russell Nelson wrote:
> 
>> ISTM that these
>> elaborate Mandis-quote schemes may significantly reduce the odds of
>> needing to escape a string literal, but the cost (in clarity,
>> transparency, and most importantly, ability to manipulate your code in
>> anything other than an advanced, complying editor) is pretty high.  I
>> find '''triple quotes''' a lot easier to understand/explain than this
>> scheme of defining arbitrary delimiters.
> 
> In fact, the triple quotes are just special cases of the Mandis quotes,
> and would still be legal. No?
> 
> 
> '''Hello world'''
> 
> 'x'Hello world'x'
> 
> '4242424242'Hello world'4242424242'
> 
> same difference

Not really, no. " is essentially just '' as a single character. Indeed if
you look at some forms of documentation (tends to be older docs), you'll
often find things like ``this'' or ''this'' where these days people would
write "this". (Some ancient keyboards didn't have " characters, which
forced this approach)
As a result you have:
   * 'this'
   * "this"
   * '''this'''

Which is logically the same as the following, and can be viewed as the same,
with an optimised second case.
   * 'this'
   * ''this''
   * '''this'''

Likewise when writing, many people will interchange ' with ", hence '''
whilst odd isn't suprising to see - it's a logical extension, and still
looks like a form of quote. I've taken to using this incidentally in block
quotes in emails and interestingly I've not had any comments as to what I
mean by it.

However ...
> 'x'Hello world'x'
> '4242424242'Hello world'4242424242'

... are completely different kettles of fish.

to me I can't help reading those as mistypings of 
> 'x', Hello world, 'x'
> '4242424242', Hello world, '4242424242'

Which in turn look like mistypings. Far from being clearer you end up with
something that looks like typoes even when you know the rules. Indeed how
could you tell what the intent here was if you were presented with it and
knew there was a bug, and that there was an issue in the code?

foo = 'this'the'other'andnot'this' ?

Is that legal ? Does that mean:
   * '''this'the'other'andnot'this'''

or was it a rushed and they meant:
   foo = 'this',the,'other',andnot,'this' ?

Python often tends to do things which even if suprising are fairly obvious
what they mean to the casual observer. 'this' isn't like any other
mainstream programing language and as a result would confused people much
more than a simple 'this'.

(Is that a mandis quote or is it a sentance that makes no sense? :)

In many respects it's much like various tagging formats, but misses some
advantages eg xml:
<this> isn't like any other mainstream programing language and as a result
would confused people much more than a simple </this>

Unlike mandis quotes here we have a clear indication that the thing the
"this"s are distinct from the data. Also it's clear that the following is a
mistake:
<this> isn't like any other mainstream programing language and as a result
would confused people like <this> much more than a simple </this>

Whereas is the following a mistake?
'this' isn't like any other mainstream programing language and as a result
would confused people like 'this' much more than a simple 'this'

Personally I would say that if someone was _really_ interested in discarding
quoting schemes, there's one easy way of doing so - only ever use ''' and
""". It's trivial, it's implemented and is as you say very similar to
Mandis quotes, but doesn't allow for uses that make maintenance harder.

However personally I see a benefit between having """, ", ''', and ' - the
single quote form makes it explicit that the string should terminate on
that line, and makes it *a lot* simpler to find out if a quote is missing:
   foo = 'th,is',the,'oth,er',a'n,'dn',ot,'this' ?
Whereas """ makes it clear the string *doesn't* terminate on the same line. 

Mandis quotes don't really help with conveying _either_ intent.

Regards,


Michael.



More information about the Python-list mailing list