[Tutor] Literal string concatenation (Was: Re: Combining dictionaries)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Sep 7 07:26:41 CEST 2005



On Tue, 6 Sep 2005, bob wrote:

> At 04:14 PM 9/6/2005, Mike Cheponis wrote:
> >On Tue, 6 Sep 2005, Danny Yoo wrote:[snip]
> >
> >How can I actively help fix these Python bugs?
>
> I am concerned when you use the term "bugs". The behaviors you describe
> are part of the design of Python, and they work as designed. To me a bug
> is a failure of something to work as designed.

Hi Bob,

This is one of those fuzzy boundary conditions, though.  It's not
technically a bug, but people mistake what it's meant for so much that I
consider it a Python wart.

Here's a small sample of people misusing or misunderstanding literal
string concatenation:

    http://mail.python.org/pipermail/python-list/2002-May/106643.html
    http://mail.python.org/pipermail/tutor/2003-December/027170.html
    http://mail.python.org/pipermail/python-list/2005-April/277513.html

Granted, people sometimes make mistakes because they're just doing random
stuff.

The last one post, though, makes it very clear that the person has seen
examples of literal string concatenation before, and is naturally trying
to generalize the conceptual pattern.  That is, given previous experience,
the beginner is trying to integrate the idea with the rest of that
knowledge, and to much surprise, it doesn't work.

I can't blind myself and say that it's the beginner's fault for not
reading the reference manual.  Implicit literal string concatenation is
just one of those non-integrating special cases that smells kludgy. It
doesn't really help one learn the rest of the language, and I assert that
it causes problems, for both beginners and professionals. I too have made
the mistake of doing something like this in my own programs:

    ['this', 'is'
     'a', 'list',
     'of', 'strings']

Here, a comma (or a missing one!) makes a big difference.  If I make this
mistake, to keep my dignity and ego, I have to convince myself that other
people can make the same error.  *grin*


I don't harbor any illusions about getting this "fixed": it's part of the
way Python's grammar works, and it's not going away anytime soon.  But
it's something I do feel sad about.

Talk to you later!



More information about the Tutor mailing list