He who lives by the quick fix…

I write software interatively and almost always top-down. As such , I tend to rely heavily on the refactoring tools provided in the Eclipse JDT. But I’ve really started to lean on the Quick Fix feature.

When you write code from the top-down, you always start with a lot of errors. Ideally, I start by building JUnit unit tests and then spend the rest of my time making them work. I’ve spoken with a lot of folks who try very hard to avoid ever having errors show up when they hit ‘save’; I don’t understand these folks because the errors save you time.

When a red line appears under some part of your Java code, that means there’s an error. If you put the cursor in the code with an error and hit CTRL-1 (on Windows and Linux) to get a context menu with all the possible ways to fix the error. I most commonly use the Quick Fixes to create a new class or new method (since I build things top-down, I tend to use these things before I actually build them). The Quick Fix mechanism generally does a pretty good job of determining things like an appropriate super class or interface for a class, return values and parameters for methods, and such. It builds a pretty good skeleton of the thing you need to make.

There are also Quick Fixes that import missing classes, add exception handling code, or help you fix typing mistakes in class names. It’s all quite wonderful for a lazy person such as myself.

A few days ago, I was building an anonymous class and discovered a new quick fix. I built the class based on an interface that I hadn’t yet added and added a method that doesn’t exist (as is my normal approach). I used the quick fix to build the interface. Building the interface made both errors go away. On a whim, I put the cursor over the method I had added to my anonymous class (which hadn’t yet been added to my new interface) and hit the CTRL-1 not really expecting much to happen. However, the menu did contain something useful: a quick fix to create my method in the super type (the interface).

So you can even quick fix things that don’t even appear to be broken. Very cool.

This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to He who lives by the quick fix…

  1. RefuX says:

    Interestingly enough one of the ‘Visual Studio Rots the Mind’ arguments was that you have to write everything bottom up.My Eclipse counter-example was the same as yours, ‘just use quick-fix!’.So I guess Eclipse doesn’t rot the mind🙂

  2. Wayne says:

    John Arthorne just let me know that when I added the method to the interface, I was actually using “Quick Assist” and not “Quick Fix”. Oops.

  3. Villane says:

    This is how I work as well sometimes, or at least I’ve been trying to start working that way lately. Mostly I have worked by alternating between top-down and bottom-up, usually leaving auto-generated methods empty at first when writing the “top” classes. They will of course contain the also automatically generated TODO notes, so I can quickly glance at where there is unimplemented code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s