« March 2005 | Main | May 2005 »

April 23, 2005

Great things I've never done

I regularly have ideas that are impossible, or forget within hours, have no clue how to implement, or no time, or all of the above. I really should make a list.

  • A squeak wrapper around the Gecko HTML rendering engine.
  • A simple, high quality probabilistic gossip based P2P framework (I actually started a Java version but got bored).
  • A tuple space implementation on top of the aforementioned simple P2P framework.
  • A mobile-code mechanism for the tuple-space, so arbitrary tasks can be submitted. The Jini model uses jars downloaded from a webserver, which isn't really 'grid' enough somehow.

April 22, 2005

Programming as Literacy

In what's typically called 'the western world', before literacy became essentially ubiquitous it was limited to a select few. Monks originally, then scribes. These individuals possessed a truly remarkable skill. They could make marks on paper that could remember things. They could capture information and retrieve it later. Associated with this skill was the ability to make marks that could perform complex computations and produce an answer. People with these skills were hired by nobles and merchants to increase business value.

You know what I'm going to say next of course.

Programming appears to have many parallels with literacy in medieval times. It is a somewhat arcane skill known to a select few, who typically put that skill to use for others in return for remuneration. There are very few scribes left nowadays, although I'm sure at the time they felt that as there would always be a need to write things down, that there would always be scribes.

April 20, 2005

It's not technical

A counterpoint to this post from my colleague Sam.

It's not technical. Languages don't succeed for technical reasons. If this were true we'd all be programming in Lisp and Smalltalk. Java became popular by riding the internet (specifically the web) wave. .Net became popular because Microsoft have billions of dollars to spend on marketing. Both of these platforms have something in common - they are aggressively marketed by a big industry name.

Write once, run anywhere. Sun coined the term, and successfully won the mindshare. Developers working in Lisp & Smalltalk wondered what was so special about that.

Garbage collection. Most work in garbage collection was done in the 70's and 80's (possibly even earlier - Lisp has been around since the 60's). Again marketed heavily by Sun, while the aforementioned Lisp and Smalltalk programmers looked on nonplussed.

Lisp didn't take over the world because (to my knowledge) there was no big name vendor marketing it, and everyone outside the Lisp community thought it was just for AI.

Smalltalk didn't take over the world because of infighting between vendors, and a failure to see the threat of Java. They were too busy competing with each other to notice that Java was about to swamp all of them.

Having said that, there are places where Smalltalk and Lisp are thriving, and those companies are more than happy for everyone else to remain distracted by Java and .Net while they consistently outperform them in time-to-market of new features.

April 15, 2005

Immovable Type

Looks like the Sixapart, the creators of Moveable Type, have gone all commercial and VC funded on us. I look forward to explosive growth followed by burnout, collapse and recrimination. Maybe they'll get lucky and be the 1 in 10 that make it.

Freaky Friday

Woke up this morning convinced, convinced it was thursday. Someone on the tv just mentioned that it was friday, and it was like I'd been given a huge and unexpected present. Bonus. What a great way to start the day.

April 14, 2005

Can your Rails do this?

Don't get me wrong, I love Rails. Its great to see something that isn't .Net or Java gaining traction. ThoughtWorks has an internal mailing list about it and the traffic has been impressive so far.

Its just that now more than 25 people have heard about it, well, it feels like its gone all mainstream.

So I'm splitting my cool-new-dynamic-language-based-web-application-framework bandwidth between Rails and Seaside.

Today I saw something in Seaside that gave me one of those 'Dude, that so totally rocks' moments.

There's an innocent toolbar option in Seaside called 'Toggle Halos' that switches on a visual representation of the components on a page, with some icons for each one. One of the icons looks like a spanner (wrench), and when clicked on, shows you the code for the component in your browser, and lets you edit it!

Oh yes. Welcome to really rapid application development.

We need one of these

The software industry really needs an equivalent to Perry's, the chemical engineering reference guide. This book more or less contains all the information needed to build your own functioning oil refinery or other chemical engineering construct.

April 12, 2005

One thread per cpu

Hyperthreading notwithstanding, one thread per cpu will give you the highest application performance. Having more than that means context switching and contention, which means the cpu is spending time on tasks other than running your program.

For this reason, the fastCGI approach to web application servers is definitely a good thing - prefork a fixed number of single-threaded processes to handle requests, one per cpu.

So why spawn more threads or processes than cpus? Blocking. If a thread blocks, its out of action until the thing its waiting for is ready. With 1 thread per cpu, if a thread ever blocks, thats a whole cpu idle. To implement an application that never blocks, especially when it needs to make network calls (eg. to a database), or read files, is more challenging than doing the same thing with blocking calls and many threads.

April 11, 2005

CyUnit

Bought the 1st series of the remade Battlestar Galactica yesterday. Much darker and edgier than the original. None of the characters appear to be all-bad or all-good, and most of them have 'issues' of some kind.

One of the characters was working on a Cylon detector (Cylons are the bad guys, robots that look like people and want to wipe out humanity, although some are programmed to think they're human), and there's a scene where we see the UI for the first time: red bar / green bar!

Introducing CyUnit. Red bar, failing test, you're a Cylon. Green bar, you're human. Made me laugh, geek that I am.

Cool technology, bad name

The combination of DHTML, Javascript and XMLHttpRequest has been making weblog headlines recently. My experience with it predated the hype by about 6 months (we were porting a rich client system to the web and hit upon using XMLHttpRequest specifically as a solution to some of the responsiveness issues). I was a little slow to realise just how unknown the technology was in the wider world, but I don't mind that, so much as the appalling name its come to be known by.

Ajax? It sounds like a brand of detergent. Oh wait. It is.

April 09, 2005

Encapsulate the Database

Picking up the 'schema as 3rd party code' idea, I want my database access to be encapsulated behind an insulation layer that decouples the business logic from the table schema.

This is the primary reason I have mostly lost interest in tools such as Hibernate and Neo. Where the documentation says things like 'Autogenerate your mapping layer and persist your domain objects', I see 'Tightly couple your code to your database'.

Relational databases are hard to change. Especially once they've gone live. They very quickly foster an ecosystem of reports and queries, and almost always become an ad-hoc integration point for several applications, making schema changes very difficult.

For this reason alone, any tool which works by coupling business logic to to the database causes me concern. On almost every project I've seen that had an OO application and a relational DB, the persistence mechanism became a point of pain. Code becomes really hard to change because its constrained by the database schema and there's usually an additional maintenance burden of keeping an XML configuration file in sync.

Code Insulation

Or, 'Just because its open source I don't want to have to compile it every time'.

Dee mentioned using vendor branches to manage 3rd party source.

I choose to avoid them. If I'm using a 3rd party library, I want a released binary. Recompiling someone else's source as well as my own seems like a waste of time.

With respect to 'fixing in place', sure, if I know a solution I'll submit a patch, but fixing in place means forking the 3rd party codebase, which (depending on the license) might oblige me to release it back to the community (which means time spent not getting work done), and opens a real potential for causing merge hell when I want to use a new version of the library. This happened to me a few weeks ago. Had the project done either of encapsulating access to the 3rd party code, or stuck with a binary version, the upgrade would have been far easier.

April 07, 2005

Inversion of inversion of control

Followup to Sam's post, Sam's other post and Liz's post about Sam's posts.

The contextual IOC pattern looks to me like a solution to the 'problem' of Dependency Injection based IOC, namely that all an object's dependencies are explicitly named. But wait a minute, IOC was a solution to the problem of having objects whose dependencies weren't clear in the first place.

Dependency injection bothers me because it encourages an object to have too much control. To shamelessly steal Liz's example code:

new GameFactory(UserPreference preference, GuiComponentFactory factory, Scorer scorer, RulesEngine rulesEngine, Timer timer)

The reason GameFactory needs all that stuff is because it is presumably going to pass it down to the Game objects it creates. That is fine, and 5 parameters in a constructor isn't setting off any code-smell alarms for me. I wouldn't do it that way however. For a start, I question the need for a factory. Presumably somewhere there is a UI showing a list of possible games waiting for the player to choose one. I see no benefit in having an abstract factory when what I want to do in response to a user clicking 'Tetris' is a new TetrisGame(). The indirection of the factory is just getting in the way.

I could see how you might want a more configurable list of games, in which case possibly a GameCollection containing a TetrisFactory, a PacmanFactory etc. might work, if the game objects were too heavyweight to simply pre-instantiate at startup.

That's not really where I want to go with this post though. The thing that really caught my eye was the Timer parameter. I'm being a bit mean picking on this one as its easy target, and design is subjective, but it demonstrates one of my concerns with IOC quite nicely. Clearly a Game object requires some notion of the passage of time, as many games are based on things happening periodically. In the Tetris example, it has to move a block down the screen and check to see if it's landed on the pile. However, injecting a Timer is not what I would do. What the game object really wants is for something else to tell it when time has passed. Something external. The code might look like this:

public abstract class Game implements TimeDependent {
}

public interface TimeDependent {
void clockTick(long millisSinceLastTick);
// or possibly, for more OO flexibility
void clockTick(TimeInstant aFrozenMomentInTime);
}

This style satisfies all the requirements of testability, with the added simplification of removing one of the dependencies from the constructor.

You could do the same with Scorer. The game could expose a public TetrisScore basicScore() method, that a collaborator can call, and do its own post-processing on before showing it to the user.

UserPreferences is tougher. I'd agree that the game wants to ask a number of questions of the preferences object, so it should probably be given it.

To conclude, we build object-oriented systems. Its ok for an object to need help from collaborating objects, without having to own them all, or even know who is helping it.

The XP definition of 3rd party code

Continuing along the train of thought from my previous post, I came up with this rather extreme definition of 3rd party code:

3rd party code is any code on a different release cycle to the system under development.

This definition covers everything from 3rd party binaries, code developed by other in-house teams, the operating system, and your database schema.

Third party code considered harmful

Most systems are not built from scratch. Most will use third party libraries, either commercial products or open source utilities.

A good example of this in the Java world is log4J - many projects use it for their logging requirements, and its a good tool. However what most projects will do is use it directly, which means that virtually every class in the system will have a dependency on log4J. If a need arises that log4J can't handle, or a new version is released that changes some behaviour your project depends on, it can be a huge job to go through all your code making changes.

A useful approach is to wrap all access to 3rd party code yourself, thus giving you a single point of contact between your system's code and the external library. This wrapper is also a useful place to put any extension functionality that your system needs.

April 04, 2005

Yaks shaved today: 2

A question about the origins of the phrase Yak shaving has led me to discover the new online magazine from O'Reilly. Among other things in the 1st edition, it contains this article about how to build your own railgun, also known as a gauss rifle. Sweet.

Webtrends

Seeing lots of signs that dotcom bubble 2.0 might be on the way. Lots of people putting together ruby on rails based sites that all seem to be dedicated to finding new ways of helping people publicise things we used to write in private diaries.

Me. I'm going straight to the front of the curve, stepping right past ruby on rails, to seaside on smalltalk.

April 01, 2005

Registry Rant

The Windows Registry.

Lets make a giant file that every application dumps all its data into!
Lets make the operating system use it as well so a misbehaving application can wreck your whole system!
Lets key everything with a GUID so nobody has a damn clue what anything is!
And lets categorize it so that every application has to sprinkle its data into 10 different places!

Windows Registry, I want the last 3 hours of my life back.