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


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

Re: Refactoring discovery

From Joshua Cranmer <Pidgeot18@verizon.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Refactoring discovery
Date 2011-03-30 17:31 -0400
Organization A noiseless patient Spider
Message-ID <in07ga$g5q$1@dont-email.me> (permalink)
References <kbgoo6dfrkh58r3ogel9nb6rekrs258it2@4ax.com> <imi0cq$ah4$1@dont-email.me> <imjjus$2cj$1@lust.ihug.co.nz> <e7Mkp.1468$0s5.314@newsfe17.iad>

Show all headers | View raw


On 03/30/2011 04:10 PM, David Lamb wrote:
> We already write "combined operations" in other contexts.
> if (x.hasKey(y)) then x.addPair(y,
> someVeryBigThingIDidn'tWantToSysnthesizeUnlessIHadTo)

Well, another way to implement this is:

public boolean hasKey(Y y) {
   LocPtr ptr = getWhereToInsert(y);
   this.cachedPtr = ptr;
   return ptr.valid();
}

public void addPair(Y y, Object obj) {
   LocPtr ptr;
   if (cachedPtr && cachedPtr.y == y)
     ptr = cachedPtr;
   else
     ptr = getWhereToInsert(y);
   ptr.insert(obj);
}

Which pretty much gets you the "benefit" of combining them into one 
single operation without needing to provide all of the back-level 
predicate code operations (set-if-present, set-if-not-present, etc.)
-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next 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