Tuesday, September 30, 2008

Whiteboarding: A form of torture?

The whiteboard pattern is a pretty well-known "best practice" in the OSGi community. For this reason, I was somewhat surprised to hear from a co-worker (echoed by a couple folks at EclipseCon) that not everyone considers this pattern a blessing. Unfortunately, I have never seen this argument laid out in writing before, so I thought I would give it a shot in this blog entry--apologies if I do it no justice.

The whiteboard pattern is basically a modification on the standard listener pattern in which the content publisher looks up its consumers in the service registry instead of the consumers hooking themselves into the publisher. For a deeper understanding, there is lots of good info available including this whitepaper. This pattern purportedly works much better (fewer lines of code, less prone to error, etc.) in the dynamic world of OSGi services...so why wouldn't everyone love that?

The answer (and I suspect this is an eye-of-the-beholder thing) is simplicity. Although the code presented in the whitepaper makes it pretty clear that using the basic framework to implement the traditional listener pattern can be quite burdensome, I am not convinced it must be this way. With the improvements in service frameworks like Declarative Services, it is becoming easier and cheaper to develop a system based around service interactions. So if the programming complexity becomes similar, in what way does the whiteboard pattern introduce additional complexity?

I can say from first-hand experience that the loosely-coupled nature of OSGi services can be a dual edged sword...powerful yes, but also difficult to follow. When you step into a large project with lots of service dependencies, it can be hard to untangle the interactions and see how the pieces fit together. This effort is made even more difficult in code which uses the whiteboard pattern. The registry becomes entangled with a bunch of listener objects, which have no clear indication of who should call them or what service they are providing to the system. Additionally, the developer is expected to know that they can hook into a particular producer by implementing some standard interface and publishing it to the registry. This type of hidden interaction model can be very tricky to find and needs to be well documented to be effective...or else it can start to feel a bit too 'magical'.

The beauty of the service registry is that it gives us a single place for safe, dynamic, loosely-coupled bundle interaction. So what we would really like to see in the registry is the "service" a particular bundle is offering to the other bundles in the system. On the one hand we have a pool of content consumers offering only a "listen" service, while on the other we have a content publisher who allows you to register your interest with its content. Now which of these bundles do you think more accurately fits the average developer's notion of "service"? I wonder why we don't see this type of "whiteboard" pattern in distributed SOA systems...

Friday, September 5, 2008

Keyboard Shortcuts - Others

In my previous post I covered my favorite Eclipse shortcuts fairly extensively. Here are some of my favorites in other programs:

Browsers/Apps

Most folks know that Firefox, IE7, Chrome and some other tabbed interfaces provide the following shortcuts for working with tabs:
  • Ctrl + T => New Tab
  • Ctrl + Tab => Next Tab
  • Ctrl + W => Close Tab
You can also hold the Ctrl key when following a link to open it in a new tab in the background. Similarly, you can hold the Shift key instead to have it open in a new window altogether.

Perhaps a bit less known is
  • Alt + D => Goto the Address Bar
While there are similar shortcuts to do the same thing, this one will work across Firefox, Chrome, Internet Explorer, Windows Explorer (the Windows File Manager) and most other apps I've used with a similar layout.

I have begun to use this Alt + D shortcut in combination with the Quick Search feature in Firefox. This is a feature that allows you associate a keyword in the address bar with a particular type of search. Firefox comes preloaded with a number of useful ones, including "wp" for wikipedia (though my Linux version of Firefox 3 seems to be missing these for some reason). To try this out, simply navigate to the address bar and type "wp firefox". This should pull up a page with the results of the wikipedia search. You can even set your own Quick Searches (much like setting a bookmark). For more info on this nice little feature, check out http://lifehacker.com/software/geek-to-live/geek-to-live-fifteen-firefox-quick-searches-129658.php

Finally, there are the page search shortcuts (at least in Firefox).
  • / => Find As You Type Text
  • ' => Find As You Type Link
I still tend to use the Find shortcut Ctrl + F for text searches instead of / because you can more easily toggle through multiple hits. However, the ', search_string, Enter sequence is a very useful one for quickly finding and following a link on the page.

Finally, some new-fangled, web 2.0, RIA, Ajax-enabled, Software-as-a-Service webpages provide their own shortcuts. The only ones I know of and use are the Google shortcuts (especially for Gmail and Reader). In particular, I find the use of j/k and n/p to navigate lists/items quite useful. For a useful reference list, be sure to type '?' while in one of these services.

Operating Systems

Operating systems usually provide some useful shortcuts for managing the desktop and the running applications.
  • Alt + Tab => Switch between applications
If you continue to hold the Alt key (and have multiple apps running), pressing Tab multiple times will cycle you through a list of the running applications. Interestingly, there is a lesser known Alt + Esc shortcut which can be used to switch between applications in-order (queue) as apposed to the last used (stack).

On my work computers I use Windows XP and have gotten familiar with a number of the special windows shortcuts (many involving that silly little "windows" key between Ctrl and Alt on the keyboard). Of these shortcuts, perhaps my favorite is:
  • Winkey + D => Show Desktop (Toggle)
However, for some reason, this shortcut doesn't work on my T60p Thinkpad! For more shortcut-related info on the Windows Key, be sure to check out http://www.codinghorror.com/blog/archives/000378.html

Well that is enough for now. I will have to write new posts or update these ones as I find particularly useful shortcuts which I have missed.

Friday, August 29, 2008

Keyboard Shortcuts - Eclipse

Whether you call them Keyboard Shortcuts, Key Bindings, Hotkeys, or what-have-you the Eclipse IDE contains a great number of useful keyboard shortcuts...from general navigation to coding/editing and running/debugging. In fact, beneath the surface lies an entirely extensible command and binding framework, which I have only briefly investigated.

One simple shortcut for displaying a list of these shortcuts is
  • Ctrl + Shift + L => Show Key Assist
This same feature is available in some Eclipse RCP products as well, including Lotus Notes 8. Unfortunately, I don't find such a list all that useful...especially if I am looking for one binding/command in particular. Fortunately, in the Eclipse IDE at least, hitting Ctrl+Shift+L again will open the key binding preferences page, found in Preferences under General->Keys. This page contains a long list of all the key bindings in your system and is also equipped with a fancy filtering search function which is VERY useful for finding both commands and shortcuts...as well as letting you set your own custom bindings.

Here is a list of some of the most useful Eclipse shortcuts I use:
Disclaimer: my shortcuts are very Java(JDT)/Plug-in(PDE) focused. Similar shortcuts are probably available in CDT or other packages, especially given the ongoing work to provide JDT-like functionality via projects such as the DLTK.

Common
There is something to be said for de facto shortcuts which work across all types of programs. Eclipse does a good job in this respect by implementing some shortcuts that are common to many programs. Such shortcuts include
  • [update: I thought Ctrl+Tab was used to tab through the open editors, but I see now the default for this command is Ctrl+F6. Another command I would find useful is a next tab command for navigating the bottom tabs found in editors such as the Plug-in Manifest Editor.]
  • Ctrl + W => Close Tab
  • Ctrl + N => New (Other...)
Navigation
One of the tasks which led to my constant use of the mouse in Eclipse was the simple navigation between views/perspectives/editors/etc. While each of these tasks has its own set of commands (Alt+Shift+Q was particularly useful for me to open/navigate to different views), I recently discovered the master of all shortcuts
  • Ctrl + 3 => Quick Access
Or as I like to call it, the "find whatever I'm looking for" command. This one command will give you a filtered search for perspectives, views, wizards, command, etc. The thing that makes this command even more useful is that it caches your command choice to provide a customized list of your common commands. While I still use Ctrl+E to activate an editor and Ctrl+N to launch the New->Other... wizard (I find it tricky to filter between those options), this is definitely one of my favorite shortcuts.

Most people I know are familiar with some common navigation shortcuts such as
  • F3 => Open Declaration
  • F2 => Open Tooltip
but they are nonetheless worth mentioning. Similar functionality is available using Ctrl+click.

Eclipse provides some useful views for navigation, including the type hierarchy and outline views, but instead of letting these views clog your precious screen real-estate, you can use their quick command options instead:
  • Ctrl + O => Quick Outline (x2 to toggle show/hide inherited members)
  • Ctrl + T => Type Hierarchy (x2 to toggle between supertype/subtype hierarchies)
In additional to the normal Find/Replace (Ctrl+F) command, Eclipse provides an advanced extensible search feature, which provides customizable scoped searches for particular resources such as Java Search, Plug-in Search, and standard global search.
  • Ctrl + H => Search
Although this feature provides powerful queries for all sorts of resources, I primarily use it for doing global/workspace file searches based on text and file type. It is also worth pointing out that the file search provides a global Replace... button as well if you look for it. For Java-specific searches, I usually find myself using some other useful bindings instead:
  • Ctrl + G => Declarations in Workspace
  • Ctrl + Shift + G => References in Workspace
Somewhat related, the call hierachy view is a very useful way to figure out who calls a method
  • Ctrl + Alt + H => Call Hierarchy
Another command I use religiously, is the open resource command
  • Ctrl + Shift + R => Open Resource
Similarly, the open type and open plug-in artifact commands are very useful when you know which type of resource you are looking for.
  • Ctrl + Shift + T => open type
  • Ctrl + Shift + A => open plug-in artifact*
Editing
Eclipse also provides some useful commands for use while programming. Perhaps the best know example would be the content assist (Ctrl+Space) feature. This binding will also rotate through a list of (customizable) templates/proposals if you press it more than once.

Another prevalent shortcut is the quick fix. This command seems to get better with each version of eclipse (especially for OSGi-related issues). I also use the lesser know quick assist command for assigning statements to fields (Ctrl+2, F) and local variables (Ctrl+2, L).
  • Ctrl + 1 => Quick Fix
  • Ctrl + 2 => Quick Assist (Assign To)
Another useful editing shortcut is the formatting command
  • Ctrl + Shift + F => format
For the longest time I used Ctrl+I to fix indentation issue, in part because I found the format option too extreme. However, after investing a little time in learning the formatting preferences, I now tend to format just about everything.

Eclipse is also chock full of refactoring/source assistance. Although each of these menus is available via shortcut (Alt+Shift+T and Alt+Shift+S), my favorite refactoring shortcuts are:
  • Alt + Shift + R => Rename
  • Alt + Shift + Z => Surround With
  • Alt + Shift + M => Extract Method
Both Surround With (try/catch, loops, etc) and Extract Method are quite useful for optimizing common tasks. However, the Rename shortcut in particular has been a real time-saver for me.

Run/Debug
Finally I would be remiss to list my favorite run/debug shortcuts, though I think these are fairly self-explanatory:
  • F11 => Run
  • Ctrl + F11 => Debug
  • F5 => Step Into
  • F6 => Step Over
  • F7 => Step Return
  • F8 => Resume
  • Ctrl + R => Run to Line
  • Ctrl + click => Step Into Method
  • Ctrl + F2 => Terminate
One thing worth noting here is that the F11 run/debug command used to always launch the previously launched app...but it will now default to whatever project is associated with the selected resource/active editor. To edit this preference, check out the Launch Operation section of Preferences->Run/Debug->Launching.

Conclusion
The combination of key bindings and filtering text boxes is awesomely powerful.
Learning to use Alt, Ctrl, and Shift on both sides of keyboard is vital (maybe its just me, but I previously used my left hand for all these keys...proving problematic for bindings like Alt+Shift+R).
In general, I am not a big fan of Fx (x=1-12) shortcuts as I find them awkward to type (though I do use them and have even listed a few).

Here is a slightly condensed list of the most useful bindings I've seen people miss:
  • Ctrl + Shift + L (x2) => Key Bindings Preferences
  • Ctrl + 3 => Quick Access List
  • Ctrl + O => Quick Outline (x2 to toggle show/hide inherited members)
  • Ctrl + T => Type Hierarchy (x2 to toggle between supertype/subtype hierarchies)
  • Ctrl + H => Search (File Search)
  • Ctrl + G => Declarations in Workspace
  • Ctrl + Shift + G => References in Workspace
  • Ctrl + Alt + H => Call Hierarchy
  • Ctrl + Shift + R => Open Resource
  • Ctrl + Shift + T => Open Type
  • Ctrl + Shift + F => Format
  • Alt + Shift + F1 => Plug-in Spy
  • Alt + Shift + R => Rename
  • F11 => Run
  • Ctrl + F11 => Debug
  • Ctrl + R => Run to Line
There are also a couple of custom bindings I usually set, but I will leave those for another day. There are PLENTY of commands which I left off this list, so let me know if I missed one of your favorites!

*new in Ganymede