[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Easy object slot access in 5.2
- From: Tony Finch <dot@...>
- Date: Mon, 21 Nov 2011 23:26:06 +0000
Mark Hamburg <firstname.lastname@example.org> wrote:
> Cute. I used to dislike this sort of thing, but it has a certain amount
> of resonance and leads to thoughts like the following:
I was thinking of languages like Smalltalk, C++, Java, etc, that allow you
to refer to instance variables without having to prefix with this or self.
Not sure if this is a good example to copy, though!
> Couple this with an import keyword that defines a local based on a
> require and you then are back to running global free most of the time.
A related idea is language support for strict globals, i.e. you can't use
a global without previously declaring it. All the languages I mentioned
above explicitly declare instance variables. When you use _ENV instead of
self, a global declaration becomes an instance variable declaration.
> But I can also see all sorts of ways this sort of cute approach to
> things makes things more fragile as well. For example, the above code
> ceases to do what you were expecting if you happen to define a local
> named slot1 or slot2.
One advantage of _ENV over setfenv() is that _ENV changes can be
discovered by simple syntactic analysis.
Still I think using _ENV for objects is probably too unidiomatic to be
worth using in real code.
f.anthony.n.finch <email@example.com> http://dotat.at/
Humber, Thames, Dover, Wight: Southeast, becoming variable, 3 or 4. Smooth or
slight. Fog patches then showers. Moderate, occasionally very poor.