Unexpected Python Behavior

A

Andrea Griffini

It's clear to you, possibly.

Yes. Feel also free to add "IMO" at every phrase. I originally
wrote "it's clear to me" but then removed it because I didn't
like the sound of it (to me...with me).
Hate? This doesn't sound like the Alex I know (and I'm talking about
through the face meetings here, not just net acquaintanceship) This guy
was the technical editor for my book, and I know him to be not only
technically brilliant but also an affable and congenial person).

Yes... I can very well understand that this is not the Alex you
know, but it's the Alex I know. Would you just please blank
out the names and read the messages instead ?
Well, clearly not with an attitude like that. Frankly that's about as
insulting as you should be getting around here. In fact I think you've
gone too far. I preferred the sarcasm.

Can you take the time to read my messages in this thread
and Alex' replies to my messages, and tell me when was that
I passed the reasonable limit ?
Perhaps anyone who has opinions that vary from yours has a problem
requiring psychotherapeutic help? I'm beginning to sense that I too am a
little unbalanced.

I'm not talking about this. I think Alex has a problem
with me and I really do not understand why this happened.
The problem (as I see it) started many years ago in a C++
newsgroup when I simply noted that at that time it was
IMO unfair to compare what the return code approach was
actually able to deliver (basically *all* the software we
were using at that time) with what the exception approach
was just promising.
The theme is of course very complex, but the discussion
simply ended on the spot because Alex understood that I
was calling him a dishonest (?) and then plonked me or at
least said he did (and shortly after actually left the group).
Before the alleged plonk I asked if he could actually provide
evidence that the exceptions-everywhere approach was paying
off in complex systems (I think exceptions are just wonderful
in a few special cases - i.e. when you can "rollback" or
at least "restart" a subsystem - but they're not a panacea
in general when your program state is complex, distributed
and unprotected... the core problem I see is that "strong"
exception safety doesn't scale up by composition) but his
reply was that he couldn't provide examples because it was
secret material (!?).

All this is probably on google, of course; but it's in italian.

What surprised me however is that nonsenses like the risk
of name rebinding (that pervades python; that is the
*essence* of python) were not commented. Why f,g = g,f and
not math.sin,math.cos = math.cos,math.sin ?

May be is the "pythonic" way to always privately import and
then bind functions to local names and doing all this
by using fake parameters with a default value ?

I was suprised that no one noted that if we want statics,
and the "hasattr" approach is slow then *the slowness* is
the problem. Probably a static keyword binding local names
to globally living objects to my newbie eyes would be the
best and would better describe the static local in C
(even if in python it would be arbitrary "how much" static
the var should be ... being the function definition an
executable statement should they be shared just between
calls of the same function instance ? should they be
shared between all instances of that function object ?)

I was also quite suprised about the discussion moving
to the microseconds when if I care about microseconds
the python is a questionable choice. True that python
is often "fast enough", but If I've to write uglier code
to get a 1.2x speedup then I can do it with other languages
instead of using something that is *essentially* slow
and get a 10x speedup. Ugly for ugly I'd use C++ (or
pyrex or whatever else) for that part if speed is a problem.
I saw just one message saying what I (as a newbie to python)
think is obvious to at least anyone with a reasonable brain
and cold enough to think without prejudice; i.e. that defining

def foo(x, cache=[])

when you've no intention to receive that parameter is a purely,
simply, uncontestably, stinking, ugly hack (also IMO adding
underscores to that "cache" name is not making this hack really
any prettier).
Well, of course, as a newbie to Python you are clearly in a far better
position than anyone else to say what's reasonable. This couldn't
possibly be a sensible use of name scoping rules to avoid the necessity
for a static declaration, could it? Dammit, you know what a function is,
and if it has parameters then we should damned well use them in the calls.

Right.

I'm sorry I don't understand if this is sarcasm or not...
are you really saying that using those fake parameters is
not an ugly stinking hack for the absence of a sensible
way to declare function static variables ?

Where do you stop ? Is it beautiful to use them also for
binding builtin functions you need ?

What about adding an every-other parameter with a string
default just for adding per-parameter documentation ?
Well I don't often say this, but I think we have to get the attitude
adjusters out here. Just sit in this chair, please, you'll just feel a
little prick with a needle [this is a lie: I don't really have a
needle]. There, that should feel better. Take three of the purple
tablets a day, and come back when you are able to indulge in a
difference of opinion without suggesting that those of a different view
require therapy.

Is this humor ? I've had and I'm still having a lot of
discussions with people not agreeing with me, but luckily
enough not many were so personally aggressive as Alex.
With normal people I normally end up agreeing on something,
or my counter-part does the same, or, most often, it's a
mix of the two. There are cases in which the discussion
ends up with everyone remaining with the same starting
position. But rarely I got to the "puh-LEEZE" level.

When things tend to degenerate my standard reaction has
been lately to just keep silent. This normally happens
after writing a VERY long reply, that I just avoid
posting... not because I fear the consequences; but
because all the content seems me so obvious that makes
clear the discussion left the land of logic and it's
entering the war territory. When someone I'm discussing
with is avoiding acknowledging even the obvious (and
it's clear that it can't be for a mental limit problem)
it's also obvious there's no point in keep discussing.
I don't suppose it's come to your attention that Alex is the author of
"Python in a Nutshell" and co-author of "The Python Cookbook", and
therefore rather well qualified to pontificate on the vagaries of Python
usage?

Sure I know that. I didn't read either however (yet).

But the key point is that your name is just not enough
to make drink what you say without thinking; sorry if
this sounds offending, but that philosophy is a part
of me I just can't shut off.

Say something convincing and I'll be more than happy to
agree with you. Say something that IMO is wrong and I'll
say it's wrong, whatever is your name (remaining of
course well prepared to accept an explanation if you're
kind enough to explain why you stand behind your position).

And (drumrolls) Alex Martelli name is surely not the
biggest I've had discussion with. By far.
I suspect the only offense he is actually guilty of is treating
you as better-informed than you actually are.

I can't find a way to say more clearly that I know
basically nothing of python. The biggest python program
I wrote so far is totalling a ridicolous 3800 lines.

But tell me that

def foo(x,my_personal_cache_so_please_dont_pass_this_parm=[]):
...

is beautiful and I can sign a paper where is stated
that you're either kidding or a dork.

Andrea
 
A

Andrea Griffini

Heh, this may in fact have something to do with his attacks -- we're
both nobodies from a nowhere land (Italy well qualifies for such
epithets;-), yet I'm reasonably well-known in this field and he's not...
some people need no more motivation than envy, in order to start spewing
venomonous attacks, after all;-).

So you feel attacked. You also feel being a nobody. That would
explain the reaction... but can you tell me when I started
spewing venomonous attacks ? I don't understand this part.
Seriously, being "well qualified to pontificate" isn't really the issue
here. For example, Greg Ewing is surely just as well qualified, yet
disagrees with me (and with the anonymous author of FAQ 1.4.21, and
presumably with Ka-Ping Yee, who uses the cache-as-default idiom in the
pydoc.py module he contributed to the Python Standard Library, ...) on
the specific point (while agreeing with me that evaluating default
values once at def-time is a good thing -- he has not commented on that
on this thread, but it's easy to google for what he said in the past).

Evaluating defaults at def-time is IMO a reasonable decision;
not the only reasonable one I can see (but remember I'm a newbie),
but still quite reasonable.

(mis)using modifiable defaults is however quite another thing,
the former *allows* for the latter; but the two are not IMO the
same. One thing is what is legal, another is what is moral.
Yet, none of us take such technical disagreements as excuses to spew
insults at each other, nor do we have the arrogance to proclaim our
opinions in the matter "uncontestable".

"puh-LEEZE" is the courtesy form for IMHO ? I'm an "hypocrit" just
because your little brain isn't able to grasp that difference ?

Then "I piss on your head" (please consider this as the courtesy
form for "I don't agree wholeheartedly with you") :)
I think these differences
between typical Pythonistas' behavior, and AG's, are important -- and
maybe, at one remove, they may help explain why you, I, Greg, Ka-Ping,
etc, can be "well qualified"... readiness to listen, and to argue with
the common courtesy civil people maintain, can help one _learn_...

Is this a calling everyone for a vote ? Sounds sorta funny...
and sort of pathetic at the same time.

Is there any specific reason for which you want me out of
python ? I was quite seriously thinking to pushing a lot for
adopting python as the main language for developing our next
CAD-CAM...

Andrea
 
V

Ville Vainio

Andrea> Yes... I can very well understand that this is not the
Andrea> Alex you know, but it's the Alex I know. Would you just
Andrea> please blank out the names and read the messages instead ?

Doesn't help much.


Andrea> Can you take the time to read my messages in this thread
Andrea> and Alex' replies to my messages, and tell me when was
Andrea> that I passed the reasonable limit ?

Actually, you appeared to pass the reasonable limits for this
particular newsgroup. This newsgroup is noticeably friendlier than
most of the other newsgroups out there - I don't know why, it might be
a byproduct of some cosmic similarity between people who dig Python,
or just a nice, contagious tradition.

What you might consider appropriate in a C++ newsgroup sticks out like
a sore thumb here. Going for Ad Hominem is always a bad idea,
especially when provoked by a purely technical discussion. I believe
you will learn to appreciate this tradition when you hang out more
around here.

Andrea> The problem (as I see it) started many years ago in a C++
Andrea> newsgroup when I simply noted that at that time it was IMO
Andrea> unfair to compare what the return code approach was
Andrea> actually able to deliver (basically *all* the software we
Andrea> were using at that time) with what the exception approach
Andrea> was just promising.

I guess comparing the ups and downs is reasonable, rewriting a big
pile of code is a different thing. Surely you agree that in Python the
exceptions are the way to go?

Andrea> off in complex systems (I think exceptions are just
Andrea> wonderful in a few special cases - i.e. when you can
Andrea> "rollback" or at least "restart" a subsystem - but they're
Andrea> not a panacea in general when your program state is
Andrea> complex, distributed and unprotected... the core problem I

Coding using exceptions is just much less ledious and
error-prone. Also, the code is much more readable when every line
doesn't have CroakIfError(stuff_that_needs_to_be_done()). Exceptions
are slighly less cool in C++ because of all the memory management
complications.

Andrea> May be is the "pythonic" way to always privately import
Andrea> and then bind functions to local names and doing all this
Andrea> by using fake parameters with a default value ?

Of course not.

Andrea> I was also quite suprised about the discussion moving to
Andrea> the microseconds when if I care about microseconds the
Andrea> python is a questionable choice. True that python is often
Andrea> "fast enough", but If I've to write uglier code to get a
Andrea> 1.2x speedup then I can do it with other languages instead
Andrea> of using something that is *essentially* slow and get a
Andrea> 10x speedup. Ugly for ugly I'd use C++ (or

1.2x speedup just isn't worth the ugly code, for typical
situations. Just go ahead and write pretty code, it's probably fast
enough as well. Premature optimization is the root of all evil.

Andrea> But the key point is that your name is just not enough to
Andrea> make drink what you say without thinking; sorry if this
Andrea> sounds offending, but that philosophy is a part of me I
Andrea> just can't shut off.

Name, perhaps not, but when you are a newbie at something, the more
experienced ones are right surprisingly often. Questioning stuff when
you are new is almost a rite of passage :).

Andrea> And (drumrolls) Alex Martelli name is surely not the
Andrea> biggest I've had discussion with. By far.

Again, completely unnecessary.

People do get pissed off on usenet, for one reason or another. When I
feel insulted (once here, a few times elsewhere), I just like to point
out briefly that what the other guy said was insulting, and stop
there. Unlike in "real life", the parent comment is there for all to
see, and everyone can draw their own conclusions. Perhaps the other
guy had a bad day, or has some personal issues to sort out; rarely is
it worth it fire back. There are no "debate points" to score, and
nobody thinks that whoever wields the sharpest sarcasm wins. It's not
slashdot, we are here with our real names :).

Andrea> But tell me that

Andrea> def foo(x,my_personal_cache_so_please_dont_pass_this_parm=[]):
Andrea> ...

Andrea> is beautiful and I can sign a paper where is stated that
Andrea> you're either kidding or a dork.

It's not beautiful, but it works, and is already in the language. Come
on, you are an old C++ hand, you are used to dealing with the horrors
of chtulhuan proportions daily. I'm a C++ programmer as well, and
nothing in Python compares to the dirt I deal with every day. Private
cache in param list is a minor issue.
 
G

gmduncan

(Hopefully a humourous followup - click here to escape.)

Yup, I walked 5 ks into town today to watch the movie only to find the
cinema was closed. Grumble - trudge back home (avoiding swooping nesting
magpies) to kick the cats and then browse c.l.p to relax (such a nice civilized
news-group).

And I see this - tusk, tusk. Jeez these Mediterranean types know
how to perpetuate a feud. Make you wonder what their married life would be like ;)

OOPs - just saw the clock; "The Godfathers" now on TV !

Bye

- Gary


P.S. Don't tell mee which of these vicious critters won ( I'm talking about
this c.l.p exchange - I'll see the movie tomorrow and see that victor ;)
 
A

Andrea Griffini

Actually, you appeared to pass the reasonable limits for this
particular newsgroup.

Ok, but when that happened ? Can you be more specific ?

Andrea
 
F

Fernando Perez

Ville said:
Andrea> But tell me that

Andrea> def foo(x,my_personal_cache_so_please_dont_pass_this_parm=[]):
Andrea> ...

Andrea> is beautiful and I can sign a paper where is stated that
Andrea> you're either kidding or a dork.

It's not beautiful, but it works, and is already in the language. Come
on, you are an old C++ hand, you are used to dealing with the horrors
of chtulhuan proportions daily. I'm a C++ programmer as well, and
nothing in Python compares to the dirt I deal with every day. Private
cache in param list is a minor issue.

Sorry to pitch in late, and forgive me if this has already been discussed and
thrown out for some other reason, I didn't follow the whole thread. Why not
use function attributes for the cache?

In [3]: def foo(x):
...: if x in foo.cache:
...: print 'x=',x,'in cache!'
...: else:
...: print 'new calculation for x:',x
...: foo.cache[x] = 1
...:

In [4]: foo.cache={}

In [5]: foo(1)
new calculation for x: 1

In [6]: foo(1)
x= 1 in cache!

In [7]: foo(2)
new calculation for x: 2

In [8]: foo(2)
x= 2 in cache!

I tend to prefer this to the cache-in-args-list approach, but maybe there was a
good reason in the thread (which I didn't read). You can do this with a
full-blown class which implements __call__, which I do when the function state
is really complex. But for simple cases where I just need a few things to
enhance a function's behavior, I simply slap the attributes I need on top of
it and I'm on my way. Simple, clean and pythonic, IMHO.

Cheers,

f
 
A

Andrew Dalke

Fernando said:
Sorry to pitch in late, and forgive me if this has already been discussed and
thrown out for some other reason, I didn't follow the whole thread. Why not
use function attributes for the cache?

In [3]: def foo(x):
...: if x in foo.cache:
...: print 'x=',x,'in cache!'
...: else:
...: print 'new calculation for x:',x
...: foo.cache[x] = 1
...:

In [4]: foo.cache={}

It was discussed. Here's Alex's comments

] def f(x):
] if x in f.cache: ...
] f.cache = []
]
] which among other things suffers from f.cache having to be
] used in spots that come lexically before it's defined; or
] a decorator equivalent:

Andrew
(e-mail address removed)
 
F

Fernando Perez

It was discussed. Here's Alex's comments

] def f(x):
] if x in f.cache: ...
] f.cache = []
]
] which among other things suffers from f.cache having to be
] used in spots that come lexically before it's defined; or
] a decorator equivalent:

Ah, thanks for the pointer. The thread seemed long and heated, so I skimmed it
lightly for fear of getting burned ;)

Somehow I've just gotten used enough to this that the
'use-before-lexical-definition' ugliness just doesn't bother me. But it's
probably a sign that I've grown into a long-term relationship with python:
I've learned to gloss over some of its defects as a price for all the good
things it gives me, and at this point I just ignore them without having to
work at it. I guess I'm officially married to the language :)

Best,

f
 
V

Ville Vainio

Andrea> Ok, but when that happened ? Can you be more specific ?

A good rule of thumb is, if one has sometime negative to say, and the
way of saying it focuses on someone else's person rather than the
issue as such, one is crossing the line. I have zero interest in
pursuing this issue any further, really, just wanted to point out that
you were taking an approach that might have been much more common in
some other newsgroup and therefore seemed acceptable.

Since you are obviously (judging from your other messages) not a
generic troll or otherwise "undesirable" material, it's easier for you
and the atmosphere of the whole newsgroup if you tone down the
approach a little bit.
 
A

Andrea Griffini

Andrea> Ok, but when that happened ? Can you be more specific ?

A good rule of thumb is, if one has sometime negative to say, and the
way of saying it focuses on someone else's person rather than the
issue as such, one is crossing the line.

Do you mean something like (for example):

"I've seen hypocrisy in my life, but this ridiculous
combination sure takes the prize!"

?
I have zero interest in
pursuing this issue any further, really, just wanted to point out that
you were taking an approach that might have been much more common in
some other newsgroup and therefore seemed acceptable.

I don't have any doubt you're tired with all this stuff...
however it would probaly have been way quicker instead of
writing a lot of general words just pointing out (I mean *cite*)
what is the passage of mines that you think was beyond the
acceptable limit.
Since you are obviously (judging from your other messages) not a
generic troll or otherwise "undesirable" material, it's easier for you
and the atmosphere of the whole newsgroup if you tone down the
approach a little bit.

Tone down what ? Do you mean my sarcastic message ?
I'm sorry, but if you expect me to:

1- Swallow without thinking any argument in a technical
discussion
2- Swallow insults received for no reason

then I've to inform you that this is not going to happen
anytime soon. No matter who is the author of the dubious
argument, no matter who is the author of the insult.

If turning off your brain and your self respect is your
definition of peace and harmony, then please do so and be
happy with it; but this is not my philosophy.

If I appear silent it's probably because I decided that
the counterpart is not even worth a direct reply; it doesn't
mean I swallowed anything. When I've to acknowledge an error
of mines, I say that quite clearly (and quite happily also).

Andrea
 
V

Ville Vainio

Andrea> On 05 Oct 2004 11:33:29 +0300, Ville Vainio <[email protected]>
Andrea> wrote:

Andrea> Ok, but when that happened ? Can you be more specific ?

"""
It doesn't matter *what* the great Alex says, just remember
*who* said it. Does the discussion about the risk of
rebinding names a total nonsense just because the very same
applies in that very same example to math.cos and math.sin ?
So ? Still it's Alex's word... widsom from another planet
you (a no-one) surely can't question.
"""

etc. etc.


Andrea> however it would probaly have been way quicker instead of
Andrea> writing a lot of general words just pointing out (I mean
Andrea> *cite*) what is the passage of mines that you think was
Andrea> beyond the acceptable limit.

Sorry - actually writing those general words were faster, I'm getting
pretty quick with this Dvorak layout ;-).

Andrea> Tone down what ? Do you mean my sarcastic message ?

Yes.

Andrea> I'm sorry, but if you expect me to:

Andrea> 1- Swallow without thinking any argument in a technical
Andrea> discussion

Of course not.

Andrea> 2- Swallow insults received for no reason

There's no need to swallow it - expressing the fact that one is
insulted doesn't hurt.

Andrea> If turning off your brain and your self respect is your
Andrea> definition of peace and harmony, then please do so and be
Andrea> happy with it; but this is not my philosophy.

Yes, pride can be a bitch to control. Swallowing one's pride is
extremely difficult for everyone, even more so when you have obviously
been mistreated.

From http://www.onlamp.com/pub/wlg/5499 :

"""

Danny referred to the Perl folk as "chaotic/good trickster archetypes"
and Python users as "peaceful,
northern-european-have-their-glasses-on-a-little-string-to-stop-them-loosing-them
sensible fellows".

"""

I guess one just gets used to a certain kind of mentality here. Of
course diversity is valuable etc. etc. I'm sure you will learn that
you won't need to swallow your pride all that often around these
parts, so this is really a minor issue. I guess we can now give this
issue a rest, and get on w/ whatever we need to get on w/ :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top