RFC -- HYGIENIC MACROS IN PYTHON

Gerson Kurz gerson.kurz at t-online.de
Tue Feb 5 12:10:52 EST 2002


On Tue, 05 Feb 2002 05:36:47 GMT, Courageous <jkraska at san.rr.com>
wrote:

>I am currently experimenting with an implementation of hygienic macros
>in a custom Python parser as part of a larger experiment.

Great, I love macros! They make for excellent code obfuscation ;)

Seriously though, I think its a very good idea. I'm known for rather
odd views on CS, so some would argue when I think its a good idea it
actually isn't (remember I didn't like exceptions?). Anyway, I like
macros, and here are a few reasons for it: 

- they can provide generic solutions that do not require runtime
interpretation (OK, that line is blurred in python). In many cases,
rather than resorting to a C++ "template", you can use plain
oldfashioned macros, and have much more fun, too. [Please, nobody tell
me that the C++ template syntax is cleaner than the macro syntax - one
look at ANY of the STL sources will prove you wrong]. 

- one change in the macro definition can change loads of code, even
code you didn't know exist, giving you POWER over LITTLE HUMANS, HA HA
HA <evil grin>.

- conditional macro redefinition makes for interesting code and has
the potential to scare the maintenance people - a property also known
as "job security". 

2 and 3 are probably nonsense; and 1 shows the main problem: because
all python code is interpreted, you could have generated the code
programmatically in python in the first place and have far more power
at your hand than any "third-hand" preprocessor might give (if I
understand you correct, you don't want to have a preprocessor,
though).

See, I too miss "do-while", but I can easily write a textprocessing
tool in python, that replaces

do:
	function()
while expression.

with

function()
while expression:
	function()

or some more suitable solution - in python itself. (Or, "of curse", in
"the VIC" as we all know since last week) 





More information about the Python-list mailing list