Why we will use obj$func() often

Mark Hahn mark at prothon.org
Sat Apr 24 02:07:47 EDT 2004


"Donn Cave" <donn at drizzle.com> wrote ...

> When I want
> a thing with persistent data, I'm thinking of an object.  One
> must keep things simple.

You aren't the only one who thinks that closures are unnecessary.  Dave
McQuigg has posted several messages today making that argument.  I also have
several people saying they couldn't live without them.  One javascript
programmer says he uses instance variables for access outside of objects
(properties) and closure variables for storage variables inside objects.  He
has posted a lengthy messge about it on the Prothon lists.  Go figure.

I personally think the complications of adding one '&' prefix to give all
the benefits of closures is a good trade-off.  No matter how much people
rant and rave about Prothon heading down the path to the Perl-y gates of
hell (sorry about that pun) I refuse to believe that some ugly punctuation
is going to ruin an otherwise good language.

> I might seriously
> consider what I believe we call lexical scoping, and a declaration -
> not assigning a type, but an initial value, like "let x = 0".
> Namespaces like Python's would be for objects - modules, classes,
> class instances, whatever - not functions - and would be purely
> explicit, not implicit like a scope (I think that would most
> conspicuously require some alternative for "def" statements,
> for example.)

I'm not following you exactly, but I think what you are asking for is the
declaration of variables with "let x = 0", or what some languages use is
just "var x" that specify that the variable belongs in the scope of that
declaration.  This resolves the ambiguity of local versus global variables
and even gives a nice solution for closures.

That is an interesting idea.  It turns out to be a little harder for the
compiler and program reader to use because both have to still scan the code
to find that declaration and discover what scope a variable belongs in,
although it is much easier than the current Python scheme where there are
complex rules and more code scanning involved, but less typing.  The Python
intrpreter requires three scans to parse the source and generate bytecodes.

The advantage of prefix symbols that Ruby and Prothon use right now is that
the compiler and the program reader don't have to scan the code at all to
see what scope the var belongs to.  When you see the & you know it's in the
surrounding function, when you see a capital letter you know it's global to
the module, when you see a lower-case letter you know it's local, etc.  Once
you get used to it the code is much more readable.  The Prothon compiler
parses source and generates code in one fast pass.

I'm sorry, I got into sales pitch mode again.  I'll let you go.  It's been
interesting chatting...





More information about the Python-list mailing list