[Edu-sig] re: Interactive interpreter: expressions vs. statements

Arthur ajsiegel@optonline.net
Mon, 17 Feb 2003 14:56:08 -0500


John writes -

>I think it's vitally important for programming students to learn the
difference between a function's RETURN VALUE and such "side-effects" as
OUTPUT (to stdout, to a >file, etc.)

I agree that the fundamental concepts here are more elusive to the beginner
than might be suspected by those to whom it has become second nature. But I
am not sure I think of it as a "expression vs. statement" issue.  Because I
guess I don't know how to think in those terms. Return  value vs. side
effecxts is a clearer concept to me - though, yes, it took some time before
it became clear.

A concrete example, with which Kirby happens to be familiar, was as to a
Python beginner exploring VPython.

He got stuck at the equivalent of:
>>> from visual import *
>>> def ball(incolor):
            sphere(color=incolor)
>>> ball_1=ball(color.blue)

#a blue sphere appears in a VPython window as expected

#But he expects this command to move the center of the sphere to coords
1,0,0
\
>>> ball_1.pos=(1,0,0)

# and gets

>>> Traceback (most recent call last):
>>>  File "<pyshell#7>", line 1, in ?
>>>  ball_1.pos=(1,0,0)
>>>  AttributeError: 'NoneType' object has no attribute 'pos'

He apparaently struggled with this for some time before screaming for help.

When we told him:

def ball(incolor):
     return sphere(color=incolor)

was what he was looking for, and why, it was to be a big revelation -
helping to put a whole host of issues in place for him. He was thrilled.

[
It also confirmed to me that VPython is a great way to get people started
and to illustrate basic principles, with the immediate visual feedback. I
know I have mentioned that 100 times before, but here I can offer a concrete
and real case, rather than one of my Zen intuitions.

*I* don't need that kind of confirmation, of course -  but others seem to
call for it. :)
 ]

Art