RFC -- HYGIENIC MACROS IN PYTHON

phil hunt philh at comuno.freeserve.co.uk
Tue Feb 5 20:53:08 EST 2002


On Wed, 06 Feb 2002 00:04:24 GMT, Courageous <jkraska at san.rr.com> wrote:
>
>>What if a macro needs to create local variables in its expansion?
>
>This is perfectly legitimate. What's not legitimate is...
>
>	deflingo myterm (i, codeblock):
>		j=3
>
>...where j=3 modifies the variable "j" in the context of the caller
>if this variable is preexisting in the caller. That's non hygienic
>behavior. Past experience with macros has shown this to be bad
>behavior; hence there is a design in the community for good "hygiene,"
>as it were.

And what if I decide that for my particular application, that's just
the behaviour I want? Or do you think that you know better than all
the users of your macro system, even though you've not met them and don't
know anything about the software they are writing? And if you take that
attitude, why not just use Pascal or Java?

>>IMO it is more Pythonic to say:
>>
>>   do:
>>      dosomething()
>>      while i <10                                                                                        
>
>Correct. I'm not quite sure how to handle that one.

It doesn't need handling; python does it OK already.

>But of course macros themselves significantly erode simplicity, making
>them _per se_ unpythonic, wouldn't you say? :)

If you are writing code for a complex system, your code needs to have a minimum
level of complexity. You can't get away from that, whether you use python or
any other language. The question is: will using a macro here introduce more
complexity than doing it another way. This is a question that can only be 
answered by having experience and, for want of a better word, taste.

Any dogmatic pronouncement that a particular programming technique (such as
macros) is inherently good or bad is just plain brain dead.



-- 
===== Philip Hunt ===== philh at comuno.freeserve.co.uk =====
Herbivore, a zero-effort email encryption system. Details at:
<http://www.vision25.demon.co.uk/oss/herbivore/intro.html>






More information about the Python-list mailing list