class notes (post facto)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

class notes (post facto)

kirby urner-4
The login process was pretty smooth at PSU.  On first login,
they're asked to change passwords.

I kept harping on their needing to not forget the new passwords,
but of course it's the user names, not the passwords, they're
likely to lose.

It's all coming back to me now (I've taught this class, or one
like it, before).

I got to park blocks way early, visiting Libyan coffee shop
to get a some "joe" and the time of day (of all days to leave
my cell phone at home...).  Took the bus 14, then hopped
a light rail to get closer.  PSU is right in downtown Portland.

I decided to spend really quite a bit of time on the 1/2 == 0
business, still using Python 2.6.

Why?

In part because showing them how to get an answer of 0.5,
without doing the "from __future__" trick, is a great segue
into talking about types, i.e. to have an answer of 0.5, enter
something like:  1.0/2 1./2 1/2. or 1/2.0 or even 1.0/2.0

This leads directly to querying some named object as to
its type.

First go over assignment of names, using the assignment
operator, e.g. a = 2, then ask for the type of a -- type(a) --
to get <type 'int'>.

I consider "type awareness" sort of the alpha and omega
of this kind of computer programming (yes, being vague
about "this kind").

After yakking about both ints and floats, it's time to
introduce strings, which makes the learning curve go
steep like a rocket.  So much to do with strings.

I got into palindromes, and string reversal.  Had to ask
if anyone knew about Napoleon.  One student did, gave
us some history.  It's that old "able was I ere I saw elba"
back story, purely fictional.  I want to talk about
Napoleon again soon, in connection with The Turk,
the first chess playing automaton (or so Napoleon
supposedly thought he was playing, when he lost to
it -- if true, that coulda been traumatizing on some
level eh?).

Before getting to all that stuff about strings though,
I was into telling other stories.  Guido naming the
language after Monty Python (whom most had
heard of -- also looked at xkcd) and then getting
DARPA funding to write IDLE: a good way to
introduce IDLE itself, which we're using.

These are Windows XP boxes and IDLE tends to
work OK on those.  It's a disaster on some versions
of Mac though, found that out at STScI.

Steve Holden, PSF chairman, is raising this question
in the community:  is it time to retire IDLE, remove
it from the standard library?  Does it hurt Python
more than help it at this point?

Anyway, I like to tell stories.  If you ever wanna track
down the 52 minutes of me on Blip TV, from the
International Room of a Hyatt Regency near O'Hare
in Chicago, you'll find me plotting "lore" and "technical"
as orthogonal axes, with a kind of "opportunity cost"
curve representing finite bandwidth and a freedom to
keep varying the mix.

Get really technical for awhile, then go back to
sharing lore, then gradually add in more skills
building...

We went on to function defs,  which gets into indentation
heavy duty -- and the story of how Python is *not* a
curly-brace language.

I talked about the XO and OLPC, about Sugar, showed
a favorite picture.  I talked about the downward pressure
the XO had exerted in the calculator market, to where
now people had these 2- and 3 hundred dollar netbooks,
though without the swivel screen the XOs had usually.

I'll keep returning to these themes over the next few
days I'm pretty sure.

We did quite a bit with the arithmetic operators, but
so far not an excessive amount.  "Using Python as a
calculator" (interactively in a shell) seems to be the
"out of the box" experience many of us expect to
start with.  Good segue to Sage I would suppose.

One kid went 2**2**2**2**2.. **2 a few times, which
quickly maxed out computer memory.

Another kid hacked into his laptop at home, ran
Python there or some such.  This is a school that
attracts some of the freakishly gifted and otherwise
weird.  My job is to keep it all moving right along.

Lots of chatter about the C language, which several
of these students have tackled already.

I brought up APL and J as in some ways "other end
of the spectrum" (way alien) so they could appreciate
how different computer languages can be.  On the
other hand, Python and APL have quite a bit in
common too (especially when you add in numpy).

I talked about Scheme and LISP and how these
would have been your languages at MIT if just
starting into computer science.  Python has joined
that list of elite languages (presuming one looks up
to MIT, which by this time I've linked to OLPC, so
at least there's some credibility there).

The function I most wanted to have them define
would eat any string and return the same string in
reverse.  This is fun for playing with palindromes.

They'll probably dream about it tonight (I know I will).

One kid, who also asked about SSL (secure sockets
layer), a 7th grader, found out about "join" just by
browsing docs in a hurry (and asked them to shoot
for a solution out of the blue).

A solution is like:

def rev ( s ):
    mylist = list ( s )
    mylist.reverse( )
    return "".join(mylist)

Having already worked on s.capitalize( ) and
s.title( ), both of which return strings while leaving
s unchanged (how strings are), coming upon
mylist.reverse( ) is a bit of a show stopper.  You
mean some methods actually change an object
"in place"?  Change it's state?  No copies, no
output?  No "back up"?

That's right.

This is one of the things a functional programming
purist might most hate about OO in general,
Python in particular:  there's so much state,
and so much changing of state.

Some objects return (give birth, remain unaffected),
others morph before your eyes.  How might any
of this be pure logical, versus too messy-biological?

My thought on that is OO is aiming to mirror the
real world and the real world is messy in this way
too.  Logical abstraction only gets us so far in the
OO model.

FP promises to free us of state.  The Great Lambda
tribe to the north of Python Nation, sees our little
iconic lambda, and thinks about rescuing us from
ourselves.  "Liberate them from state" think our
would be rescuers.

The final activity was saving lesson1.py containing
this rev function into site-packages.  We'll pick
up with it tomorrow, by the end of which I'm
hoping to have crafted a Snake class already,
using __rib__ syntax (special names).

Getting this bit in pretty early helps clear up some
of the mystery as to why dir( object of some type )
keeps dumping lists of names looking __like__ __this__.

Doing a snake class with __repr__ and __init__ starts
to clear that up.  Showing off __add__ and __mul__,
maybe as some Integer Modulo N type of object,
might even further lift the veil.

I talked quite a bit about "dot notation" in general
terms, suggested that Python is a great gateway to
myriad other languages, in that how it uses dot
notation is common to all of them.  We imported
the random module and started playing with
randint, shuffle and choice.  One student demanded
to know how to reset the seed, but I bravely
suggested we'd postpone that discussion, but he
was most welcome to study the docs.

Kirby
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: class notes (post facto)

Litvin-2
At 01:54 AM 7/13/2010, kirby urner wrote:
>You mean some methods actually change an object
>"in place"?  Change it's state?  No copies, no
>output?  No "back up"?

I've found it disconcerting that in Python 3
lst1 += lst2 changes lst1 in place, while
lst1 = lst1 + lst2 makes a copy.

Gary Litvin
www.skylit.com

_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: class notes (post facto)

Vern Ceder
Litvin wrote:
> At 01:54 AM 7/13/2010, kirby urner wrote:
>> You mean some methods actually change an object
>> "in place"?  Change it's state?  No copies, no
>> output?  No "back up"?
>
> I've found it disconcerting that in Python 3
> lst1 += lst2 changes lst1 in place, while
> lst1 = lst1 + lst2 makes a copy.

Actually this behavior has been in Python since augmented assignments
were introduced in version 2.0. The official wording on this (buried in
the language reference) is (2.7 version, emphasis mine):

"An augmented assignment expression like x += 1 can be rewritten as x =
x + 1 to achieve a similar, *but not exactly equal* effect. In the
augmented version, x is only evaluated once. Also, when possible, *the
actual operation is performed in-place*, meaning that rather than
creating a new object and assigning that to the target, the old object
is modified instead."

It *is* a bit disconcerting, but I can't at the moment think of a likely
scenario where it would be a real problem.

Cheers,
Vern

>
> Gary Litvin
> www.skylit.com
>
--
This time for sure!
    -Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
[hidden email]; 260-436-0746; FAX: 260-436-5137

The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: class notes (post facto)

Litvin-2
At 11:16 PM 7/13/2010, Vern Ceder wrote:
Actually this behavior has been in Python since augmented assignments
were introduced in version 2.0. The official wording on this (buried
in the language reference) is (2.7 version, emphasis mine):

Vern,

I was comparing Python 3 with 2.5; the latter doesn't seem to do +=
for lists in place.
Gary Litvin

_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: class notes (post facto)

Vern Ceder
Litvin wrote:

> At 11:16 PM 7/13/2010, Vern Ceder wrote:
> Actually this behavior has been in Python since augmented assignments
> were introduced in version 2.0. The official wording on this (buried in
> the language reference) is (2.7 version, emphasis mine):
>
> Vern,
>
> I was comparing Python 3 with 2.5; the latter doesn't seem to do += for
> lists in place.
> Gary Litvin
>
According to the documentation it does. The documentation has pretty
much the same wording (see
http://docs.python.org/release/2.5/ref/augassign.html). I just tried it
with 2.5.2 and I got:

Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> a = [1,2]
 >>> b = [3,4]
 >>> c = a
 >>> a += b
 >>> c
[1, 2, 3, 4]
 >>>

So yeah, Python does += in place for all versions starting with 2.0.

Cheers,
Vern


--
This time for sure!
    -Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
[hidden email]; 260-436-0746; FAX: 260-436-5137

The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: class notes (post facto)

Mark Engelberg-2
In reply to this post by kirby urner-4
On Mon, Jul 12, 2010 at 10:54 PM, kirby urner <[hidden email]> wrote:
> FP promises to free us of state.  The Great Lambda
> tribe to the north of Python Nation, sees our little
> iconic lambda, and thinks about rescuing us from
> ourselves.  "Liberate them from state" think our
> would be rescuers.

This bit cracked me up.  I definitely see a bit of myself in that parody.

I've been heavily influenced by the essays and presentations by Rich Hickey:
http://clojure.org/state
http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey
so now I mostly perceive OO as a land in which people are woefully
confused about the distinction between identity and state, because
their languages don't allow them to make a distinction.  Thinking
along these lines, your story could be extended as follows:

Rich from the Great Lambda tribe was visiting his friend Guido down in
Python Nation.  At the end of his vacation, he pulled out his camera
to take a photo of Guido as a memento.  Guido shook his head,
"Cameras don't work properly here.  You can't take a snapshot of me,
it won't work."

"Why won't it work?" asked Rich.

"Because the photo will continue to change as I change.  Tomorrow, if
I grow a beard, your photo will show me with a beard.  If I get sick
or die, your photo will disintegrate."

"So what do I do if I want to remember you as you are now?"

"Hmmm," thought Guido, scratching his chin.  "I suppose you could make
a clone of me and take the clone back with you."

"But the clone isn't really a snapshot of you," retorted Rich.  "It's
another living, changing being with its own identity, and it will
continue to have its own experiences and diverge from you over time."

"Well, maybe you could keep my clone in a dark closet, and isolate him
from having any new experiences...."

Rich returned home to the Great Lambda tribe, and told everyone about
the absurd state of affairs in Python Nation.  Everyone had a good
laugh, followed by a sense of pity for their oppressed neighbors.

But the Great Lambda tribe knows it would be fruitless to launch a
full-scale liberation mission -- the population of Python Nation
wouldn't know what to do if liberated from their state oppressor.  For
now, the Great Lambda tribe has decided that the best course of action
is to make frequent flyovers in propaganda-loaded planes, dropping
educational pamphlets which enlighten the populace about the freedom
that exists in other parts of the globe.  :)
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig