Wednesday, September 26, 2007

Black Hat Antipattern

On the way to work yesterday, I sat on the bus and was thinking of problems related to 3rd party components with source code you have no access to. Software modules that is not shipped with source code is often called black box components. This has historically been viewed as a good thing, but with the advent of Open Source, the advantage of having the software available has become evident. Before the weekend I had been trying to integrate with a backend system by using a inhouse developed library, which of course I did not have the source code for.
After struggling a long time with the library, which kept complaining in the log about a NullPointerException and a follow-up about a missing protocol I had to surrender. The library kept it's secrets tightly to it's chest.

While I was thinking about this, thoughts about magicians that pulls rabitts out of black hats came to my mind. The analogy is that the library pulls some configuration out of the Black Hat, but I did not have a clue of what to put in it to satisfy the library. The configuration file contained a property name protocol but it did not make any difference what value I supplied for it.

When I arrived at work a coworker was struggling with an exact analogy. He was using a low-level library (a sort of Data Access component), which was dependent on the HTTP session via JSF FacesContext. The is no recipee for success when using the library in a Axis 1.4 Webservice. Axis does not expose the HTTP session in any way, but some sort of manipulation of Axis could have solved it (e.g. sublassing the Axis Service servlet or with AOP) This is obvious a horrible dependency, but luckily we could get access to the source code and easily patch it.
My coworker coined the phrase I had been thinking of for libraries and components that pulls data from unknown sources as pulling from a black hat.
Another coworker who had been working a lot with this library said this dependency had caused him a lot of trouble while writing JUnit tests. I happen to be Testinfected, and believe libraries/componentes that make Unit tests hard to write should be considered candidates for refactoring and even replacement.

If you encounter Black Hat dependant libraries or components that makes Unit tests hard to write, consider your options:
  • Do you have the the source code?
    • Can you change it?
  • Is it easy to replace? In the long term it can harm your project.
  • Do you need it? Can you develop a replacement with the same or less effort as the hazzle struggling with it?