Django template philosophyOct 15 2012 | 09:56:03 | 1 Comment

Django template philosophy shares quite a bit with Chunk.  I just came across this nugget on the Django website where they describe the design decisions that went into their templating framework:

Separate logic from presentation

We see a template system as a tool that controls presentation and presentation-related logic – and that’s it. The template system shouldn’t support functionality that goes beyond this basic goal.

If we wanted to put everything in templates, we’d be using PHP. Been there, done that, wised up.

Couldn’t agree more.

Discourage redundancy

The majority of dynamic Web sites use some sort of common sitewide design – a common header, footer, navigation bar, etc. The Django template system should make it easy to store those elements in a single place, eliminating duplicate code.

This is the philosophy behind template inheritance.

Agreed.  Chunk gets this done with “exec” and “include” but, same idea.

Be decoupled from HTML

The template system shouldn’t be designed so that it only outputs HTML. It should be equally good at generating other text-based formats, or just plain text.

Absolutely.  I use Chunk all the time for templating plain-text e-mail, JSON, CSV, config files, XML etc.

XML should not be used for template languages

Using an XML engine to parse templates introduces a whole new world of human error in editing templates – and incurs an unacceptable level of overhead in template processing.

I think this is a dig at XSLT and funny XML-based templating solutions like Thymeleaf.  I never understood the appeal of these either.

Assume designer competence

The template system shouldn’t be designed so that templates necessarily are displayed nicely in WYSIWYG editors such as Dreamweaver. That is too severe of a limitation and wouldn’t allow the syntax to be as nice as it is. Django expects template authors are comfortable editing HTML directly.

Hear hear.  Chunk keeps both options open, however.  A file full of snippets probably won’t open in DreamWeaver but if you stay away from snippets and define one template per file, you should be able to use just about any HTML Editor out there.

Treat whitespace obviously

The template system shouldn’t do magic things with whitespace. If a template includes whitespace, the system should treat the whitespace as it treats text – just display it. Any whitespace that’s not in a template tag should be displayed.

Okay, so here I disagree.  If you don’t do some “smart” handling of whitespace, your template gets contorted and unreadable when you actually do care about the whitespace in the final output.

Don’t invent a programming language

The template system intentionally doesn’t allow the following:

  • Assignment to variables
  • Advanced logic

The goal is not to invent a programming language. The goal is to offer just enough programming-esque functionality, such as branching and looping, that is essential for making presentation-related decisions.

The Django template system recognizes that templates are most often written by designers, not programmers, and therefore should not assume Python knowledge.

Wow.  Couldn’t have put it better myself.  This is what Chunk is all about.  If you want to write code in your templates, go use PHP or JSP.  Knock yourself out.  But man, your templates are ugly and your whole team is going to suffer headaches from looking cross-eyed at your mishmosh code.

Safety and security

The template system, out of the box, should forbid the inclusion of malicious code – such as commands that delete database records.

This is another reason the template system doesn’t allow arbitrary Python code.



The template system should recognize that advanced template authors may want to extend its technology.

This is the philosophy behind custom template tags and filters.

Chunk is similarly extensible: write your own filters, make your own tag-command protocols.

Careful kid, they’ll break ya heaht…May 15 2009 | 09:02:45 | No Comments

I have cancelled my cable TV. Man did it feel good to tell Comcast to go **** it. Net gain $840/yr. Well, minus whatever it will cost to buy episodes of Top Chef for my wife (ok I admit it, she’s got me hooked too).

tim_thomasRabid sports fan that I am, I did not take the plunge until I discovered and the wonders of p2p live streaming sports. So far this has turned out to be a mixed bag. When it’s good, it’s mid-to-low-res but you can follow the action. Veetle is pretty cool. When it’s bad it really stinks. The players and plays are fuzzy. The score is rarely legible. The keyframes drop out and for several seconds at a time blotchy pieces of the previous shot carry over for that “they’re playing in a vat of pea soup” effect. The best is when the feed stops for buffering just when Ray Allen has released the shot that will send the game into triple overtime.

But hey, the Bruins are in the playoffs (well, until they choked in OT last night), the Celtics are in the playoffs, and I have found that I will endure quite a lot of low quality picture to be connected to the hunt for a championship.

Some nights the only available feed is from Taiwan, with audio in Taiwanese Chinese (although I have to say, I don’t speak a word and the Taiwan commercials are still hilarious).

I find it ironic that in this age of higher and higher def, my own TV viewing quality experience is moving in the opposite direction. It’s consoling to think that a generation earlier I might be slapping the side of the TV fonzie-style before a big play to try to reduce the static from a bad over-the-air signal. Now I move around the room and adjust the angle of my laptop in the hopes that our wifi is the bottleneck.

However fuzzy the broadcast, last night proved to me that they can still break your heart, and that stings in hi-def. Bruins out of the hunt. Magic force game 7 on the Celts. Sox fall in the 12th. To cap it all off, the Yanks win. I guess we had it coming?

iPhone App EnvyMay 04 2009 | 16:46:59 | No Comments

Argh, it’s such a timesuck upgrading my jailbroken iPhone to the latest iPhone firmware/OS.  I have T-Mobile so I have to keep my iPhone jailbroken/unlocked.  It’s easier than you would think (initially) but I’m still reminded of how annoying it is (1) every time I try to install some cool-looking app just to find that it runs only on the very latest iPhone OS, and (2) every time I open iTunes and that damned dialog pops up (‘Hey, you haven’t updated to the latest iPhone version.  I know I’ve asked you like 527 times already but gosh, don’t you really want to upgrade?’)

Yes.  I’m looking for the button that says “Yes, damn it, I do want to, but I don’t have five hours right now to waste re-jailbreaking and re-unlocking my phone afterwards, and then re-syncing 15GB of music and apps, just so I can run Sportacular.”

Why is it so hard to write iPhone apps that are back-compatible with “ancient” 2.1 which everyone was running, what, two months ago?  Aren’t they all just glorified javascript apps anyway?  Blurg.

I miss my sidekick.  Kinda.