Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: About java program. Date: Wed, 19 Jun 2013 21:20:35 +0200 Lines: 49 Message-ID: References: <324f929f-772e-4004-81e1-6b454cdae794@googlegroups.com> <19wnriq53qxel.u9rt8wy6z52g.dlg@40tude.net> <1lvu4yv8sxe73$.n4o05ixuag9y.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 KjdNRxqI1C7rA9jdBGy96w45P3kZ+zZ151Bcf0V1t/ck/Xmk8= Cancel-Lock: sha1:fv8Zx+b9po7XxsybzX8+0SeKFDo= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: X-Antivirus: avast! (VPS 130619-0, 19.06.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.java.programmer:24474 On 19.06.2013 02:26, Arved Sandstrom wrote: > I find the style of clearly declaring a result variable at the beginning > of a method often comes about because you have to declare the variable > anyway, because of try-catch and conditional blocks and so forth. So it > may as well get declared early. I try to declare in the smallest necessary scope. And I find myself converting boolean result = false; try { result = whatEver() || somethingElse(); } catch (whatever...) { no return or change of result } return result; to try { return whatEver() || somethingElse(); } catch (whatever...) { no return or change of result return false; } because I find that more readable. Variables are not a value in itself. If they don't serve a purpose they should go away IMHO since they decouple calculation of the value from usage. Of course, if you need the same value multiple times then that warrants every variable. But cases like the one above do not. > I don't think it's a style to either decry or enthusiastically endorse. > It hardly introduces clutter, though. Right. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/