Thoughts from the office by Ed Ball
Friday, July 30, 2004

I enjoyed reading Refactoring, by Martin Fowler et al. The book seems to treat refactoring both as a technique and as a philosophy.

As a technique, refactoring is simply “change made to the internal structure of software to make it easier to understand and cheaper to modify without changing the observable behavior of the software.” Most of the book is a reference of refactorings: motivation, mechanics, and examples for things like “Extract Method” and “Replace Conditional with Polymorphism”. I love to write good code, so I actually liked reading the reference material – each refactoring represents a code change that has the potential to make it better.

As a philosophy, the book tries to help the reader know when refactoring should take place, and which refactorings should be used. One practical motivation for refactoring is to improve the design and understandability of code before you add a feature or fix a bug. To determine which refactorings are needed, you’ll notice “bad smells” in the code – one chapter is devoted to some of the more common smells, including duplicated code, long methods, switch statements, etc. One quickly begins to see the author’s idea of what good code looks like; the reader must decide if he agrees.

The trouble with refactoring is the “without changing the observable behavior” part. It’s hard to guarantee that your changes haven’t changed anything. In fact, from page 8: “Before you start refactoring, check that you have a solid suite of tests. These tests must be self-checking.” The process of writing these tests is not described in detail – and rightly so – but the need for a test suite is important to keep in mind. Writing good tests is certainly harder than the process of refactoring itself.

I’m not yet sold on the philosophy behind refactoring, but I want to give it a try. Good refactoring tools are becoming more common – the prospect of avoiding the busy work of refactoring is very attractive, and would be a strong influence to try it out, though there’s still that pesky test suite to create...

Writing this review, I realize that I should read the opening chapters again. In case it isn’t clear, I highly recommend this book.

7/30/2004 4:36:03 PM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Books#

Okay, twice now I've tried to love Microsoft's latest mouse, the Wireless IntelliMouse Explorer. My old tried-and-true Microsoft mouse is no longer working properly, so I need a new mouse. Unfortunately, I simply can't bring myself to use the Microsoft mouse, and find myself preferring the chintzy Logitech mouse that I'm using as a stopgap. Why, you ask? Well:

  • The scroll wheel moves smoothly instead of at intervals. This takes some getting used to, but the worst part is that, if you even brush the wheel with your finger, you'll find that you've scrolled your window a little bit.
  • The scroll wheel is nearly impossible to click. I like using the scroll wheel as a third mouse button, but this mouse makes that almost impossible. Even if I did have the finger strength to get the wheel clicked, the previous problem strikes – it is truly impossible to click the scroll wheel without doing a bit of scrolling at the same time! Not good for middle-clicking links on a Web page, that's for sure.
  • The horizontal scrolling aspect of the scroll wheel is pure hype, at least for now. It's hard to do, it scrolls unbearably slowly, when it works, and configuration doesn't seem to help a bit. And, again, any operation near the scroll wheel is going to cause some vertical scrolling whether you like it or not.
  • The orientation is terrible, at least the way I hold a mouse. When I move this cheap Logitech mouse from side-to-side, the mouse cursor stays on a pretty even horizontal. When I do the same with the Microsoft mouse, I can't keep the mouse cursor on a horizontal line to save my life. I suppose after a few weeks I could teach myself to contort my wrist such that it would work, but considering I don't have any trouble with any other mouse I've found, I don't think the problem is me.
  • The mouse buttons on the side are very difficult to press with my thumb; I have to contort my hand unnaturally to hit either of them.
  • Also, the mouse buttons on the side are too small. How I miss my original IntelliMouse Optical, with its nice, big side buttons...
  • Last, but certainly not least, the new mouse only works with IntelliMouse 5.0 driver software, which is significantly inferior to the previous version, IntelliMouse 4.12. Specifically:
    • You can no longer change the orientation. This would help solve the orientation problem, but it can't be done!
    • There are fewer options for button assignment. Specifically, I like to assign the little side button to the Ctrl key; I guess Microsoft decided I didn't need that feature any more.

Don't even get me started on the new Microsoft keyboards. I'm just thankful that they still sell the Microsoft Natural Keyboard Elite.

7/30/2004 12:09:32 PM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Hardware#
Thursday, July 22, 2004

I may love ClearType a little bit less, but it looks like Longhorn will bring me a ClearType to love a little bit more.

7/22/2004 9:03:38 AM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Windows#
Monday, July 19, 2004

I really enjoyed this short article from MSDN Magazine on What Makes Good Code Good (by Paul DiLascia). It matches quite nicely with my own views on the subject.

  • Simplicity
  • Readability
  • Modularity
  • Layering
  • Design
  • Efficiency
  • Elegance
  • Clarity

Now get out there and write some good code!

7/19/2004 3:45:17 PM (Pacific Daylight Time, UTC-07:00) | Comments [1] | Code#

If you’re looking for a simple, cool, free photo manager, go download Picasa! I’ve been using Windows Explorer to manage my photos, so it’s a great improvement for me. Why? Well:

  • It has a great interface for moving photos from a Memory Stick into the My Pictures folder.
  • It automatically finds the pictures on my hard drive and displays thumbnails for all of them in a smooth-scrolling view.
  • You can use really small thumbnails to see hundreds of images at a time, or really big thumbnails to see good detail when looking for a particular picture.
  • It’s easy (and fast!) to rotate photos.
  • It’s easy to remove red-eye from a photo, and it does a very good job.
  • It has a great cropping tool. In fact, it has a feature I’ve been looking for – it can keep the cropping rectangle at a 3 x 5 ratio to ensure my prints don’t get clipped!
  • It has nice slideshow support.
  • It supports videos as well as photos.
  • It has good keyboard shortcuts for most operations.
  • It does everything very quickly, even on my slow machine at home.

It has a number of other cool features that I won’t use as often, including an interactive timeline view. I’m sure it doesn’t hold a candle to more powerful photo managers, but considering the price (free!), I’m really enjoying Picasa.

(Thanks to Scott Watermasysk for the link!)

7/19/2004 2:47:31 PM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Tools#
Friday, July 16, 2004

One of my favorite features in Visual Studio is IntelliSense auto-completion. That is, if I type “XmlEl” and hit Ctrl+Space, it will fill in the rest for me – “ement”. If I haven't typed enough characters – “XmlE” could be completed with “lement”, “ntity”, etc. – it gives me a little list of identifiers to choose from, and selects the most likely candidate as the default.

Microsoft Word needs this feature. Just a few moments ago, I typed “Indispe” ... and wasn't sure how to spell the rest. I can guess, and then look for the red wavy underline, of course, but wouldn't it be better if I could hit Ctrl+Space, and voilà! It correctly completes the word with “nsable”. Now that would be cool.

7/16/2004 3:11:54 PM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Tools#
Friday, July 09, 2004

I’m definitely not happy with my definition of “100% shorter” from last time. After all, if “100% longer” means “twice as long”, shouldn’t “100% shorter” mean “twice as short,” which is “half as long”?

To figure this out, let’s use “inverse-inches.” So if our rope is 60 inches long, it is 1/60 inverse-inches short. “100% shorter” is thus 1/60 + 1/60 = 1/30 inverse-inches short, or 30 inches long:

  • 50% shorter – 1/60 + 1/120 = 3/120 inverse-inches – 40 inches
  • 25% shorter – 1/60 + 1/240 = 5/240 inverse-inches – 48 inches
  • 75% shorter – 1/60 + 3/240 = 7/240 inverse-inches – 34.3 inches
  • 200% shorter – 1/60 + 2/60 = 3/60 inverse-inches – 20 inches
  • 300% shorter – 1/60 + 3/60 = 4/60 inverse-inches – 15 inches

Now “200% shorter” is the same as “three times as short” (as described last time), which works the same way as longer/long, so I think we’ve got it. Still, it’s not exactly obvious.

In any case, length is obviously not the only measurement that this applies to; some of these seem more sensible than others:

  • half as young is twice as old; twice as young is half as old
  • half as many is twice as few; twice as few is half as many
  • half as wide is twice as narrow; twice as narrow is half as wide
  • half as big is twice as small; twice as small is half as big

(Of course, “big” has its own problems – what’s “twice as big” as a 13-inch television? Shall we double the lengths of the sides, the length of the 13-inch diagonal, the area of the screen, or the volume of the box? We’d need to be more precise.)

This stuff actually makes more sense when we use ratio measurements, as with our original measurement of speed. We measure how fast something is by measuring how many tasks are accomplished in an amount of time, e.g. miles per hour – bigger numbers are faster. To measure how slow something is, we measure the inverse, which is how much time it takes to do a number of tasks, e.g. seconds per lap – bigger numbers are slower.

So, if my task took 20% less time, then a previously 100-second task would now take 80 seconds. To measure how fast the task is, we invert the measurement – I improved the speed from 1/100 tasks per second to 1/80 tasks per second. In decimal, that’s 0.01 tasks per second to 0.0125 tasks per second. That’s an improvement of 0.0025 tasks per second, which is 25% of 0.01, so we’d say that the task runs 25% faster.

Ouch. My brain hurts. Since I’d have to justify why shaving 20 seconds off of 100 is “25% faster”, I should probably stick with “20% less time.”

In summary then, we should probably avoid using phrases that would require us to invert our preferred form of measurement. Even “150% longer” can be confusing (it means 2.5 times the length), so you might avoid phrases like that as well. Stick with language that is clear and unambiguous.

7/9/2004 11:11:51 AM (Pacific Daylight Time, UTC-07:00) | Comments [1] | Misc#
Thursday, July 08, 2004

I had just optimized some code, and was about to say that it was “20% faster” when I realized I wasn’t really sure of what that meant. I said “takes 20% less time” instead, but now I have to know – what is “20% faster”?

(This may seem silly, but there’s a practical side as well. You find these kinds of measurements all over the place, particularly in product marketing. Just Google some of these phrases and see for yourself.)

Let’s start with something that seems obvious: length. If our old rope is 60 inches long, this is how long the new rope would be, depending on how we describe it:

  • as long – 60 inches
  • twice as long – 120 inches
  • half as long – 30 inches
  • three times as long – 180 inches
  • one-third as long – 20 inches

Makes sense, right? What if we use the word “longer” instead of “as long”? That is, how long would the string be if it was “200% longer”? Twice as long, i.e., 120 inches? That seems reasonable, until you consider what “50% longer” would mean:

  • 50% longer – 1.5 times as long – 90 inches
  • 100% longer – twice as long – 120 inches
  • 200% longer – three times as long – 180 inches

Let’s make things a little more complicated. What about the word “short”? How long would the string be if it was “half as short”? That’s a tough one. Many people would use that phrase if they thought that the old rope was “short” already, and they would mean that it was “half as long,” i.e., 30 inches. But what if we said it was “twice as short”? That’s got to be “half as long,” too.

The difficulty here is that we don’t have a number that gets bigger as the rope gets shorter. The only logical thing to do is to make “short” the inverse of “long”:

  • as short – as long – 60 inches
  • twice as short – half as long – 30 inches
  • half as short – twice as long – 120 inches
  • three times as short – one-third as long – 20 inches
  • one-third as short – three times as long – 180 inches

Those figures just seem weird, so it would probably be best to avoid that usage. Of course, we wouldn’t be done unless we considered “shorter.” How long would the new string be if it was “50% shorter”? We’d better just subtract that percentage from the original length:

  • 50% shorter – 30 inches
  • 25% shorter – 45 inches
  • 75% shorter – 15 inches

By that logic, “100% shorter” wouldn’t make much sense, since it would be 0 inches. “200% shorter” makes even less sense. Again, you probably want to avoid using “short” or “shorter” when describing relative measurements.

Well, that’s all for now. Tune in next time for the next exciting installment of “Relative Measurements in English,” where we’ll discuss other forms of measurement, and finally decide what “20% faster” really means!

7/8/2004 4:53:46 PM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Misc#
Wednesday, July 07, 2004

“Ever notice when you click the +/- icon next to a folder (or double click on a Solution/Project file), it collapses that particular node in the Solution Explorer... but not any of the sub-nodes? If you have a really large project with a deep hierarchy, wouldn't it be nice to be able to recursively close all of the items beneath a current node so when you expand it again it doesn't re-expand everything below it? Now you can.”

Excellent. (The other features of Solvent are cool, too.)

7/7/2004 2:08:27 PM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Tools#
Friday, July 02, 2004

Test-Driven Development in Microsoft .NET, by James W. Newkirk and Alexei A. Vorontsov, seems primarily intended for programmers that are convinced that TDD is a “good thing” and are writing “enterprise” applications with ASP.NET and ADO.NET in which even one minor defect is one too many. Since only one of those things apply to me (I am a programmer), it should come as no surprise that I did not get much out of this book, and ended up skimming most of it. If you fit the profile better than I do, you will probably like this book a lot more than I did.

I did enjoy the first three chapters, as well as Appendix A, as they teach the basics of TDD by example. TDD seems most logical when developing small, independent components without user interface. Even that looks like an awful lot of work, and it seems to me that the work could increase exponentially with larger, codependent, and/or user interface driven components. Perhaps experience can mitigate some of that, but I don’t think I’m ready to commit the extra time and energy.

7/2/2004 3:13:09 PM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Books#
Search
Archive
Links
Categories
Administration
Blogroll