Python's "only one way to do it" philosophy isn't good?

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Jun 23 21:06:54 EDT 2007


On Sat, 23 Jun 2007 14:56:35 -0400, Douglas Alan wrote:

>> How long did it take you to write the macros, and use them, compared
>> to running Pylint or Pychecker or equivalent?
> 
> An hour?  Who cares?  You write it once and then you have it for the
> rest of your life.  You put it in a widely available library, and then
> *every* programmer also has it for the rest of their lives.  The
> amortized cost: $0.00.  The value: priceless.

Really? Where do I download this macro? How do I find out about it? How
many Lisp programmers are using it now?

How does your glib response jib with your earlier claims that the
weakness of Lisp/Scheme is the lack of good libraries?

Googling for ' "Douglas Allen" download lisp OR scheme ' wasn't very
promising. If you have made your macros available to others, they don't
seem to be very well-known.

In fairness, the various Python lints/checkers aren't part of the standard
library either, but they are well-know "standards".



>> But if you really want declarations, you can have them.
> 
>>>>> import variables
>>>>> variables.declare(x=1, y=2.5, z=[1, 2, 4])
>>>>> variables.x = None
>>>>> variables.w = 0
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "variables.py", line 15, in __setattr__
>>     raise self.DeclarationError("Variable '%s' not declared" % name)
>> variables.DeclarationError: Variable 'w' not declared
> 
> Thanks, but that's just too syntactically ugly and verbose for me to
> use.


"Syntactically ugly"? "Verbose"?

Compare yours with mine:

let x = 0
let y = 1
let z = 2
set x = 99 

(Looks like BASIC, circa 1979.)

variables.declare(x=0, y=1, z=2)
variables.x = 99

(Standard Python syntax.)

I don't think having two easily confused names, let and set, is an
advantage, but if you don't like the word "declare" you could change it to
"let", or change the name of the module to "set" (although that runs the
risk of confusing it with sets).

Because this uses perfectly stock-standard Python syntax, you could even
do this, so you type fewer characters:

v = variables
v.x = 99

and it would Just Work. 


> Not only that, but my fellow Python programmers would be sure to
> come and shoot me if I were to code that way.

*shrug* They'd shoot you if you used "let x = 0" too.


> One of the reasons that I want to use Python is because I like reading
> and writing code that is easy to read and looks good.  I don't want to
> bend it to my will at the expense of ugly looking code.

But the "ugly looking code" is stock-standard Python syntax.

module.function(keyword=value)
module.attribute = value

is precisely the standard Python syntax you describe as "easy to read and
looks good" one moment. I don't believe you that you find it "ugly looking
code" -- if you did, you wouldn't be using Python.


-- 
Steven.




More information about the Python-list mailing list