[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: accumulator generator (Java)
At 09:36 PM 5/23/2002 -0400, you wrote:
>The point about this is that I have attempted, exceedingly awkwardly, to
>eliminate the need for an instance variable, making use of the closure-like
>behaviour of inner classes in Java. Unfortunately, this is illegal Java.
>Interestingly, though, it works under IBM's Jikes compiler (v1.14), so I'm
>pointing it out in the general spirit of perversity that flourishes on lists
>It's illegal because the variable n must be declared as "final" (immutable),
>but it is being mutated within the method inc(). Sun's compiler catches
>this with "cannot assign a value to final variable n", but Jikes does not.
>The code generated by Jikes seems to work correctly, even under the Sun JVM
All I have to say is "hah!". This is funny. Bonus points to you for
actually figuring this out. Did you discover this in the process of
performing this experiment or in something else (I'd imagine something
else, but I'm curious to hear it from you).
>So in legal Java, I don't think it's possible (?) to write this code to rely
>on closure-like behavior, without using an instance variable; and besides, a
>pure object approach tends to be far more natural in Java.
Which makes me wonder about the ever-present push to get generics in Java.
I tend to think generics are a Good Thing, but if the object approach is
the most innate, how would generics have to be implemented to be seen as a
universal boon that didn't upset Java programmers?
This, of course, gets back to the idea that each language has it's own feel
and that idioms and practices from other languages don't necessarily
translate, a la the Python v. Lisp thread.
>This sort of thing always reminds me of the quotation (or paper title) which
>goes "Objects are a poor man's closure". As soon as I got to the point of
>believing that, I read in Queinnec's "Lisp in Small Pieces" a statement very
>close to "closures are a poor man's object". It was at that point that I
>reached satori... ;)
SICP has a similar point, in that you construct an object system out of
closures. I look at closures being more generic than objects, whereas
objects have very specific properties. I suppose it depends on what I'm
doing and what I'm doing it with at the time that would determine whether
or not I found my objects as lame closures or closures as lame objects. I
tend to feel that, between the two, I would rather have real closures, and
if necessary, I'll build my own object system thank-you-very-much over
having to be constrained in an "objects only" universe. But then, I still
liking hacking in Smalltalk for fun sometimes.
On a completely different note, has anyone else seen the work Chris Double
has been doing with GOO (nee Proto) and .NET?
Dan Moniz <firstname.lastname@example.org> [http://www.pobox.com/~dnm/]