July Link Dump

gsmith | link dump | Sunday, July 27th, 2008

A fantastic talk by Clay Shirky about the idea of a “cognitive surplus”.  What do gin and sitcoms have in common besides being fantastic together?  Watch to find out.

The subway doesn’t really work this way, but this surrealist comic is fantastic.

This video featuring the personifications of famous fonts has been making its rounds on social news sites lately, but it is too good to leave out.

Destee Nation Shirt Company has an enticing slogan: “Real shirts from real places.”  Great products, and totally feeds my need to have unique stuff.

This seems like a reasonably good design blog: dropping it the old RSS reader to see how it sits.  Let me know if you know of other good ones.

And lastly our token ridiculousness: an anamotronic monkey head attached to a Roomba.

Pattern Prone

gsmith | programming | Wednesday, July 23rd, 2008

A commenter on my Problem with Patterns post had an interesting response:

“It think that what you are trying to do, identify patterns that are more interesting because they are not so much a work-around for missing language features is an interesting approach—and greatly more sophisticated that the average “critique” of patterns. And yet, would Flyweight seem so interesting in a language with symbols and automatic memoisation?”

I’ll go ahead and plug their blog as thanks for being so insightful.

This got me thinking about what I was really getting at.  The whole thing came to mind after having a “I hate design patterns” conversation with someone, but really we were trying to say “I hate having to use a design pattern to do something that should be easy.”  Usually this happens when you are aware of a different programming language in which doing that thing would be easy.  Or maybe you’re just very imaginative.

So what I decided to get out of the whole discussion (both with commenters and with other people I’ve spoken with lately) is that some programming languages are Pattern Prone. A Pattern Prone language is a language where certain restrictions or missing features cause you to repeat complex processes to solve simple problems.  This is a fuzzy measurement: you can’t really make a definitive list of what languages are Pattern Prone.  But it will give you a better way of expressing certain complaints without posting on your blog that there is a Problem with Patterns.

Patterned Backgrounds

gsmith | the web | Saturday, July 19th, 2008

I’ve been noticing websites using patterned backgrounds again.  This is a trend that died pretty early, but the resurrection has been tasteful thus far.  InviteShare is one site that pushes on the idea hard, takes risks, and pulls it off.  I love the black translucent parts contrasted with the orange translucent parts.  Also, intricate, flowery patterns look great in dark gray on black.  My favorite dress shirt is dark gray on black paisley.

To experiment with the technique, I’ve put a pink skull pattern on this site.  It could use some tweaks, but I’m going to let it sink in for a bit before I decide what to do with it.

(Note: the site design has changed since this post)

Text Zoom on the Web: The Game Changes

gsmith | the web | Thursday, July 17th, 2008

Changing text size in a web browser is an accessibility feature. I’ve never seen someone do this besides to read text that is too small. Anyone with sub-par vision needs your site to be accessible. Hell, I do, if I forget my glasses somewhere.

I want to bring it up because major browsers are changing the way they zoom. Opera seems to have started it, and now Firefox 3 does it as well: Modern browsers scale the content wholesale, rather than shifting around font sizes and letting the layout recalculate with the new values.

This is great! Any complex layout requires careful thought to get zooming right: You’re basically designing 3 or more different layouts (the big one, the normal one, the small one). Layout becomes slave to font sizes rather than pixels, the actual medium you’re working in. With the way new web browsers are being made, soon you’ll never do any work to make your site scale. Keep that in mind, watch the progress browsers are making, be ready to stop designing for old-school zooming as soon as it makes sense for you to stop.

Simple Lessons

gsmith | programming | Monday, July 7th, 2008

Some of the simple lessons I’ve learned lately.

  • Software features are a waste of time if you haven’t released your software yet.  Not exaggerating.  Literally a waste of time.
  • Cultural connotations don’t go away when you ignore them.  You can’t reason with them.  If a cultural connotation is disrupting the effect of something you’re doing, steer clear.  You can’t beat society.
  • Sometimes you need a case of Red Bull, a couple Pizza deliveries, and a weekend of being a shut-in if you want to be a productive programmer outside of your job.
  • Good ideas are easy to come by.  Most of them aren’t plausible for you, personally.  Choose carefully.

The Problem with Patterns

gsmith | programming | Tuesday, July 1st, 2008

There was also a problem with popplers, but it is not related.

(Note: I later wrote this post, which comes to a better conclusion than this article did -Greg)

I’m not a big fan of design patterns.  I know, I know, what could be bad about established processes for solving equally established problems?

I’m not going to complain about misuse of design patterns.  I can roll my eyes at overuse of Singletons, but can’t say overuse is the pattern’s fault.  A lot of people misuse the Factory Method Pattern.  Sometimes people seem to just use this pattern for the hell of it, when a normal constructor would suffice.  Still, these people are Doing It Wrong, so it is their own fault.  I’m not even going to complain that people use patterns as an excuse to not really think through their problems and figure out the best thing to do.  Like I said: This is not what is wrong with design patterns.  This is what is wrong with bad programmers.

So what is wrong with design patterns?  Let’s start by analyzing a few examples.  I’m going to draw my examples from the ubiquitous Design Patterns: Elements of Reusable Object-Oriented Software.

Lets look at the Command Pattern.  In it “A command object encapsulates an action and its parameters.”  I always call this the Functor Pattern, because I call these things Functors.

In a lot of languages, this doesn’t even constitute a design pattern.  The idea of functions as first-class objects, specifically functions that can be assigned to values, makes doing this a fundamental part of programming in that language.  For that reason, we can adjust the definition of the pattern:

“A command object encapsulates an action and its parameters.  This is useful in languages that don’t allow function values.”

Here is what is interesting: The pattern is not about programming.  It is about programming in this particular language.  In some other languages, the pattern is meaningless.

Let’s look at another example.   The Factory Method Pattern is about hiding the concrete class of an object.  Look at this constructor (in Java):

class DatabaseConnection {
    public DatabaseConnection() {
        ... do some set up work ...
    }
}

Lets say we want to implement both MySqlDatabaseConnection and SqlServerDatabaseConnection.  But we want which one we use to be defined in a configuration file rather than in the code.  Normally you would create a constructor for each of these classes, but then, when you want to instantiate the database connection, you have to pick one.  You can’t do this:

class DatabaseConnection {
    public DatabaseConnection() {
        if (Config.getConfig().getDatabaseType().equals(DatabaseType.MYSQL)) {
            return new MySqlDatabaseConnection();
        }
        ... else if etc ...
    }
}

Doh!  Constructors have no return values, so this is just bogus, though it might seem like what you want to do.  The Factory pattern is the way to do this that actually works.

But stop.  See what happened there?  We are using a design pattern because we can’t do what we want to do.  If Java constructors worked a little differently, and let us construct an object of an arbitrary subtype of the type the constructor lives in, there would be no Factory pattern.

As you begin to analyze the various established Design Patterns, you start to notice this type of thing more and more.  A lot of them solve problems that are imposed by the programming language you are using.  Some ways to recognize such patterns are:

  • The pattern is too trivial to mention in a different programming language
  • The pattern results from being unable to do what seems naturally correct

Not all design patterns are like this.  The Flyweight Pattern, for example, seems to basically reduce to optimizing the time-space trade-off of a group of many similar hashes.  This is more of a data structures thing than most Design Patterns seem to be.  It is also particularly interesting and useful, in my opinion.

So, going to sum up and draw some conclusions.  It is no accident that Java is the language that brought Design Patterns to the forefront of our minds: It also is a language that loves to force you to do things in very particular ways, especially as opposed to simpler and more elegant languages.  Many design patterns emerged as ways to do things that aren’t specifically considered in Java’s Way Of Doing Things.  And that is what frustrates me about them: I’d really rather just use a language where it is easy to do what I want to get done.

Of course, I’m not going to get into a discussion of the advantages of strictly constrained ways of doing things, or dynamic versus static typing, or anything like that.  Suffice it to say: I understand there are advantages.  However, these advantages don’t do much to reconsile my enjoyment as a programmer.  And I admit: I’m a little selfish that way.

By the way, the picture for this article is a Poppler.  There was a problem with them too, but it is not related to the problem discussed in this article.