Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Inserting In a List Date: Mon, 08 Apr 2013 19:13:46 +0200 Lines: 34 Message-ID: References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> <8MWdnbEIVKIMXfzMnZ2dnUVZ8tednZ2d@bt.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net xztuqD4LFLnfB5JtJ2J+awuiaBhrq+PUw+eQ7hfkPnh5DjGwU= Cancel-Lock: sha1:Lhoi8ch8CB4kvhpH34mRfovjFgk= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 In-Reply-To: X-Antivirus: avast! (VPS 130408-1, 08.04.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.java.programmer:23386 On 08.04.2013 09:54, lipska the kat wrote: > On 08/04/13 07:28, Robert Klemme wrote: >> Making those things which are mutable to stand out vs. those which >> aren't helps when there are a lot variables around. >> >> One example: I had to modify a 600+ lines method (yeah, ugly). I >> started with refactoring because otherwise I would have had zero chance >> to fully understand what the code actually did. In the process I >> started with moving variable declarations to the most restricted scope >> and making things final. That helped my a great deal in understanding >> the logic. Then I refactored appropriate parts into separate methods. >> This is the kind of experience that led me to find "final" useful. > > I would be prepared to wager that when you had finished refactoring, > your method local variables were largely *not* final. > > Was this the case ? I really don't remember what the ratio of final vs. non final variables was afterwards. But for example, foreach loop variable were indeed final. Moving variables to smallest possible scopes also nicely helped in finding a bug: there was a variable declared outside the loop and it was obviously intended to be used during one iteration only but there was a code path which allowed the last value to survive and be reused. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/