Do pythons like sugar?

Carl Banks imbosol at
Fri Jan 10 00:43:02 CET 2003

Andrew Dalke wrote:
> 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.

Well, I'm accusing responders of being presumptuous, and you've just
demonstrated it.  <shrug> What made you so sure that's what he really
wanted answered?  I'm surprised you would say this after he made it
clear he wasn't interested in anyone helping him rewrite his classes.
It's clear now you made the wrong assumption.

Personally, I don't think the assumption was warranted, even before he
made it clear that it wasn't what he was asking.  I see the first
paragraph as background information, not a question to be answered.

For the record, I was (and am) playing devil's advocate--trying to put
the other side into perspective.  He certainly hasn't displayed the
best tact, and I'm sure that has gone a long way into bringing out the
worst in the responders.


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

Rereading it, I don't think you were brusque at all.  He definitely
overreacted.  However, he was definitely being sarcastic when he said
his design was perfect; not trying to say he was a better coder (which
was the point I was trying to make).

> 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?

Well, I would have responded differently than you.  You said, "You
don't need it," which was a little rude.  He probably was asking for
it, but it was still a little rude.

If I had felt like you did, I would have said something like, "There
is a way.  I highly recommend you not use it; many Pythonistas
consider it bad style, it makes code harder to understand, and it has
some hidden dangers on top of that.  But if you insist, I'll tell

And if he had insisted, I would have told him, with a "use at your own
risk" disclaimer.

Sometimes it's best to just let them learn the hard way.

Of course, what I really would have done is not answered it at all.  I
just don't think it's nice to give someone alternate answers without
being prepared to answer (or help answer) the actual question.

>> 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?

No, because you made an assumption about what he wanted answered.
(Bennetts did that more brazenly than you, though.)


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

Look, I'm sorry, but I don't see it.  His original question was
explicit and specific, even if was a tad more wordy than it had to be.
He asked whether Python had syntax sugar for self; nothing more.  I
don't think it was warranted to assume he was asking anything other
than that.

You did not answer the question he asked.  (Ok, technically you did:
he asked, "Is there a way?"  I hope you agree that it's not an invalid
assumption that he also wanted to know how to do it.)

> 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?

Might have been a good idea.  It was a tough situation, I'll cut you
some slack, ok?  I was more bothered by Andrew Bennetts' attitude


More information about the Python-list mailing list