Globalton «

Comments Off on Globalton

It’s Steve Yegge’s fault that I was rethinking the singleton pattern. I read his Singleton Considered Stupid post in early 2008 with the rest of the proggit before it devolved into a memetic garbage patch. Yegge’s rant ends with a note about design patterns that curled up in my hindbrain and has been whispering to me since:

The problem is, about 1/3 to 1/2 of them [design patterns] were basically cover-ups for deficiencies in C++ that don’t exist in other languages. Although I’m not a huge Perl fan anymore, I have to admit the Perl community caught on to this first (or at least funniest). They pointed out that many of these so-called patterns were actually an implementation of Functional Programming in C++.

I’ve had the ranty discussions about how the singleton could be better known as globalton typical of any developer who’s heard that joke:

I’ve never understood why people bother with all that mucking around with instances. Just tag the object initialization on to the end some startup script like the database initialization and add ‘global $map;’ anytime you want to access it. It’s a global variable; most languages have very succinct idioms for managing those, unfortunately.

Singleton has a very small niche managing some hardware access and then is abused approximately all of the time as a noisy version of global variables. Seeing this over and over kept me thinking about whether design patterns are indeed mostly a standard set of tools for working around language deficiencies. (ObSlander: It’d certainly explain the Java community’s fixation on them.)

I’ve had an urge to reread Design Patterns and work through them in a high-level language like Ruby or, better, JavaScript.

But it turns out, as usual, that Peter Norvig is way ahead, with a 1998 presentation on design patterns in dynamic language noting that in some languages design patterns are simply invisible. Unfortunately he didn’t leave behind a detailed pronouncement of opinion as to the value remaining in design patterns when a language invisibly supports the most common patterns at the least, so I suppose I still have the exercise ahead of me.