why cannot assign to function call

Derek Martin code at pizzashack.org
Sun Jan 4 23:55:09 EST 2009


On Sun, Jan 04, 2009 at 09:30:20PM -0500, Steve Holden wrote:
> > I'm going to go out on a limb and assert that there's NO POSSIBLE WAY
> > a student could intuit Python's variable assignment behavior, having
> > never been exposed to that same behavior prior.  It needs to be
> > taught.
> > 
> As does assignment of any kind. 

I'm not sure that's true.  Having taken algebra prior to learning Basic,
I intuitively understood what this program would do when I executed
it, the first time I saw the code, and before I read the explanation:

10 let x = 10
20 print x

[Well, to be honest it's been a very long time since I've programmed
in Pet BASIC, and the syntax may be wrong.  The point is, just as I
did then, I am positive that you intuitively understand what the above
is intended to do, even if it is not valid BASIC syntax -- because if
you did not, we would not be having this discussion.]

> You can't argue that one semantic or another is more intuitive
> without offering evidence.

I think I have though, not that it matters, since that was never
really my point.  Python's assignment model requires more explanation
than the traditional one, simply to state what it does.  That alone is
evidence (but not proof).  I haven't proven it scientifically, and I'm
not willing to jump through the necessary hoops (which would require a
psychological study) to do so simply to win an argument on Usenet.
It's not about winning... it's about illumination. ;-)
 
> You're perhaps familiar with some algebra that I didn't study. 

Not unless you never studied it at all... ;-)

> In algebra and number theory identity and equality are equivalent. 

Indeed.  The point of bringing up algebra is that it provides a
background against which someone might be very likely to intuit what
variable assignment does in traditional programming languages -- at
least accurately enough to use it effectively without needing to
understand the underlying implementation and worry about any corner
cases.  It really doesn't need to be explained, unless the student has
no prior background in either math or computers.  In the case of
passing parameters things unavoidably get hairy, but at least at the
moment we're not discussing that, and also that has no analogous in
(at least high school) mathematics (at least, that I can think of) or
much of anywhere else from whence a student might draw any insights.

As for there being no assignment in algebra, is that not really what
variable substitution is?  They have different names, but in my
estimation they perform exactly the same function.  You're assigning
specific values to the variables in an expression so that you can
solve for a constant... just like in a computer program.  There is
even an allocation of memory: it's in your brain. :D

> This is far from the case in programming languages, so any analogy
> based on it is specious to some degree. Programming isn't
> mathematics (except perhaps for functional programming).

I agree; but I wasn't making an analogy.  I was pointing out (an
extremely likely) basis for intuition.

> It's difficult to think of a single aspect of Python that doesn't cause
> confusion in a typical year. 

Surely some cause more than others... and surely some are more
surprising than others. ;-)

> The confusion is sometimes caused by ill-informed comment. While
> well-informed, you appear to feel that everyone else should share
> your idea of what's intuitive and what's BIZARRE.

Alright, perhaps I exaggerated when I said bizarre, but I did explain
exactly what I meant, and I believe that what I said in my explanation
is at least arguably true.  I stand by the idea that it's much less
intuitive than the traditional assignment model, and despite your
protestations of lack of proof, I'm pretty sure you agree. ;-)

Ultimately, none of this really matters, as perhaps my point is that
Python *is different* from what A LOT of folks learning it have
already seen (if anything), and it's often easy for them to
misunderstand the Python way.  As you said, let's provide light, not
heat, when we come across people who get confused between Python and
something else.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20090104/6234fa4f/attachment.sig>


More information about the Python-list mailing list