Been browsing some interesting discussion over at Quora on how they built their site.

It’s basically Python and Pylons. But this is cool. They don’t use a templating language.

Here’s developer Charlie Cheever :

What “templating” means to most people is a way of having the developer write out HTML basically the way that you would send it to the browser and then having a way to include a few things — typically variable substitution by using special tags lik or similar.

In our case, no one writes any code that looks like HTML/XML literals, so there’s nothing in our codebase that really matches what most people think of as templates. We do have view code but that interleaves calls into the model and application logic along with a Python code description of what the HTML for that component should be, which is different from templates which are usually based around the ideas of separating logic and data fetching from this.

This sounds like an approach I’ve been favouring for a while. I did it in Mind Traffic Control, some other unreleased SdiDesk in Python experiments, and I do it in some Javascript I’ve written. People think that you should separate HTML from code because HTML is the domain of designers and code is for programmers. But I think HTML is the realm of data-structure (designers should stick to CSS) and part of the programmers’ remit.

The way a programmer (or at least, this programmer) wants to express complex data structures is with function composition. So here’s an example of my file.

# HTML library
# basic level

def tag(name,x,*argv) :
if x is None :
return u"<"+name+u"/>"
if argv != (None,) :
inside = u''.join(argv)
else :
inside = u''
if isinstance(x,dict) :
# we're passing a dictionary of attributes for the tag
s = u"<%s " % name
s = s + ' '.join(['%s="%s"'%(k,v) for (k,v) in x.iteritems()])
s = s + u">"+inside+u""
return s

# or there are no attributes, just inner
return u"<"+name+u">"+x+inside+u""

# Now we'll actually make some tags
tags = ['html','head','body','script','p','div','table',
'h3','h4','h5','h6', 'style','pre']

loc = locals()
def setit(loc,t) :
loc[t] = lambda x=None,*argv : tag(t,x,*argv)

for t in tags :

# Use like this

But I did start to wonder, given the prevalence of templating languages and some of my recent experiences as a Django developer, whether this wasn’t just me being wilfully perverse / crazy. I admit I’m kind of relieved to read that Quora are doing something similar. Maybe I wasn’t so mad after all.

Bonus link : Decomposition by language is probably a modularity mistake. (Written back when I was more confident.)

To return to a theme I started many years ago, I commented on this excellent article about why web-site development has got so damned hard. (And remember when we all thought of web-apps as lighter and simpler than desktop apps? What happened?)

Anyway, here’s my comment.

I think the problem is less the multiplicity of programming languages, than our insistence that we should always be separating our languages in different places.

This goes against the basic tenets of cohesion and coupling. We cluster unrelated activities together because they happen to have the same syntactic sugar, while separating tightly-coupled activities because half of them happen on the client and the other on the server. Why the hell should this implementation detail have to be reflected in our architecture?

What I’d like, controversially, is to be able to mix-and-match the languages within the same source file, grouping together the python, javascript, html and sql that actually has to work together in one place. I have no trouble dropping into regular expressions or similar DSLs from inside my main code, why should dropping into a layout or query language be different?

Joel Spolsky :

And your programmers are like, jeez louise, GMail is huge, we can’t port GMail to this stupid NewSDK. We’d have to change every line of code. Heck it’d be a complete rewrite; the whole programming model is upside down and recursive and the portable programming language has more parentheses than even Google can buy. The last line of almost every function consists of a string of 3,296 right parentheses. You have to buy a special editor to count them.


I mean, that wasn’t exactly the whole GeekWeaver gameplan. But “high level” lisp-like language that compiles down into complex web-applications, is not so far off. I was thinking of Dojo as the Javascript library, PHP at the server, and Facebook itself (or Ning) as the layer at which applications can be glued together. So read with Marc Andreesen too.

It’s the zeitgeist I tell ya’