Tuesday, May 6, 2008

Bubble Wrap, Hani Suleiman and Logging Abstraction

Let's imagine that you are in an antique shop and a beautiful vase or a statue caught your eye and you thought of buying it, either for yourself or as a gift for a friend. You look at the price tag, and you find that it has a reasonable price. You compare it with the other antiques in the shop, and you decide that this is the one that you want.

You then call for the sales person to take the antique (let's just say that it's a vase) that you chose to the cashier, where you go to pay for it, and to, more importantly, choose the box! Why a box? And why is it that important?

Well, imagine going home with this vase un-boxed. The risk of it shattering, or at least getting a part chipped off is quiet high, and you wouldn't like this to happen, would you? Boxing is very important for reducing the risk of your vase getting broken or chipped off. But there's one more thing. The vase you chose is an antique hand made vase. It did not come out of a production line that produces thousands of replicas. It is one of a kind, handcrafted by a craftsman somewhere in the world, so it does not have a box specifically made for it with an image of the vase printed on it. You'll have to choose a box that will suit your needs. You can choose a fancy looking box if this is going to be wrapped as a gift, or you can choose a cheap box if you just want to take the vase home, and don't care about the box. The box can be made out of paper, cardboard or wood. You have the freedom of choice, and you have a really large variety to choose from, because this antique shop has got everything.

So, you choose a box that suites your needs, and now everything is OK, right? No, it's not OK. If the vase does not fit the box exactly, then you'll be facing some trouble, because the vase might break inside the box after banging to the walls of it a several times. Even if it's a perfect fit, you still have a problem. What if you decide to buy a cheap ugly looking wooden box, that is a perfect fit, but after going home, you remember that your best friends birthday is next week, you didn't get him/her a gift, and this vase matches his/her taste exactly. You'll certainly need to get a new fancy box for the occasion instead of the cheap ugly one. What will you be doing then?

Cushioning is the answer. Foam peanuts, styrofoam and bubble wrap are all great ways to cushion your valuable vase in the box that suites your needs. If you'd ever need to change boxes, there will be no problem, since you can wrap your vase in bubble wrap, and you're done. After all, this is what bubble wrap is good for (even though some people think that it's good for annoying other people by popping them in public).

What does all of the above have to do with anything? Well, let the vase be a software product, the box be the logging framework and the bubble wrap be the logging abstraction framework. That simple! You buy the software solution because this is what you want, but you need logging to trace transactions and exceptions that occur in the system, so you can tell the vase manufactures, sorry, the software vendor to give you patches that fix those problems. Using a logging abstraction framework helps you changing the logging framework very easily, without the need to change anything your software. Imagine having to change the vase, simply because the fancy box you got to put it into for your friend doesn't fit. It would be insane, wouldn't it.

OK, so what about Hani Suleiman? He's the CTO of a consulting company, and the owner of the controversial BileBlog. He's also a member of the executive committee of the JCP, and on the expert group of several specification requests. In his last post before his disappearance from the blogsphere (which was 9 months ago), he was ranting about Tapestry's creator, Howard Lewis Ship, moving from ACL (that's Apache Commons Logging, not Anterior Cruciate Ligament :P), more commonly known as clogging or JCL, to SLF4J. He was referring to Howard's blog entry, which didn't give much technical details (actually no technical details) on SLF4J in my humble opinion.

Well, I have to disagree with Hani here. Even though Log4J is one of the most widely used logging framework, it's not the best. You've got Logback for example, which was created by the founder of Log4J, and has several performance enhancements. You also have a lot of other logging frameworks, and it's totally wrong to force your consumer to use one of your choice.

When you are developing a framework (like the case of tapestry), you should never tie the users with a specific logging framework. I, for instance, like to use logback instead of the de-facto log4j. Being tied to a single implementation is really frustrating. You should be able to change the box if you want. I know that what you actually want is the vase, but if you have no choice but taking it an ugly cheap looking box, and no bubble wrap, you might think of purchasing another vase from another shop, just because you can't possibly give your friend a gift in this ugly box.

He casualy flaps his michelin man arms about about how easy it’ll be for everyone to migrate, and how its no big deal to CHANGE EVERY SINGLE F****** SOURCE FILE YOU HAVE.
This is what Hani says in his blog, and again I wonder how would a man of his position imagine something like that? SLF4J is intended to be a drop-in replacement to clogging. You just have to read the manual (which is quiet small by the way). You can just drop in slf4j.jar and slf4j-jcl.jar in your class path in place commons-logging.jar, and you're done. Now you can use bubble wrap instead of foam peanuts!

Even if you're developing a product or a system, it's a bad practice to tie yourself with the concrete implementation of, well, anything. It's the ABC of design. You have to decouple yourself from everything. You have to "DESIGN TO INTERFACES", and this is why abstraction is so important.

Dear Hani, I have to totally disagree with you on that subject. Even if you are annoyed by people constantly popping up the bubbles in the bubble wrap, this doesn't mean that bubble wrap is a bad thing. Eliminating the use of the bubble wrap would make buying the vase a great risk, since it may break, or get chipped off. Not cushioning your antiques is a bad practice. Even if you get a box where the vase fits in perfectly, without the bubble wrap, you'll not be able to change the box (logging framework) without totally redesigning the vase :D.

The only exception to the above is with log4j and slf4j. Slf4j took the liberty of creating a drop-in jar that is intended to redirect the calls made to log4j to slf4j. This is done so that if you are using a library that calls log4j directly, and you want to use some other logging framework via slf4j. Anyway, I again repeat and insist that using a logging framework directly without an abstraction layer is totally wrong. It's like putting your valuable vase in a large wooden case in the back of your car while driving on a bumpy road, without any bubble wrap!

One last thing. Some people speculated that one of Hani's subjects waited for him in a dark alley and killed him, since it's been 8 months now since his last post. Actually, Hani is still alive, but he seems pretty busy to be blogging about anything these days. He is on the industry reviewers list of two tracks of this years JavaOne. He also had a couple of comments on a blog post, and was interviewed in February by InfoQ. Good to hear that he's still alive.

At the end, if you are a fan of popping up bubble wrap, you'll like this. Another thing, the bubble wrapped statue image was taken by Japh in the British Museum back in 2004. I contacted him to ask for his permission to use it. He gave me his permission to use it.


Shams said...

a nice to present slf4j :)

Alaa Nassef said...

Actually, I wanted it to be more on logging abstraction than SLF4J. Had to mention the latter a lot since I was commenting on Hani's blog post.

Shams said...

is there a similar framework like slf4j for abstracting logging? If so how does it compare with slf4j?

Alaa Nassef said...

There's commons logging, which dates to a much older era than SLF4J. It's more complex, with lower performance, but so popular, and is used in most open source projects. I wrote a hate article on it.