wxPython and macros (was: Why don't people like lisp?

Kenny Tilton ktilton at nyc.rr.com
Sun Oct 26 13:33:04 EST 2003



mike420 at ziplip.com wrote:

> Tayss wrote:
> 
> 
>>app   = wxPySimpleApp()
>>frame = MainWindow(None, -1, "A window")
>>frame.Show(True)
>>app.MainLoop()
>>
> 
> 
> Why do you need a macro for that? Why don't you just write
> 
> def start_window(name) :
>     app = wxPySimpleApp()
>     frame = MainWindow(None, -1, name)
>     frame.Show(True)
>     app.MainLoop()
>     return (app, frame)
> 
> Macros are used for other things! 
> 
> With this function, you can do
> 
> app, frame = start_window("a window")
> app.do_stuff()
> frame.do_whatever()
> 
> With a "macro" (if Python had them), you could define
> with_open_window(name), and do
> 
> with_open_window("a window")
>    app.do_stuff()
>    frame.do_whatever()
> 
> Conclusion: you don't need macros here.
> Moral: maybe you do not *deserve* macros.

They are unworthy? :)

You know, I'll say it again, considering the audience (Pythonistas 
debating amongst themselves whether to have macros) Lispniks should have 
emphasized from the get-go that one of the things macros do is clean up 
code visually (as demonstrated above). Some think I over-use macros, but 
I think I do so precisely because, like Pythonistas, I place a premium 
on visually clean code.

If you go here:

    http://alu.cliki.net/RtL%20Highlight%20Film

...and read the subsection "Power Hungry" you would think macros are 
there just for the expressive power. That's true about the power, but 
what is strange is that the response by some here has been "I can do 
that with an HOF or a metaclass! OK, it's a little messy, but...".

The problem is, they are precisely right! In fact, many a groovy:

    (with-groove-on (x y z) (do-your-ting))

expands directly into :

    (call-with-groove-on (lambda (x) (do-your-ting))
         :option-a y :option-b z)

Me, I am not as smart as some Lispniks, and I find that visual clutter 
makes it hard for me to read even my own code. I am a pathological slob 
in all aspects of my life, but when it comes to code I switch from Oscar 
to Felix (obscure "Odd Couple" reference). If code does not look 
aerodynamically efficient I shave down the corners, with a macro if I 
know the rough bit is such a key part of the framework I am building 
that it will appear in dozens or hundreds of places.

Now one very good point is that macros are a big change to make an 
already clean-looking language cleaner. ie, The added value may not be 
so great in Python as in other languages because another way 
(indentation) was found to clean up code (and in my experience the 
improvement is dramatic.

It will be interesting to see if Pythonistas can clean up your wxPython 
example using existing Python capabilities.

If so, ok, /now/ we can argue about whether Paul Graham is right when he 
says that some things can only be done with a macro:

     http://www.paulgraham.com/onlisp.html

:)

kenny the sophist


-- 
http://tilton-technology.com
What?! You are a newbie and you haven't answered my:
  http://alu.cliki.net/The%20Road%20to%20Lisp%20Survey





More information about the Python-list mailing list