Re: Variables and closures (Was: Objects and Relations)

From: Marshall <marshall.spight_at_gmail.com>
Date: 9 Feb 2007 22:32:10 -0800
Message-ID: <1171089130.887490.138400_at_s48g2000cws.googlegroups.com>


On Feb 9, 8:25 pm, Chris Smith <cdsm..._at_twu.net> wrote:

>

> So in Java, for example, a[5] (where a is an array) is a variable. In
> C++, it is not; but the definitions share a lot. In neither Java nor
> C++ is an object considered a variable. In C++, but not Java, a
> variable name denotes an object; but that's actually a semantic
> difference between the languages, not a definitional one. Of course,
> variables in ML have a completely different meaning. Variables in
> Prolog, furthermore, have yet another completely different meaning.

I am sympathetic to the general tone of your message. I have said before that there is no point in any discussion about whether a given definition is "right" or not. And in fact with semiformal specifications such as C++ and Java have it is possible to cite authoritative definitions relative to the authority of the spec itself.

However, in this case I see an actual benefit (I almost said "value" ha ha) to making explicit the fact that objects are a kind of first class variable. It makes the significance of various language design choices more apparent.

In fact, I recall a thread on comp.lang.java.programmer about the differences and similarities between closures and objects, and there was a message that I thought exactly nailed the issue.

The world we live in today, I was able to locate the exact message in about 20 seconds:

http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/c1c00c7700ba271f/8fba25efa30e9c48?lnk=st&q=&rnum=2#8fba25efa30e9c48

It's from five years ago. That sort of thing still kind of spooks me.

Amusingly, whereas I once felt that Dale's excellent point argued strongly against closures, I now feel that that point argues strongly against objects and in favor of closures. It may also be timely to note that Neal Gafter is circulating a proposal to add closures to Java.

Well, I think I'm just rambling at this point. Toodeloo!

Marshall Received on Sat Feb 10 2007 - 07:32:10 CET

Original text of this message