I'll Give You My Template When You Pry It From My Cold Dead Hands

| Comments

In a recent Coding Horror post, Jeff suggests that templating frameworks are often more trouble than they’re worth; valuable only in trivial cases:

I think existing templating solutions are going about this completely backwards. Rather than poking holes in HTML to insert code, we should simply treat HTML as code.

Huh? Have we not struggled for years to pull ourselves up out of the muck of generating markup in our code? Jeff goes on:

Templating tends to break down because it forces you to treat code and markup as two different and fundamentally incompatible things.

CORRECT! Code and markup are two different things. They’re different languages! When you write a web app, you’re using one language (Python, Java, Ruby) to generate others (HTML, Javascript). A daunting task, no matter how you slice it. Why smash them together?

By keeping markup very far away from business logic, the core logic is more stable and there’s less temptation to mingle concerns.

Tag soup happens because web development is complex stuff, and there’s really no way around it.

If you don’t like the syntax of a templating system, find one you like better or work to isolate the gross parts. Whatever you do, please don’t push us back to the dark ages of building strings of markup in our code, no matter how seductive your language makes it feel.

blog comments powered by Disqus