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


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

Re: Refactoring discovery

From David Lamb <dalamb@cs.queensu.ca>
Newsgroups comp.lang.java.programmer
Subject Re: Refactoring discovery
References <kbgoo6dfrkh58r3ogel9nb6rekrs258it2@4ax.com> <imi0cq$ah4$1@dont-email.me> <imjjus$2cj$1@lust.ihug.co.nz>
Message-ID <e7Mkp.1468$0s5.314@newsfe17.iad> (permalink)
Date 2011-03-30 16:10 -0400

Show all headers | View raw


On 25/03/2011 10:44 PM, Lawrence D'Oliveiro wrote:
> In message<imi0cq$ah4$1@dont-email.me>, Eric Sosman wrote:
>> You'd want something that could attach names to the pieces of the
>> assignment target, and match them up with names in the expression value.
>> Something like
>> int r, g, b;
>> (r.red, g.green, b.blue) = backgroundColor; // drop alpha
>
> In Python you can write
>      r, g, b = (getattr(backgroundColor, f) for f in ("red", "green", "blue"))
> But really, is it such a big deal? In conventional languages like C we
> happily write
>
>      q = y / z;
>      r = y % z;
>
> and leave it to the compiler to do the dataflow analysis for us.

Quotient and remainder of division are a very special case. The hardware 
sometimes has a single operation that produces both, and knowledge that 
/ and % are closely related operations is built into the language.  With
    first = longComplexOperation(lots of arguments)
    second = anotherLongComplexOperation(same set of arguments)
it's going to take a very sophisticated compiler to synthesize
    (first, second) = combinedLongOperation(same set of arguments)
and it's going to have to solve the Halting Problem, too.

We already write "combined operations" in other contexts.
if (x.hasKey(y)) then x.addPair(y, 
someVeryBigThingIDidn'tWantToSysnthesizeUnlessIHadTo)

sometimes gets implemented as
   whereToInsert = x.findLocation(y);
   if (whereToInsert.keyIsntAlreadyThere())
     whereToInsert.addPair(y,...)
Or possibly whereToInsert is internal state in x and x.addPair(y,z) is 
x.addAtSpotDeterminedByLastHasKey(z).

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar


Thread

Re: Refactoring discovery David Lamb <dalamb@cs.queensu.ca> - 2011-03-30 16:10 -0400
  Re: Refactoring discovery David Lamb <dalamb@cs.queensu.ca> - 2011-03-30 16:25 -0400
  Re: Refactoring discovery Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-03-30 17:31 -0400
    Re: Refactoring discovery markspace <-@.> - 2011-03-30 15:52 -0700
    Re: Refactoring discovery Lew <noone@lewscanon.com> - 2011-03-30 23:58 -0400

csiph-web