[Edu-sig] Explaining Classes and Objects
Scott David Daniels
Scott.Daniels at Acm.Org
Mon Jun 13 21:41:52 CEST 2005
Kirby Urner wrote:
>>Classes are not a feasible choice to start with because they are a most
>>complex structure in a programming language that builds on knowledge of
>>virtually anything else.
>>
>
>
> We agree on a lot of points.
>
> Because just about any decent Python script makes use of core data
> structures, such as the list, even if only as a range() return, dot-notation
> starts to be relevant right from the top. Explaining dot-notation as
> thing.action(inputs) identifies these "things" as the objects, with
> dot-notation being a postfix notation for calling, setting and getting.
>
> Yes, but I still need to explain dot-notation, even in the early days of
> just doing simple functions.
>
You might try: "These names don't just exist in some primordial soup.
There has to be a place they get stored. There is a bit of "magic":
import __main__
a = 24
print a, __main__.a
__main__.a = 365
print a, __main__.a
And even:
print a, __main__.a, __main__.__main__.a
Now everything is dot notation, with some of the "thing." stuff assumed.
Eventually you'll have to say locacal variables don't really work like
that, but they are close.
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Edu-sig
mailing list