Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Blocks for scope control Date: Sun, 15 Jan 2012 11:21:42 -0800 Organization: albasani.net Lines: 34 Message-ID: References: <9ngdd9Fv6mU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net dF6wn1I94DM3X643KhHoFNCWAn+xQDv8XYOsiO+fRRHNoopsREMJokX03yxe86rPxGNZr0ZXFD7trOYSNyIjTvTsA/ksWqw6nSLk3iaNaMEzgtHyorz2LKzkc4B21Qii NNTP-Posting-Date: Sun, 15 Jan 2012 19:21:44 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="JN6+C9PVrp8Ev3yDPDPp5RsTk/grckRgbLECY7JBvS0/LFVoKCeGqX4v6w9npn+lQ91/1TRUFnRaR8f5rv/eeWkAlhZqvaq7Q8bIfHw4EVNHqoAa//yKSSa7GX+OmoJV"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16 In-Reply-To: Cancel-Lock: sha1:mpjALWZNDLvmrfL5QF9hH7+v2Co= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11360 Stefan Ram wrote: > Robert Klemm writes: >>> { final Button button = new Button(); frame.add( button ); } >> Why do you think it makes sense to replace this >> frame.add( new Button() ); >> with the block above? > > This code (comments removed by me): > > for (ThumbnailAction thumbAction : chunks) { > JButton thumbButton = new JButton(thumbAction); > buttonBar.add(thumbButton, buttonBar.getComponentCount() - 1); > } > > can be found in the renowned Java Tutorial at > > http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html > > . So such temporary names for one-time use are not > against common teachings. Some argue, and there's merit in the position, that the one-time name idiom enhances code readability over the constructor-in-the-method-argument idiom. (I also find merit in the "you ought to know Java well enough to read a friggin' construction in an argument, for God's sake" argument, for anyone claiming remuneration for their Java skills. Lacking such knowledge and charging for your Java skills is fraud if the ignorance is not disclosed up front.) -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg