Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Usefulness of "final" (Was: Re: Inserting In a List) Date: Wed, 03 Apr 2013 08:09:30 +0200 Lines: 57 Message-ID: References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net aNe6NMoNYkPbHMQ5wkAW6A2wcnDdpAO0Lz5YaG0B/afJZSXTg= Cancel-Lock: sha1:C8Ks78pfdP3J0gsVVYm0cqBPuTM= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 In-Reply-To: X-Antivirus: avast! (VPS 130402-1, 02.04.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.java.programmer:23209 On 02.04.2013 22:41, Eric Sosman wrote: > On 4/2/2013 3:06 PM, Robert Klemme wrote: >> [...] >> I believe in using "final" pretty often as it will immediately indicate >> which local variables are constant for a method call and which are >> modified all the time. [...] > > De gustibus non disputandum est, but I think "final" should > be reserved for things that *mustn't* change, and shouldn't just > be pasted on to anything that happens to remain constant in the > code's current incarnation. When considering a change to some > code I might see > > Thing thing = getThing(); > // ... code that doesn't happen to change `thing' I am so used to using "final" that this immediately makes me wonder why it's not final - did the author intend to not change it, forget to change it or forgot the "final"? :-) > or I might see > > final Thing thing = getThing(); > // ... code that (obviously) doesn't change `thing' > > In the first case I might think about inserting, say, > > if (thing == null) > thing = fallbackThing(); > > ... while in the second case I wouldn't even consider it: I > would suppose that the code relied on `thing' being exactly > what getThing() had returned, perhaps in some way and for some > reason not clear to me. > > But, as I said above, de gustibus. Maybe we're not that far apart: I make things "final" that are not supposed to change. If at a later time I decide they need to change I remove the "final" but it reminds me that other code relies on this value not changing - so I can check whether the change breaks the code in some way. >> Generally I find "finally" quite useful - apparently significantly more >> useful than you do. :-) > > "finally" is a Godsend -- but did you mean "final"? Yes, of course. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/