1st non-trivial program - gentle criticism requested

Gary D. Duzan gduzan at gte.com
Fri Apr 14 09:58:51 EDT 2000


Fredrik Lundh wrote:
> 
> Gary D. Duzan <gduzan at gte.com> wrote:
> > This potential stumbling block makes me wonder if allowing the
> > singleton case was really wise.
> 
> stumbling block?
> 
> what kind of programmer changes his code without thinking,
> reading what he just typed, or running the resulting program?
> 
> if you want to optimize python for that kind of programmer,
> you have to change a whole lot more than the string formatting
> operator...
> 
> </F>

   My only point would be that if the formatting operator only took
tuples (oh, and dictionaries, of course), everyone would already be
in the habit of using a "(x,)" notation, so such changes wouldn't be
a problem. It is always nice to reduce the number of code points
impacted by a given change. I think it is arguably an easier rule
for newbies, as well, who may be thinking that the formatting string
is matching the variable, not its expansion. After all, "'%s' % x"
works fine when "x" is a string, number, list, dictionary, class,
instance, module, etc., but not if it is a tuple. Encouraging a
style that only mostly works isn't really a good thing and could be
considered a violation of the Principle of Least Astonishment.
   Not that I'm proposing a change, mind you; it is a bit late for
that. I'm just noting it as an issue, and suggesting that it may be
worth considering to discourage the use of the singleton version in
the future. (Of course, I'm being a hypocrite here since I use the
singleton version all the time, but I like to put my idealist/language
purist hat on every once in a while.)

					Gary Duzan
					GTE Laboratories



More information about the Python-list mailing list