RFC -- HYGIENIC MACROS IN PYTHON

David Brady daves_spam_dodging_account at yahoo.com
Tue Feb 5 13:30:05 EST 2002


I've looked over your lingos examples, and my reaction
is twofold:  One, I'm excited that Python is powerful
and flexible enough to let you experiment with this
kind of stuff.  Two, you are dabbling in the dark arts
and are at risk of condemning your immortal soul to
the fires of hell.  ;-)

I am far from a Python guru, so I hardly speak for the
PSU; but I *am* an accomplished perl hacker who has
completely forsaken his immoral ways and converted to
the true light of Python.  What you are doing looks to
me like trying to bring perl and C syntax into Python,
rather than embracing the appropriate Python approach.

Specifically, a maxim of Python is that there should
be a right way to do everything, as opposed to there
being a hojillion-zillion different ways to do it (a
la perl).

Please understand I'm not attacking you or anything,
it's just that the examples you've shown are solutions
to problems that don't exist in Python.

Invariant: I don't see the purpose of the invariant
lingo, except as the target of a goto command.  Goto
has it's place, usually in trying to clean up
monolithic C code.  In Python, however, a better
solution is to simply design so that gotos are not
necessary.  Python replacement: def.

Unless: if not.  Having an unless keyword would make
*some* python code more clear to perl immigrants; but
it's only a matter of (a very short) time before
somebody writes "unless not" instead of "if".  Trust
me--I've seen that kind of syntax in perl, usually
written by people not paying attention.  (That's a
dirty little secret, isn't it?  That people write code
while half asleep, or they make a quick logic change
without really thinking it through?  But they do.  And
with the "one best way" maxim of Python, the code has
a greater tendency to survive these somnogenic edits.)

factor.  I'm not sure what "factor" does, but it looks
like a function call without the parens.

f(i): i=3. (Functions modifying their args.)  This is
the thing that tipped me off to your turning to the
dark side.  :-)  I struggled to get my mind around
this exact concept when I first came to Python.  The
fact is (as best I can tell) that Python deliberately
does NOT permit this.  If you want to modify a
variable, you HAVE to do it explicitly: i = f(i).

do.  Python replacement: while.  I agree that do and
while are not the same thing; do ensures that a loop
is executed at least once.  But again, with the
constraint of "just one way to loop" solutions seem to
sort themselves out.  So you have to write a
precondition; that's just a simple

p=GetFirst()
while(p):
    p = GetNext(p)

Personally, I think switch and do..while might be
worthy of a PEP, but in their absence I find myself
not just coding around their absence, but actually
*thinking* differently about the code.  For example, I
have started trying to redesign switch(x) syntax so
that x is an object instead of a condition, and
x.DoSomething() is the appropriate case/action for
that object.

This is just my $0.02.  Again, I think you may be on
to something, and I think it's cool that Python is
flexible enough to let you get there.  Good luck, and
please keep reporting on what you come up with!

Cheers,

-dB

=====
David Brady
daves_spam_dodging_account at yahoo.com
I'm feeling very surreal today... or *AM* I?

__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com




More information about the Python-list mailing list