Wednesday, July 13, 2011

Tuesday, July 12, 2011

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 html.py 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"</"+name+u">"
return s

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


# Now we'll actually make some tags
tags = ['html','head','body','script','p','div','table',
'tr','th','td','ul','ol','li','dt','dd','h1','h2',
'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 :
setit(loc,t)


# Use like this
html(
head(),
body(
h2("Header"),
p('para1'),
p('para2')
)
)




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.)

Thursday, June 02, 2011

Monday, April 18, 2011

Nice Quora question about code at early Google.

What I take away from these stories is that pushing out ugly prototypes of your products will not prevent you from building a world-class engineering organization in the future.

Monday, April 11, 2011

Bloody hell, Prolog can be frustrating sometimes!!!!

Sunday, April 10, 2011

Doh! I may have been a bit previous in saying that I'd got the hang of Prolog syntax.

Friday, April 08, 2011

Awesome response from SWI-Prolog when you just query an unbound variable. :-)


?- X.
% ... 1,000,000 ............ 10,000,000 years later
%
% >> 42 << (last release gives the question)

Thursday, April 07, 2011

Wow! Playing with Prolog at the moment. It's awesome.

I seem to have finally achieved some kind of fluency instead of fumbling around without knowing how to drive the thing. It probably helps that Erlang has accustomed me to the syntax and other conventions.

Monday, March 07, 2011

At Aharon's prompting I had a play with node.js over the weekend. It is very good. I can see why it's "the next BIG thing". (See the nice starter tutorial with a very impressive minimal twitter reader.)

Trying to think of something fun to do with node.js now.

Also, what with getting into Urbi, "events" are clearly the trend of 2011 for me.

Sunday, March 06, 2011

Resolver Systems have a new "cloud-based" pythonic spreadsheet called "Project Dirigible"

Wednesday, March 02, 2011

Urbi is a great, parallel, event driven language for programming robots.

Watch the tutorial video.


Absolutely packed with interesting control structures to handle the implicit parallelism and event-driven nature of the language. Several important ideas : free subsumption architecture (you actually run many different programs in parallel, each dealing with certain motors and sensors, but interacting with each other only through the body of the robot; "blending" modes which let different programs send multiple instructions to the same motor at the same time; "tags" which let you interact with (start, pause, stop) running processes by name.

Monday, February 14, 2011

An idea for an Android GUI designer.

Interesting to see the state of the art here. It's an improvement on XML ... but still, not as far forward as you'd hope.