Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe27.iad.POSTED!not-for-mail From: Arved Sandstrom User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: refactoring problem References: <7fssg8dakvofmv6pk3sfvp5jmaku55vgmm@4ax.com> In-Reply-To: <7fssg8dakvofmv6pk3sfvp5jmaku55vgmm@4ax.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 38 Message-ID: X-Complaints-To: abuse@newsgroups-download.com NNTP-Posting-Date: Sun, 03 Feb 2013 16:28:00 UTC Organization: Public Usenet Newsgroup Access Date: Sun, 03 Feb 2013 12:27:59 -0400 X-Received-Bytes: 2274 Xref: csiph.com comp.lang.java.programmer:22047 On 02/03/2013 10:30 AM, Roedy Green wrote: > Consider the following refactoring problem. > > There is a hunk of almost identical code that appears multiple times. > It sets up 6 local variables. > > I would like to encapsulate it. > > The obvious way to handle it is to make all the variables instance. > But they are ARE local. (I might be using threads) > Further their declarations would be scattered to the winds. > > I could create a separate class just to hold the values. This is > tedious, but it may be the only way. I think that's a decent way of handling this problem in Java. > I think, why can methods have multiple inputs, but only one output? I > have been thinking that for about 50 years, and it ,seems unlikely to > change soon. How exactly would you expect multiple outputs to work? If you've been thinking about this for about 50 years, then we're talking pretty much any programming language out there. Apart from the technique of defining a single object or struct to hold multiple return values, you have other languages that support returning lists or tuples. You do have languages (Scheme, for example) that return "true" multiple values from procedures, I don't see that their techniques have large advantages over tuples myself. And then of course there are things like generators, or for example, lazy evaluation of a map function over a list. What else would you have in mind? [ SNIP ] AHS