is there any principle when writing python function

rantingrick rantingrick at gmail.com
Sat Aug 27 00:26:37 CEST 2011


On Aug 26, 4:45 pm, Chris Angelico <ros... at gmail.com> wrote:
> On Sat, Aug 27, 2011 at 4:05 AM, rantingrick <rantingr... at gmail.com> wrote:
> > Now take a look at MY simple ONE module solution. It has JUST enough
> > methods and NOT a single more!
>
> I disagree - create_widgets() is completely unnecessary in the
> presence of show(),

Well since you cannot see the underlying code i won't be too harsh on
you :), but yes, i can assure you that create widgets IS necessary for
readability. show() calls "self.create_widgets()" then adds a special
hit tag to the text widget and sets up a modal behavior of the dialog,
it's only 5-7 lines of setup code but i think the separation is
warranted.

Could i have rolled all the create_widgets() code into the show()
method? Of course, however i do see a good reason for separation here
for the sake of readability. Although i must admit, had the interface
been much larger i most assuredly would have rolled it together.

> unless it's possible to show the dialog, hide it,
> and then re-show it without recreating the widgets.

Yes the instance lives on between session to save state. Also the
"find_again" binding of the text widget calls the
SearchReplaceDialog.find_again() method when {CONTROL+G} event fires.

> I'm sure there are. But let's face it: We're programming in PYTHON.
> Not C, not Erlang, not Pike, not PHP. Python. If this has been the
> right choice, then we should assume that efficiency isn't king, but
> readability and maintainability probably are; so the important
> considerations are not "will it take two extra nanoseconds to
> execute" but "can my successor understand what the code's doing" and
> "will he, if he edits my code, have a reasonable expectation that
> he's not breaking stuff". These are always important.

Bravo! That has to be most lucid and intelligent statement from you to
date. And i must say the warm fuzzies i got from imagining the defeat
D'Aprano must have felt whist reading it left me with a nice feeling.

How do like them apples, D'Aprano? :-)




More information about the Python-list mailing list