Rigidly defined areas of doubt and uncertainty.

Sunday, December 09, 2007

The simplest template engine that could possibly work

In Templates Are Code, Too Hendrik explains in detail why the last thing the world needs is another template engine. So here's mine.

function template($template, $data) {
include $template;
return ob_get_clean();

That's all you need to write a template engine in PHP, because PHP is a template engine. You write your templates like this:


And call them like this:

echo template("template.tpl", array("title" => "Hello, world!"));

And you can combine them like this:

$content = template("content.tpl",
array("heading" => "Content heading",
"body" => "content body"));
echo template("container.tpl",
array("title" => "Hello, world!",
"content" => $content));

Sunday, August 05, 2007

Personality test

Personality tests, such as Myers Briggs, are a popular tool in the workplace. They replace vague subjective feelings with scientific measurements. But how far should we trust them? I recommend you try the Forer Personality Test. You'll probably learn something important.

Tuesday, July 24, 2007

If you're not using a framework, you're doing it wrong

I'm really enjoying learning Rails at the moment. One of the things that strikes me about it is how easily it meshes with my own ideas. This is what I would have written if I had the skill and the time. Suddenly a huge chunk of infrastructure code doesn't have to be written.

What Rails gives you is flexibility. Many people write their own libraries of code, or CMS systems from scratch, or use one of the major open source projects as a basis for their applications. Within the limited domain of these programs you can have pretty good productivity, but it's hard to adapt them to changing requirements without major rewrites or hacks. In Rails on the other hand, the infrastructure is cleanly separated from the application code. There is a lot less to change so refactoring is far cheaper.

For all but the simplest "Hello world" application I'd recommend using a good framework. It will have already solved your problems before you even knew they existed. Rails is my choice, but there are others.

Monday, July 16, 2007

I've joined a gym

Five weeks ago I decided to visit a gym for the first time. My local leisure centre has a 'kickstart' programme of five weekly appointments with an instructor to get you started. For someone like me who's never used a gym before it's a real help to have someone to guide you.

The idea of going to a gym never appealed to me before, but I'm actually rather enjoying it. The great thing that a gym has to offer is variety. Everything you need is all in one place. That helps to keep it from getting boring too. I don't do more than ten minutes or two sets on any one exercise.

No measureable results yet, but I definitely feel fitter, and I'm able to exercise harder now than I could when I started, and that's the measurement that counts.

Friday, March 23, 2007

How to herd cats

The Good Soldier Skat is a great essay in which I found much to sympathise with. In it Richard Hillesley contrasts a traditional regulated bureaucratic business with the freedom of open source projects. It's not so much a case for open source software as the idea of trusting and freeing your workers. Companies really should look to successful open source projects to see how to organise and motivate their own teams. It means letting go of some control, which is a risk, but the benefits could be much greater.

Via programming.reddit

See also The Success of Open Source and Innovation Happens Elsewhere

Monday, March 19, 2007

The Pyramids are crap

The Pyramids are crap. Egyptians should be embarrassed by these massive monuments to stupidity. They're a constant reminder of how utterly useless the ancient Egyptians were at architecture. What's the very simplest way to build a tall structure that won't fall over? Pile the bricks on top of each other. And that's essentially what the pyramids are. Big piles of bricks.

The only thing you should be impressed by is the fact that the Pharaohs had such resources and power at their command that they could be so wasteful with them. I'm sure the slaves worked as hard as any man can, and the pyramid building operation was run as fast as it possibly could be. All that hard work. What a waste. It only goes to show that hard work doesn't pay off.

I'm not going to build any pyramids.

Thursday, March 01, 2007

Movie title fun

[From The Jay]

Looks like the Web 2.0 meme has drifted into the movie business. Surely this is the first movie with a minor version number? A good move in my view, much easier to keep track of than all re-remasterings and directors cuts of directors cuts.

Sunday, February 25, 2007

Ubiquitous version control

The more I use it the more applications I find for version control, and each time I find a new application it alters the way I work.

In the first instance, version control is just a safe place to store your code and keep track of changes between revisions.

If you use a concurrent versioning system such as svn then it also becomes a tool for collaborative working. Two people can work on the same file and each time one of them commits their work to the repository the other can automatically incorporate the changes in their copy of the file.

I've started using the same functionality to manage staging and live versions of websites. The web server connects to svn just like any other user and can update its copy of the site to the latest version with a single update command. Bye bye ftp.

I sometimes work from home and it's very useful to be able to pick up the exact code that I've been working on at the office. Martin Fowler takes this even further in MultipleDesktops. In my latest project I've set up the repository with not just the code, but also the specification documents, the HTML pages I need to get started and my own notes and documentation.

One problem I have with using version control for remote working is that I don't want to commit broken code. Then I watched this screencast on Atomic Coding (BTW aren't screencasts great). It's very much in the spirit of agile and test driven development, and is made easier by using dynamic languages without a compilation cycle. The trick is to make small steps, where each step produces working code of some description. When the time between commits is no more than a couple of hours there's not much opportunity to leave code where I can't get at it remotely. Another benefit of atomic coding is that commits act as a kind of bookmark so I can keep track of where I am when I'm switching between several projects, which is often the case when your working on web site timescales.

I don't think I'll have hard time adapting to the atomic approach. The biggest change will be at the start of a project where I usually write a lot of code before running anything. To code atomically I'll have to make sure each class runs before I move on to the next one.

Sunday, January 14, 2007

How not to advertise software

"If programmers built planes" shows a team of engineers working to finish a plane in mid flight. A rather unfortunate metaphor. I thought it was a parody, but apparently EDS paid for this.

It's true that requirements change and software grows and evolves with business, but good programmers make sure it never has to fly with gaping holes in it's hull, or an untested undercarriage. The plane metaphor states the problem very well, but doesn't show how EDS think they can solve it. How do you write an exciting advert around ideas like test driven design, encapsulation and refactoring? Something I should think about, because they're ideas I need clients and my non-technical colleagues to understand and appreciate.