Wednesday, March 25, 2009

Thoughts from EclipseCon: LogService is an Anti-Example

I'm in Santa Clara, CA, this week attending EclipseCon. It's always great to reconnect with old friends and to catch up on what's new in the world of Eclipse.

OSGi has been gaining lots of traction in recent years, which is a great trend to see. (Finally!) Many people who have been steeped in Eclipse for years are just now getting around to investigating OSGi.

Given that there are still many minds yet to be converted to thinking more in terms of OSGi services and less in terms of Eclipse extension points, I have a modest pedagogical proposal:

Never use OSGi's LogService as an example ever again!

Over and over I hear the OSGi cognoscenti rattle off an example to OSGi beginners with LogServices as the example service. I can't tell you how many times I have heard examples that begin with "Suppose you want to use the LogService."

This is bad for at least three reasons:
  1. Logging is arguably something you might not actually want to do as a service. For example, your application might need to log about the fact that it is unable to acquire a service in the first place. Or it may need to log in a static initializer. At this point, it's too early to have acquired the LogService. We don't want our examples to lead OSGi beginners into thinking that logging is something best achieved via services.
  2. The behavior of OSGi's LogService is almost guaranteed not to match an OSGi beginner's expectations of how a logging service should work. I'm not saying OSGi's log service is wrong necessarily - I'll leave that argument for others to make. I'm saying that we should prefer examples whose semantics are shared between expert and novice. Without that, it's likely the concept we're tying to convey by way of the example is corrupted by the semantic impedance mismatch. An audience member in a session this morning asked a question using the LogService as the example (that was the dominant example in the talk so far, so why not?) and the answer he received from the OSGi expert was specific to the quirks of OSGi's LogService and missed the point of the question entirely. Sigh. Sadly, the questioner left the room even more confused than when he'd entered. Score one for the evil forces conspiring against OSGi adoption in the Eclipse community.
  3. Using only examples that are part of the OSGi framework mistakenly implies that services are something to be used only within the framework, not in your application. Certainly, no OSGi expert would ever argue this to be the case, but they seem unaware that this is unintentionally implied in their example. This misses what I think is the best part of OSGi - architecting your application as services.
I know that no OSGi expert intends to tell beginners that logging is best achieved by services, that the LogService is easy to understand, or that services are something only the framework should provide. So I'm suggesting that we use some concocted application service rather than any service provided by the OSGi framework. Almost anything would be better - StockQuoteService, TemperatureService, etc.

The only thing that could possibly be a worse example than the LogService would be the FooService. (Evil Forces of Foo, you know who you are.)


1 comment:

Simon Archer said...

Very well put, Paul. You should consider writing a book on OSGi. Oh yeah, you already are...