jducoeur: (Default)
jducoeur ([personal profile] jducoeur) wrote2008-10-31 03:11 pm
Entry tags:

Okay, that may qualify as too clever

There I was, coding along, and realized that this clause -- to unsubscribe from someone's presence when they change their IM handle -- also needs to be over there, for the case where they simply delete their IM handle. I copy the code from place A to B, think about it a minute, slap myself mentally, and decide that I should be extracting a method instead.

So I go to code A, invoke Eclipse's "Extract Method", and *poof*, I have a new method. I go over to B, to replace my copied code with a method call...

... and it's already been done for me.

On the one hand, that's exactly what I wanted. OTOH, it's kind of spooky. It hadn't even occurred to me that Extract Method would go looking for duplicate code and refactor that as well. It's probably usually correct, but managed to hit a button I wasn't even aware of -- the "Waitaminnit, that's *my* code! Don't screw with it!" response was quite visceral...

[identity profile] metageek.livejournal.com 2008-11-01 01:40 pm (UTC)(link)
Ow. I would hate that: the notion of having an IDE mung my code is nothing compared to the notion of having that munging depend on history, rather than the state of the code.

But that's me. I'd rather attack my code with a penknife than run it through a nanoassembler. If I need more complicated changes, I'll script them myself. (It helps to stick to high-level languages where small text changes can have large effects. The strategy is less useful in languages like Java, which lack metaprogramming and first-order functions.)