[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bindings and assignments (was: Re: continuations)

I use final for locals and parameters all the time but I think that's 

a) I use anonymous classes, and
b) I spent a lot of time in the past w/ Lisp and Scheme.
(the two are not necessarily unrelated)

I suspect most Java programmers don't use these idioms because they
had already written a lot of Java before "final" became applicable
to locals.  When it first came out, the only motivation for the practice
that I saw floating around was that you could use symbolic constants
in switch expressions by declaring a set of final locals.

I still occasionally lapse and leave out "final" markers on parameters
just because I wrote so much code without them in the past.  I just
went back and looked at the example code in our Java text (which is
pretty old now) and I definitely didn't use "final" everywhere.  The 
only places
I did were in the chapter on inner classes which included an example
of a pattern matcher written in CPS.  :-)


Vadim Nasardinov wrote:

> Shriram Krishnamurthi wrote:
>  > Two related, necessarily somewhat vague, questions:
> <sperber-mode>
>  Just to be clear, the answer to the original question is, yes, a
>  syntactic distinction does exist.  The following questions are along
>  the lines of, yeah, but is it this facility used in practice?
> </sperber-mode>
>  > 1. What do the main Java texts/books say about this?  Do they (a)
>  > emphasize its existence, (b) provide useful guidelines on its use
> I dunneaux.  Haven't read a mainstream book in a long time.  I looked
> up "final" in the index of "Effective Java" by Joshua Bloch, and he
> doesn't seem to say anything about the use of "final" for local
> variables, although he does say a great deal about other uses of this
> keyword.  (I may have overlooked a reference though.)
>  > 2. Do practicing programmers use it much?
> Judging by code I looked at, most Java programmers don't think in
> terms of let/set/set!.  They don't use the "final" keyword to declare
> local variables.  Those who do are in the minority.  (The only guy I
> know of who does this more or less consistently has also been known to
> write small utils in Scheme on occasion, so he doesn't count.)
> Personally, I use this idiom rather infrequently.
> This, of course, is anecdotal and not based on any hard numbers.