Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #22062

Re: refactoring problem

Newsgroups comp.lang.java.programmer
Date 2013-02-03 14:36 -0800
References <7fssg8dakvofmv6pk3sfvp5jmaku55vgmm@4ax.com> <kewPs.130004$Sl.6860@newsfe27.iad>
Message-ID <f85debeb-77d9-4a10-9c66-bf1ac63cd8f8@googlegroups.com> (permalink)
Subject Re: refactoring problem
From Lew <lewbloch@gmail.com>

Show all headers | View raw


Arved Sandstrom wrote:
> 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.

It might be tedious, but programming is a cost-benefit exercise.

If you have six variables that are so tightly bound semantically that 
you consistently want to treat them as a unit, then you have a type.

The right thing to do with a type in your programming model is to 
implement it as a type.

> I think that's a decent way of handling this problem in Java.

Or any OO-ish language.

>> 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 

And a classic inquiry.

> a single object or struct to hold multiple return values, you have other 
> languages that support returning lists or tuples. You do have languages 

A tuple is roughly equivalent to a struct or class with the same number 
of elements.

If tuples or types do not require explicit declaration, then we have 
something like dynamic types.

If we had a strongly-typed tuple language that was as rigid about 
declaration of tuples as Java is about types, we'd have comparable 
tedium.

> (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.

Maps are like the poor-man's dynamic type. They're lovely little data 
structures.

> What else would you have in mind?

Here's the thing. No language has it all, otherwise there'd be no programs 
left to write.

So somewhere between that _reductio ad absurdum_ and the abacus each 
programming language has to choose a subset of tools, an axiomatic set
if you will, that becomes core to the language. The rest you write yourself.

You can do what you want in this case, and in this case it will be better 
program design anyway, by writing a type to express the relationship among 
those six things you represent as variables.

Too bad for you that you find it tedious.

Sometimes a great chef has to chop onions, though it make them cry.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

refactoring problem Roedy Green <see_website@mindprod.com.invalid> - 2013-02-03 06:30 -0800
  Re: refactoring problem Martin Gregorie <martin@address-in-sig.invalid> - 2013-02-03 16:23 +0000
  Re: refactoring problem Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-02-03 12:27 -0400
    Re: refactoring problem Roedy Green <see_website@mindprod.com.invalid> - 2013-02-03 12:35 -0800
      Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-03 15:37 -0500
    Re: refactoring problem Leif Roar Moldskred <leifm@dimnakorr.com> - 2013-02-03 15:21 -0600
      Re: refactoring problem Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-02-03 17:38 -0400
      Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-03 16:46 -0500
    Re: refactoring problem Lew <lewbloch@gmail.com> - 2013-02-03 14:36 -0800
  Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-03 11:34 -0500
  Re: refactoring problem Joshua Cranmer <Pidgeot18@verizon.invalid> - 2013-02-03 11:54 -0600
    Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-03 13:13 -0500
      Re: refactoring problem Knute Johnson <nospam@knutejohnson.com> - 2013-02-03 10:20 -0800
        Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-03 13:32 -0500
          Re: refactoring problem Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2013-02-03 10:50 -0800
            Re: refactoring problem Robert Klemme <shortcutter@googlemail.com> - 2013-02-03 21:38 +0100
            Re: refactoring problem "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-02-04 08:11 +0000
              Re: refactoring problem Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2013-02-04 03:56 -0800
      Re: refactoring problem Silvio <silvio@internet.com> - 2013-02-04 13:21 +0100
        Re: refactoring problem Lew <lewbloch@gmail.com> - 2013-02-04 12:35 -0800
          Re: refactoring problem Silvio <silvio@internet.com> - 2013-02-04 22:15 +0100
            Re: refactoring problem Lew <lewbloch@gmail.com> - 2013-02-04 13:49 -0800
              Re: refactoring problem Silvio <silvio@internet.com> - 2013-02-04 23:51 +0100
            Re: refactoring problem Lew <lewbloch@gmail.com> - 2013-02-04 13:53 -0800
              Re: refactoring problem Silvio <silvio@internet.com> - 2013-02-04 23:48 +0100
                Re: refactoring problem Lew <lewbloch@gmail.com> - 2013-02-04 17:08 -0800
                Re: refactoring problem Silvio <silvio@internet.com> - 2013-02-05 10:07 +0100
                Re: refactoring problem Lew <lewbloch@gmail.com> - 2013-02-05 13:13 -0800
                Re: refactoring problem Jim Gibson <jimsgibson@gmail.com> - 2013-02-05 13:20 -0800
                Re: refactoring problem Lew <lewbloch@gmail.com> - 2013-02-05 13:31 -0800
                Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 21:42 -0500
            Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-04 18:33 -0500
          Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-04 18:32 -0500
            Re: refactoring problem Martin Gregorie <martin@address-in-sig.invalid> - 2013-02-05 01:50 +0000
          Re: refactoring problem Joshua Cranmer <Pidgeot18@verizon.invalid> - 2013-02-05 10:04 -0600
            Re: refactoring problem Gene Wirchenko <genew@telus.net> - 2013-02-05 10:38 -0800
              Re: refactoring problem Joshua Cranmer <Pidgeot18@verizon.invalid> - 2013-02-05 13:53 -0600
            Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 21:43 -0500
              Re: refactoring problem markspace <markspace@nospam.nospam> - 2013-02-05 19:15 -0800
                Re: refactoring problem Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 23:58 -0500
  Re: refactoring problem Joerg Meier <joergmmeier@arcor.de> - 2013-02-05 11:09 +0100

csiph-web