code is data

bruno at modulix onurb at xiludom.gro
Mon Jun 19 04:38:04 EDT 2006


Ravi Teja wrote:
> BJörn Lindqvist wrote:
> 
>>>Personally, I would like to see macros in Python (actually Logix
>>>succeeding is good enough). But I am no language designer and the
>>>community has no interest in it. When I absolutely need macros, I will
>>>go elsewhere.
>>
>>One must wonder, when is that? When do you absolutely need macros?
> 
> 
> Whenever there is significant boiler plate code that functions and
> classes cannot eliminate alone.
> Whenever there is a more elegant way to express your code.
> 
> Python 2.5 introduced conditional expressions and with statement. With
> macros, one would not have to wait for the language team to implement
> them. More so for features which only a small part of the community has
> an interest in.
> 
> I *like* 1..5 (ada, ruby) instead of range(5). If I had macros, I would
> have done it myself for *my* code.

And that's the downside with macros - and with anything that's not
officially part of the language or it's standard lib : everybody
implements it it's own way, and you end up with dozens non-standard ways
of doing the same thing.

Not to say this is absolutely bad, but there's a balance to be found
here. One could do function decorators long before we had official
syntactic sugar for it, but it only started to be a common idiom with
the @decorator syntax. Python 2.5 introduces a 'partial' type, that is
quite easy to implement with 2.4 (and probably with older versions too),
but having it in the builtins or standard lib means it will become the
standard way to do it - no need to deal with half a dozen half-backed
implementations of it no more.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list