December 27th, 2012

Working on the computer, Working

Templating Engines: The Wrong Solution to the Wrong Problem

I'm here today to explain why templating engines are the wrong solution to the wrong problem. Their popularity among various circles waxes and wanes, yet they persist. Some designers and programmers love them, and some hate them. I'm going to go through some of the common reasons why they're loved then expand on why and where they go wrong.

Using a template engine allows my designer to design without learning how to code
False. Your designer still has to learn the engine's specific syntax and its specific gotchas and how-tos. Some designers won't want to go past designing, and I respect that. They shouldn't have to. For the ones that do, though, you've effectively crippled them and required that they start over to go any further. Not all template engines are created equal and some force your designers to copy and paste instead of reuse display logic.

Using a template engine frees my programmer from worrying about the design.
False. Your programmer now has to worry about two different domains. Who is going to maintain the template engine when something breaks or your designer needs to do more than it natively allows? Designers that want to go beyond just designer are now unlikely to tackle a whole other language just to add an additional feature they need for the display logic. When a designer writes something, gets an error, and can't find a way around it, who are they going to bother to help fix it? Your programmer. Now your programmer has to know the template's syntax and implementation as well.

A template engine allows me to separate my application logic from my display logic.
True, but a template engine is not required to do this. I suspect many of us first learn about this concept by using a template engine which helps artificially enforce the paradigm, but the same can be done without a template engine. Take PHP for example, which was originally designed to be a template engine. You can put your HTML in one PHP file, your logic in another PHP file, and simply pass the variables necessary for display to the HTML file and iterate and echo them without any of the logic for handling responses or pulling data from the datastore. Your designers only need to learn about the same basic concepts of PHP that they would have in the template's syntax, such as if, foreach, and echo.

A template engine allows me to run template code from untrusted sources.
True and false. A lot of template engines make this claim, yet the reality is they are vulnerable to exploits just like the base language is. Incorrectly set up, poorly developed, or just edge cases not caught by the developers can allow malicious users to get through. If your designers are paid and working for you, yet you're concerned about this, then you have bigger problems. The only time a template engine is valid in this case is if the content is coming from random users online, in which case a template language is probably more powerful than the content your users are submitting really needs. Something much simpler, like Markdown or a WYSIWYG editor may be all you need.

Template engines have very bad performance costs
Somewhat True. Most template engines are doing nothing more than string manipulation, quite often through the use of regular expressions. String manipulation is computationally intensive and if implemented poorly extremely so. A good template engine will only incur this cost once when the template itself is modified, but many incur it every time the page is accessed. Worse yet some template engines require every add-on to manually parse the same blocks of text multiple times. If your site becomes very active then this penalty is going to add up rather quickly and your users will find another site to visit when the pages start taking more than a couple of seconds to load due to demand.

The Take Away
The real benefit of a template engine is the separation of application from display logic. The core take-away, though, is if you understand that then you can do the exact same thing without yet another template engine. A poorly documented template engine will drive your designers and programmers insane, and have a hefty learning curve. The more complex, and capable, your template engine is the more likely it will be the programmers who have to work with it anyway. If you limit the scope of the language that the designer needs to learn then it can be almost as easy on them as trying to teach them the template engine's syntax. It will also be one less subsystem to maintain.
Ctrl+Alt+Del - Scott & Ted

Facing the Music: I'm just me, nothing more or less, and not "that"

It's time to face the music and admit a few things.

First, I'm not pretty. I can't pretend to be cute, geeky, hot, fashionable, hip, or any of that. The best that can be said about me are basic facts like 'male', 'white', 'pale', and 'awkward'. Average height, average build, just average. Maybe a little worse for wear in the physical appearance charts, but I'm no bear, twink, or anything between. I can accept that some people find me attractive, but they're very few and very far between. You don't need to pretend otherwise for my sake.

Second, I'm not a social butterfly and I don't want to be one. It would be safer to say that I'm a social chameleon: I blend into the background and can get along with, on the surface, a number of different types of people. I'm a fairly generic person and don't have any extreme interests. I like a number of things, but I'm no expert or raving fan of anything. I'm strongly opinionated about specific aspects of programming, but that's really it.

Overall I'm okay with it. I don't need to be pretty, sought after, or approved. I would like to be noticed from time to time. My philosophy is largely "To each their own" and "Treat others as they want to be treated". I'm probably the most non-judgmental person you'll ever meet when it comes to people's personal lives. Furry? Okay. Nerd? Gotcha. Hipster? Whatever floats your boat. Gamer? *nods* Artist? Cool. Actor? Neat. Into BDSM? Sounds interesting (just not really for me, thanks). etc etc etc

I've got a few friends, a few acquaintances, and a few people to play games with. Some of them aren't local, but I'll take what I can get. I'm thankful for what I have and I'm happy to be just me.

So what does that mean for the future? Probably nothing specific; just business as usual.
  • Current Mood
    pensive pensive