prototypes in Python [was: what is good in Prothon]

has has.temp2 at virgin.net
Sun May 2 14:21:33 EDT 2004


jgardner at jonathangardner.net (Jonathan Gardner) wrote in message news:<6cc20cea.0405012255.5e352d27 at posting.google.com>...

> I'll admit that classless OO programming looks neat. The only thing
> that I can't see an obvious way of doing is to share a value or method
> across multiple objects.

A couple of ways I can think of:

1. Store the value in a module-level variable. This is not so odd an
idea as it seems; e.g. see Dylan as one example of a [class-based] OO
language where encapsulation primarily happens at module rather than
class level. My own proto-OO code is generous in its use of modules
and procedures. BTW, this may work particularly well in a language
that has first-class syntactic support for declaring objects, as
that'll allow you to put multiple modules within a single file (and
modules within those modules, and so on, if that's what you want).

2. Create a single shared object to store this value, and pop a
reference to it into a slot in every object that uses it so they can
access it there. If you also want this value available to the objects'
clients as well as the objects themselves, you can always make that
slot into a parent slot so that external requests for the value are
automatically delegated to it.


> Also, it kind of renders the question, "What kind of object is this?"
> meaningless. There are no /kinds/ anymore, at least not built into the
> language. 

Yep. In its purest form, a proto-OO language would have only a single
'type' - object - and no 'classes' at all. While folk who are used to
relying on type/class information to make their programs work may
freak a bit at the thought of this, languages like Python and Ruby
have already demonstrated that 'duck typing' can work well. (Again,
it's mostly just a matter of the developer having a bit of discipline
in the first place than relying on the compiler to pick up their slop
after the event. I actually regard this particular justification for
static typing - "it helps reduce bugs" - as a physical abuse of the
type system. Anyway, if I ever feel the need for strong compile-time
typing I'll go learn OCaml or something else with a really smart,
sophisticated type system, not C/C++/Java. Or Dylan, which'll give me
best of both worlds.)


> I do enjoy seeing different perspectives from other communities. It
> helps me get a new perspective with my own programming.

Absolutely! Personally I'm only fluent in two languages - AppleScript
(my alma mater) and Python (my current development platform of choice)
- but I've tinkered with a few others (a little C, Perl, JavaScript,
for example), and read up on at least a dozen more (Lisp, Forth, Java,
Smalltalk, Eiffel, ML/OCaml, Ruby, Dylan, HyperCard, Obj-C to pop some
names off the top of my head; and various niche languages I can't even
remember the names of). Often I just get a vague impression of what
these languages are trying to do, particularly on my first attempt to
understand them, but after a while the pieces start to slot into place
and I'll maybe go read some more. Sure I'm a shallow dilletante who
clearly hasn't got enough Real Work to go do with themselves, but just
wait till I REALLY get started! (Which is sure to be any day now, oh
yes; any day...;)



More information about the Python-list mailing list