wxPython and macros (was: Why don't people like lisp?
tayss_temp at yahoo.com
Mon Oct 27 12:10:20 CET 2003
Ok, now being sober...
mike420 at ziplip.com wrote:
> Why do you need a macro for that? Why don't you just write
> def start_window(name) : # 1
> app = wxPySimpleApp() # 2
> frame = MainWindow(None, -1, name) # 3
> frame.Show(True) # 4
> app.MainLoop() # 5
> return (app, frame) # 6
Remember that we lose this game if lines #2-5 are executed out of
order. The system crashes.
Notice in #1, you used a string ("name") as the parameter. But that's
weird, you'd rather have all of line #3 as the param, not just the
little string part of it. So why can't you do that? The secret is
that strings don't have big side-effects when they execute, but line
#3 does! If you tried calling start_window() with the value of #3,
the call would execute it immediately and the system crashes.
Your example above is sensible, because we don't have the power to do
anything more meaningful. So we're stuck with some trivial function
that does nothing really important. Boa Constructor, the great Python
IDE, pops up three windows of different kinds and names on startup,
but /we/ are stuck with the trivial ability to customize one window's
Sure, we can perform all sorts of functional programming tricks to get
things to execute in the right order as mentioned here:
but we lose readability, which was the point of this exercise.
Maybe you argue this particular code only occurs once per app; but
there's a good documentation and maintainability advantage of having
stuff done once, and done right. And we talked about closing files
safely with try/finally earlier; that is something that needs to be
done often, and macros are a good way to do it. If I learn #5 should
be in a finally block, I don't want to do a big hunt and replace on my
> Conclusion: you don't need macros here.
> Moral: maybe you do not *deserve* macros.
If you think I should be a good boy and go to school only reading the
safe books, getting a spanking when I look at the dangerous ones, well
that's one philosophy of life.
More information about the Python-list