473,769 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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(na me) :
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_whatev er()

With a "macro" (if Python had them), you could define
with_open_windo w(name), and do

with_open_windo w("a window")
app.do_stuff()
frame.do_whatev er()

Conclusion: you don't need macros here.
Moral: maybe you do not *deserve* macros.
Jul 18 '05 #1
16 2420


mi*****@ziplip. com wrote:
Tayss wrote:

app = wxPySimpleApp()
frame = MainWindow(None , -1, "A window")
frame.Show(Tr ue)
app.MainLoop( )

Why do you need a macro for that? Why don't you just write

def start_window(na me) :
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_whatev er()

With a "macro" (if Python had them), you could define
with_open_windo w(name), and do

with_open_windo w("a window")
app.do_stuff()
frame.do_whatev er()

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

Jul 18 '05 #2
Kenny Tilton wrote:


mi*****@ziplip. com wrote:
<snip>

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.


< snip> 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.


After debating this topic, I have a slightly better understanding of how
I would use macros if they existed in python. My thinking is pretty
much dealing with book-keeping and resource handling.

Specifially talking about wxPython, in some class constructors, any non
handled exception (in, for example, wxFrame) can crash the application
with no tracebacks. Additionally, when subclassing some wxPython
classes, the base class *must* be called first. These issues could be
solved with macros in a perhaps clean fashion. Naturally, you don't
*need* them, but they do reduce book-keeping and visual clutter in my
opinion.

class wxFrame:
def __init__(self, ...):
with wxFrame_init(se lf, ...):
special constructor code here
as opposed to

class wxFrame:
def __init__(self, ...):
wxFrame.__init_ _(self, arguments)
try:
special constructor code here
except ...:
# handle errors, perhaps writing to a log
# close down the application with an appropriate
# error message

Perhaps I have become converted :) I also think that this could fit in
nicely to the python environment. Much more than I would have before.
I wouldn't use macros to change the language, but to provide fail-safe
handling for common tasks, sort of why I wanted to use python in the
first place.

Brian

Jul 18 '05 #3


Brian Kelley wrote:
Kenny Tilton wrote:


mi*****@ziplip. com wrote:
<snip>

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.

< snip>
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.


After debating this topic, I have a slightly better understanding of how
I would use macros if they existed in python. My thinking is pretty
much dealing with book-keeping and resource handling.

Specifially talking about wxPython, in some class constructors, any non
handled exception (in, for example, wxFrame) can crash the application
with no tracebacks. Additionally, when subclassing some wxPython
classes, the base class *must* be called first. These issues could be
solved with macros in a perhaps clean fashion. Naturally, you don't
*need* them, but they do reduce book-keeping and visual clutter in my
opinion.

class wxFrame:
def __init__(self, ...):
with wxFrame_init(se lf, ...):
special constructor code here
as opposed to

class wxFrame:
def __init__(self, ...):
wxFrame.__init_ _(self, arguments)
try:
special constructor code here
except ...:
# handle errors, perhaps writing to a log
# close down the application with an appropriate
# error message


Is the above meant to be for, say, wxFrame3D, a subclass of wxFrame?

Anyway...Yep. Any time there is boilerplate code one can slap it into a
macro. In the end only the bit that is different gets coded, so it
stands out more clearly and code is easier to read.

Now the million dollar question is: how could the longer version above
be cleaned up without macros, with HOFs or a metaclass hack or something?

kenny

--
http://tilton-technology.com

Why Lisp?...

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

Jul 18 '05 #4
Brian Kelley wrote:
Kenny Tilton wrote:


mi*****@ziplip. com wrote:
<snip>

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.

< snip>
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.


After debating this topic, I have a slightly better understanding of how
I would use macros if they existed in python. My thinking is pretty
much dealing with book-keeping and resource handling.

Specifially talking about wxPython, in some class constructors, any non
handled exception (in, for example, wxFrame) can crash the application
with no tracebacks. Additionally, when subclassing some wxPython
classes, the base class *must* be called first. These issues could be
solved with macros in a perhaps clean fashion. Naturally, you don't
*need* them, but they do reduce book-keeping and visual clutter in my
opinion.


Yes, exactly! :)
Perhaps I have become converted :) I also think that this could fit in
nicely to the python environment. Much more than I would have before. I
wouldn't use macros to change the language, but to provide fail-safe
handling for common tasks, sort of why I wanted to use python in the
first place.


Well, but that's exactly what language design is all about.

Consider the following two functions that both do the same thing:

(defun example-1 (x)
(let ((i 0))
(tagbody
:loop
(when (> i x) (go :end))
(print i)
(incf i)
(go :loop)
:end)))

(defun example-2 (x)
(loop for i from 0 to x
do (print i)))

EXAMPLE-1 requires lots of book-keeping in your head, especially when
things get messier. EXAMPLE-2 uses a for loop "just" to reduce
book-keeping and visual clutter. ;)
Pascal

Jul 18 '05 #5


Pascal Costanza wrote:
Brian Kelley wrote:
Kenny Tilton wrote:


mi*****@ziplip. com wrote:
<snip>
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).
could be solved with macros in a perhaps clean fashion. Naturally,
you don't *need* them, but they do reduce book-keeping and visual
clutter in my opinion.

Yes, exactly! :)


And to think someone said I do not know anything about marketing? Oh,
here he is:

http://alu.cliki.net/Erann%20Gat's%2 0Road%20to%20Li sp

:)

--
http://tilton-technology.com

Why Lisp?...

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

Jul 18 '05 #6
Whoa, I bow to your ability to start endless threads.

I just started drinking something when I came across this, so let me
just recap a few things, because I sense you pushed me out of context:
- Lulu inspired me to think about the nature of languages, and I
thought it was worth pointing out that frameworks were like verbose
languages. So it's not like macros are the unique evil.

- Any well-designed language with macros will have tools to help you
deal with them. Macros are after all just another tool to help you
manage complexity.

- My audience was those curious few following the thread, not the
Pythonista skimming usenet for good tips on daily work. So I'm kinda
wondering if they're angry all these threads are shoved in their
faces. I'm not out to convince, just entertain thoughts.

- I experiment. Python/wxPython was the right choice for the project,
but sometimes the soul aches for Lisp's ability to bend reality. With
Python, I can often shorten distances while running. With Lisp, I can
make reality seep into cracks and bend it around me. Maybe that's the
alcohol talking.

So when I'm coding along and a framework rubs up against me and I
wonder if it's not so maintainable, I start considering whether
there's a way to fix things. I spend a couple minutes looking at
alternate ways to express myself, and no matter if I drop or keep it,
I've learned something. Whether or not I have good taste is something
else; if I have bad taste you can bet I've been making bad decisions
with every other mechanism I can get my hands on. (Object-oriented
programming!)
-- Tayssir
Jul 18 '05 #7


Tayss wrote:
...So I'm kinda
wondering if they're angry all these threads are shoved in their
faces.


I worry, too. I console myself with premises minor and major:

minor: my newsreader shows the subject of a message. :) it also has an
"ignore thread" menu item. a couple of clicks and an asinine thread
about whether Scheme is a Lisp does not exist AFAIAC. Or I can save the
click and Just Not Read(tm) the bullshit.

major: Information Is Deeply Good. Don't ask me why, it just seems to
reliably turn out that way. Pythonistas are by definition Seekers (sheep
have the Establishment-Approved Java and C++.) Seekers do not mind
Information. And even if one resents the threads, I think one would
concede that folks are /not/ off track yelping about one language or
another, the conversation has stuck reliably to "life with macros".

I am one of those Lispniks who is always open to new technology but who
also believes "No macros? No, thanks." If you follow the link in my sig
you'll find more (and there were a few who said the same but got quoted
for some other remark).

Python has a lot of other stuff strongly reminiscent of Lisp. Y'all
should at least get to know the one feature that makes Lispniks most
ecstatic before dismissing it.

My 2. kenny

--
http://tilton-technology.com

Why Lisp?...

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

Jul 18 '05 #8
Kenny Tilton <kt*****@nyc.rr .com> wrote in message news:<_y******* ************@tw ister.nyc.rr.co m>...
Now the million dollar question is: how could the longer version above
be cleaned up without macros, with HOFs or a metaclass hack or something?

kenny


Probably yes. For what concerns automatically calling the base class
__init__ method with a metaclass, see this thread (sorry for the long
URL):

http://groups.google.com/groups?hl=e....lang.python.*

It is interesting to notice that I never use this trick since
"explicit
is better than implicit" and I do prefer to call explicitly the
__init__
method. I think it is better for the readers of my classes (including
myself six months from now).

Michele
Jul 18 '05 #9
Ok, now being sober...
mi*****@ziplip. com wrote:
Why do you need a macro for that? Why don't you just write

def start_window(na me) : # 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
name.

Sure, we can perform all sorts of functional programming tricks to get
things to execute in the right order as mentioned here:
http://groups.google.com/groups?q=g:...ing.google.com
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
old apps.

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.

-- Tayssir
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
2990
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can spare the time, I would appreciate any comments (including words like evil and disgusting, if you think they are applicable :-}) on the example here. Kenny -
303
17755
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
37
2812
by: michele.simionato | last post by:
Paul Rubin wrote: > How about macros? Some pretty horrible things have been done in C > programs with the C preprocessor. But there's a movememnt afloat to > add hygienic macros to Python. Got any thoughts about that? "Movement" seems quite an exaggeration. Maybe 2-3 people made some experiments, but nobody within the core Python developers seems to be willing to advocate the introduction of macros. > Why should you care whether the...
37
2899
by: seberino | last post by:
I've been reading the beloved Paul Graham's "Hackers and Painters". He claims he developed a web app at light speed using Lisp and lots of macros. It got me curious if Lisp is inherently faster to develop complex apps in. It would seem if you could create your own language in Lisp using macros that that would be quite an advantage.... I realize that Python has operator overloading and OOP so I'm not sure.
5
2328
by: sturlamolden | last post by:
Hello The Lisp crowd always brags about their magical macros. I was wondering if it is possible to emulate some of the functionality in Python using a function decorator that evals Python code in the stack frame of the caller. The macro would then return a Python expression as a string. Granted, I know more Python than Lisp, so it may not work exactly as you expect. Any comments and improvements are appreciated.
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.