gah! I hate the new string syntax

Donn Cave donn at
Fri Mar 2 19:47:39 CET 2001

Quoth "Mark Pilgrim" <f8dy at>:
| "Fredrik Lundh" <fredrik at> wrote in message
| news:B7In6.16281$Qb7.2658902 at
|> Sean 'Shaleh' Perry wrote:
|> > return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()])
|> >
|> > every day python seems to be moving closer to the line noise aspect of
|> > coding.
|> you're using list comprehensions and the wrong dictionary method,
|> and then you're complaining about string methods? ;-)
|> ("items()" returns a key/value tuple that you can pass directly to
|> the formatting operator.  and nobody will complain if you stick to
|> string.join for stuff like this...)
| I recognize this code as an example from my book "Dive Into Python",
| specifically, and would like
| to (partially) defend it in that context.
| 1. I used Python 1.5.x very little; I really only ramped up when 1.6/2.0 was
| released.  I *like* list comprehensions.  I prefer them over map/lambda
| because of scope issues, and I prefer them over for loops because they force
| me to think Pythonically, and they emphasize Python's strengths (less code,
| richer data structures).  To my eyes, list comprehensions fulfill Python's
| promise of being readable pseudo-code, not readable line noise.  YMMV.

Pseudo-code is the language you don't have to know, to understand,
right?  Familiar symbols, unambiguous syntax.  Could you articulate
your thoughts on this, how do list comprehensions improve on their
alternatives, there?

What does "think Pythonically" mean to you?  What are you thinking of
when list comprehensions make you cite "less code, richer data structures"
as a strength of Python?  Can you talk us crotchety old-timers through this?

| 3. I *like* string methods, even .join().  I am aware that this puts me in a
| very small minority on comp.lang.python.  But I would maintain that
| ";".join(...) only seems odd to you because you see it as the result of a
| strained migration from string.join(..., ";"), instead of seeing it with
| fresh eyes.  However, I may add a footnote explaining the old style
| string.join, if only because new programmers will eventually come across old
| code that uses it.
| If current trends continue, *far more people* will learn Python 2.0 than
| ever learned Python 1.x.  They will all take list comprehensions and string
| methods for granted, and stare at you blankly when you reminisce about the
| good old days of Python 1.5.2.

I bet when people see ";".join(...) with fresh eyes, they still
find it strained.  This is not about the old school vs. the new,
it's a serious question of how people understand computer programming
languages.  Is it like natural language?  Can we think about it in
sort of mathematical terms, like symmetry etc.?  Does everyone handle
it basically the same way?

For sure, more people will learn 2.x.  But they're here because of
the success of previous versions, not because 2.x was finally good
enough for them to get on board.  It doesn't tell us anything about
the value of features introduced in 2.x.

	Donn Cave, donn at

More information about the Python-list mailing list