Home of The JavaSpecialists' Newsletter

077"Wonderfully disgusting hack"

Posted: 2003-09-02Category: Software EngineeringJava Version: Dr. Heinz M. Kabutz
 

Abstract: 

 

Welcome to the 77th edition of The Java(tm) Specialists' Newsletter. I sent out a newsletter last week to see who preferred text over HTML, especially regarding SPAM filters. Due to the public outcry at the suggestion of moving away from HTML, I will in future send all newsletters as HTML. Please change your SPAM filters to receive emails from my email addresses.

I am sitting in a hotel room in a stunning little town in Switzerland called Zug whilst my daughter is celebrating her second birthday today. My voyage began on Saturday afternoon from Cape Town to Johannesburg, and on towards Zurich. My suitcase had other ideas. He liked Johannesburg quite a lot, and together with the other suitcases from the flight, decided to stay overnight and then instead travel to Paris, go on a tour of the Eiffel tower, meet some pretty lady suitcases, etc. He arrived last evening at my hotel door, looking rather bedraggled, with an accusing look on his face: "Why didn't you call?" he told me as he walked through the door. He amused himself by the look of his owner squashed into a one-size-too-small shirt that belonged to our Swiss customer. "What's with the shirt?!" he had the audacity to exclaim. If he thinks he is coming with to China, he has another thing coming!

Birthday and Anniversary Special: Since the 30th November 2017 is the 17th anniversary of our newsletter and my birthday is coming up on the 4th December, we are giving away a 30% discount on our new Data Structures for Java 9 Course (Late 2017 Edition). Whether you are a seasoned Java programmer or you just want to get ready for your next job interview, this course will help you. Besides detailed lectures, the course has over 130 questions that will help you discover what you missed.

"Wonderfully disgusting hack"

People sometimes ask me how I find out the things that I write about in my newsletter. The answer is that I don't know how. It is pretty much a random walk through the JDK source code that gets me the best results.

Last night, whilst my suitcase was screaming through the air at 30'000 feet, I spent some time reading through a new release of the J2EE Core Patterns book. Whilst I was reading it, I was getting more and more agitated with the way that exceptions were being handled. You know I am not a fan of checked exceptions, and in a future newsletter will expound on this. I got sidetracked from reading the book, and ended up reading up on how java.awt handles exceptions. During these explorations, I stumbled across a comment in the java.awt.Toolkit class in JDK 1.4.2 that is simply priceless. It goes like so:

    static boolean enabledOnToolkit(long eventMask) {
        // Wonderfully disgusting hack for Solaris 9
  

Is that not cute? To write that in code that you know could possibly be read by 3'000'000 Java developers around the globe takes a lot of chutzpah.

I did a search on the classes in the JDK 1.4.2 and found 45 classes that contained the word "hack". A great portion of these are from org.apache.* packages, but the majority is from code by Sun Microsystems.

Now the magic question: Am I worried? I am trying to build software for major industry players on top of a basic platform that contains 45 classes with documented hacks! Perhaps I should be worried - but I am not. What is worse than knowing you are an idiot? Worse is thinking you are not a dolt, but actually, being one.

Therefore, here are some reasons why I feel more comfortable than ever to write industry-strength code on top of Sun's JDK:

  1. All software contains hacks.
  2. I would prefer to know about them.
  3. Only a real developer would write "hack" into his comments.
  4. I am therefore more comfortable using Sun's JDK than some black-box proprietary solution with hundreds of undocumented hacks.

This is a really short newsletter, just to get this topic off my chest. Do yourself a favour and look at the source code of java.awt.Toolkit in JDK 1.4.2. I think you will enjoy it :-)

Warm regards from Switzerland, and my suitcase also says "hi".

Heinz

 

Related Articles

Browse the Newsletter Archive

About the Author

demo

Java Champion, author of the Javaspecialists Newsletter, conference speaking regular... About Heinz

Java Training

We deliver relevant courses, by top Java developers to produce more resourceful and efficient programmers within their organisations.

Java Consulting

Nobody ever wants to call a Java performance consultant, but with first-hand experience repairing and improving commercial Java applications - JavaSpecialists are a good place to start...

Threading Emergency?

If your system is down, we will review it for 15 minutes and give you our findings for just 1 € without any obligation.