Python -Vs- Ruby: A regexp match to the death!

rantingrick rantingrick at
Tue Aug 17 00:58:15 CEST 2010

On Aug 8, 8:15 pm, Steven D'Aprano <st... at REMOVE-THIS-> wrote:
> On Sun, 08 Aug 2010 17:43:03 -0700, rantingrick wrote:

> > Ruby has what they
> > call a "Here Doc". Besides picking the most boneheaded name for such an
> > object
> It's standard terminology that has been around for a long time in many
> different languages.

Just because something has been around around for a long time does not
necessarily mean it's was a good idea to begin with. STRAWMAN!

> > As you can see it is another example of tacked on functionality that was
> > not carefully considered before hand.
> I disagree. It's an old and venerable technique, and very useful on the
> rare occasion that you have lots of quotation marks in a string.


>   Python strings have four delimiters:
>   (1) single quote '
>   (2) double quote "
>   (3) single-quote here-doc '''
>   (4) double-quote here-doc """
>   plus equivalent raw-strings of each kind.
> Trying writing that as a single literal in Python without escapes. There
> are work-arounds, of course, like using implicit concatenation, but
> they're ugly.

Yes, with the choices we have today writing strings like you mention
is terribly asinine. And don't forget about filepaths and regexps too
with all the backslashing nonsense! However, there is a simple
solution to this mess. Python "double quote strings" and Python
"""multiline strings"""(that are delimited by leading and trailing
double quote triplets) should behave as they do today.

However Python 'single quote strings' and Python '''multiline
strings'''(that are delimited by leading and trailing single quote
triplets) should be raw so that they do not interpret escape
sequences. Yes i know this would break backwards compatibility *again*
but this functionality should have been made available in Py3000 since
we were already breaking it anyhow.

Why do we need both """X""" AND '''X''' this if they do exactly the
same thing? Also why do we need both "X" AND 'X' if they do exactly
the same thing. A real chance to make something special was missed and
i hope one day we come to the realization that this proposed
functionality of strings (raw and normal) is sorely needed in Python.

> In Ruby they decided to be more general, so you can define whatever
> heredoc you need to quote whatever literal string you need. That's not
> bone-headed.

The fact that Ruby has multi line strings (*ahem*... HEREDOC's) is not
at all the point i take issue with. I take issue with the boneheaded
syntax. Have you ever tried to grep Ruby heredocs? It would have been
so much easier if they had made a spec like this...

mystring = :{
blah blah blah
blah blah blah

Or at least *some* static token instead of just creating something on
the fly each time.... now thats boneheaded!

More information about the Python-list mailing list