Do pythons like sugar?

Andrew Dalke adalke at mindspring.com
Thu Jan 9 14:49:51 EST 2003


Carl Banks wrote:
> If I asked a question about how to get rid of self, and was told that
> self is necessary because code without self makes a poor
> implementation, I would say the same thing, because it's a damn petty
> excuse to refuse to answer the question.  That's not why Python uses
> self, and it's flatly wrong.

That's not what happened, IMO.  He asked two questions, one implicit
and one explicit.  The implicit one was "my code is ugly because of
all the self. references, [what can I do to improve it?]"  The explicit
one was a refinement of the original question, being "does Python
have a 'with self do' construct, which some other language use to
solve similar problems?"

Here's Afanasiy' OP so you don't need to find it.
] I've written this method for a text formatting class...
] But it's ugly as sin. With all those self's I consider
] it much less readable than it could be...
]
] A few languages provide syntax sugar for dealing with
] this by allowing you to localize the class scope.
]
] Does Python? eg. `with self do:`

First paragraph is the problem he's trying to solve.  That's
the one he wants really wants answered.

Second paragraph thoughts about how other language solve it.

Third is a question asking if the second paragraph presents
a solution which is available in Python.

We answered his more fundamental question of how to make the code
less ugly.  We "refused" to answer his second question because it
wasn't relevant to answering the first question.

When he asked for clarification on the second (explicit) question,
I said no, "with .. do" isn't available, there were other threads
on this topic, that the contruct turns out not being helpful (with
the implication he could Google for the other threads to see why),
and pointed out that it wouldn't help the code example he gave.

I then suggested a way to make it slightly easier for the cases
when a lot of self are needed.

I said there's a tricky one-liner which does what he explicitly
asked for in his second post, but that it shouldn't be used.  It
shouldn't, and I made a judgement that if I posted it it would
be detrimental to his code and any others which read it.

I also pointed out that if he wants that feature added to Python
then he needs a good justification for it, which means specific
examples, as in code.


> And when he said, "My design is perfect," he was being sarcastic, and
> was mocking Andrew Dalke's attitude.

Th OP said my attitude was brusque, or some such.  I've been reviewing
my post and I still don't see that.  Yes, I said his implementation
(not his design) was poor.  It is.  Five other people agreed with me.
Was it wrong to point that out?  It wasn't like I said it sucks or
other harshly disparaging terms.  It's poor code, and any code review
would point it out.  Not only that, I suggested how to improve it.

Since you agree with him (he having stopped responding to this thread),
perhaps you can clarify.  Was it that I wouldn't give him the rope to
hang himself by posting the exec trick?  His clarification was "object
members in scope?" and the exec trick does just that.  However, it will
only do what he expects for in-place modifications of mutable objects,
since it doesn't put locals back into module scope.

Or should I have explained all that too?

> What I do see is a presumptuous attitude from some of the reponders;
> maybe not condescending, but definitely presumptuous.

Presumptuous?  Because I made assumptions about his level of
Python knowledge based on the code he presented?

> He got unwanted answers to a question he didn't ask.

But he did ask it.  Just not with a question mark.


> So I sympathize with Afanasiy here.  It can be quite irritating to ask
> a question, and have someone second guess you for even asking.  And it
> can be very nauseating when that person treats you as if you actually
> did ask the question you didn't ask.

Hence herein I described exactly my interpretation of the OP, to
show exactly why I saw two questions.

 >  Replies like, "why are you doing it that
> way, you should do it this way," without any regard to the actual
> question, I find very rude.

There are other ways to have constructed the OP to make it more
explicit on what was requested.  The actual explicit question is


   Does Python provide syntax sugar for dealing with many self
   references by allowing you to localize the class scope?

That restated question is pieced together from across three different
paragraphs.  Had it been written that way, it would have had an
explicit answer.  It wasn't, hence the responses given.

> Whenever I want to offer alternatives, I'll usually answer the
> original question, if I know the answer, and then offer alternatives.

Hmm.  And here I thought I did.  1) rewrite the code, 2) put 'self.'
in the paste buffer.  I should also have offered 3) use local variables
instead of instance variables, but Simon Wittber already did that.

Yes, there was a solution I wasn't going to post, tough.  I
wasn't going to lie and say no when the solution wasn't a proper
answer to the question.  Nor did I want the obligation of explaining
how it worked, how it could go wrong, and why it shouldn't be used.

Perhaps I should stop posting then?

					Andrew
					dalke at dalkescientific.com






More information about the Python-list mailing list