Breaking up with Singleton

Have you ever secretly come to really dislike someone?

 

At first you think they’re great. You might even want to get closer. Then, after spending time with them, you realize they are a little obnoxious. Then, bit by bit, you start avoiding them whenever you can.

Finally, the day comes, when a friend quietly whispers “You know, I can’t stand that person”.

Reaction: Relief

Suddenly you realize you’re not crazy, it isn’t you. It’s them. Really.

Well that day has come for me and the Singleton design pattern. In Steve Yegge’s Singleton Considered Stupid I found a friend to confirm my now near hatred for the so called singleton design pattern.

Singleton and I used to be close. When I first started seeing, and, I’ll admit it, using singleton I quickly began feeling a growing unease. I found myself callously using singleton to allocate an instance, and then never speaking to singleton or the instance again.

Then things went from bad to worse. Once I started testing singleton I noticed how self centered singleton was. How could someone insist that they always be “the only one”?

Finally I started cheating; using backhanded methods to use and discard whole series of singletons. I even always took care to keep each one ignorant of the other. I told myself it was just for “unit testing”, but I knew better.

Now I realize I can’t live like this. It’s over.

Now I will only be design patterns who don’t have to be the center of universe. No more cheating, no more lying.

I hope I never see another singleton again.

Whatsa matter buddy? Yous gotta problem with Javascript?

After more than 10 years as a professional software developer I have decided that you can write good code in any language…or bad code.

I’ve seen great assembly language, bad Java, scintillating Visual Basic, poor Python, ludicrous lisp, crisp Hypertalk, and even some very good Javascript.

David Chelimsky asks What’s the Problem with Javascript and all I can do is nod my head and state “I concur”.

Javascript allows you to create classes, subclasses, and even has studly regular expression support that would make a Perl user feel right at home.

Many languages suffer from what can only be considered “the AOL” effect. When AOL really took off, (slightly) longer time internet users considered AOL users to be worthless. Some of it was that they didn’t understand [http://www.dtcc.edu/cs/rfc1855.html netiquette], but it was also that their entry onto the internet was considered too easy. They weren’t smart enough, or technical enough, or elite enough to count like ”’real”’ internet users.

Programming languages are the same way. Lisp and C++ users regularly look down on programmers using almost any other programming language because the barrier of entry to Lisp and C++ is high. Mastering difficult languages, and anything else with a high barrier of entry, should result in feelings of pride, but they also often result in feeling of superiority over others.

When I started doing web development, I felt the same way about Javascript. I had mastered C++, Lisp, and many other languages. Perhaps I would do a little client side validation in Javascript, but certainly nothing more.

It turns out Javascript is a pretty nice language. It has a fairly modern runtime: easy, built-in arrays and mapping types, garbage collection, a well designed library, and the ability to manipulate almost anything in a client browser. With a little more study I discovered that the prototype based object system was very handy for developing classes and subclasses and the syntax for doing so was only slightly more awkward than Smalltalk, Java, or C#.

These days I am asked to, and am willing, to write code in many languages I once thought beneath me.

Today if someone were to say about me “Writes good code regardless of language.” I would proud.

Any developer worth hiring should be.