the corner office

a blog, by Colin Pretorius

Eclipse: a n00b assay

What's the big deal about Eclipse? Plugins and GUI.

Plugins first. What's the big deal about plugins? I don't fully have my head around it, but it's about modularity. When I first started doing Java development, I was a complete stranger to the concept of introspection. The idea that you could write code that not only did stuff, but loaded and changed and knew how to understand the code itself. Cool. The idea that you could write a bit of XML and a program could make sense of that XML and load up and execute separate chunks of code, code that wasn't compiled into the application up-front, code that might only be written months or years later. Cooool. That's how J2EE applications work, and it's not arcane knowledge, but it's still pretty damned powerful.

Each Eclipse plugin is just a piece of code that gets pointed to by a bit of XML, and there are lots of rules which say how a plugin should play with other plugins. The interface between a plugin and its parent code is called an extension point. The parent knows how to talk to an interface, and if the plugin implements the interface, then the parent can load the plugin code, and call methods on that interface. The head-bending bit is that not only can you build an app horizontally by having lots of plugins working side by side, but you can modularise vertically, too. A plugin, or module, or bundle in OSGI terminology, can define its own extension points, and other plugins can then hook into those extension points, and they can in turn publish extension points, which other plugins talk to, and so on...

So basically, Eclipse takes the concept of modularity and redlines it. It's about writing small bits of code, wrapping them up as plugins, and then stringing them all together using (mostly) XML configuration files. The Eclipse platform is, at its core, a simple kernel-like runtime which reads these config files and is smart enough to load up the bits of code, as and when (and if) they're needed.

The second unique thing about Eclipse is its GUI. Java's standard GUI toolkits, the primitive AWT and the newer Swing, are meant to be truly cross-platform toolkits. The intended upside was that the Java GUIs would always look the same, regardless of platform, and the unexpected downside was that Java GUIs tended to look a little, well... crap. The toolkit might be nice in its own right, but never quite fits in, because it doesn't feel truly "native". Eclipse's answer to AWT is SWT. Unlike AWT, which tries to be truly cross-platform, SWT tries to look exactly like the OS it's running on. It provides a standard API, much like AWT, but the API is just a thin layer over the underlying platform's GUI toolkit. JFace is a higher-level extension to SWT, much like Swing is a higher-level extension to AWT.

Starting to learn how to do Eclipse development means getting comfortable with two new things. First, resisting the temptation to hard-wire your entire application together; getting to grips with the Way of the Plugin instead, and secondly, mastering a new GUI toolkit.

{2007.04.11 23:50}

« Knuckle down, Bert

» What doesn't pay rent must go