LinkedList Bonsai-State-Machine through Pointless Refactoring

Yesterday I had to implement a common, simple bit of functionality in a view. The view is revealed and hidden by clicking a tab button which causes it to slide up or down behind a mask.

The view is behind a mask, clicking the button reveals the view

The view is behind a mask, clicking the button reveals the view, clicking again hides it.

It’s not rocket science. The only awkward aspect of the implementation is that it has to be responsive to the user changing their mind mid-move. If I click the tab and then quickly change my mind, the movement should be reversed, and if I click it again it should be reversed again and so on.

This is the kind of behaviour I’ve implemented hundreds of times over the years, and you probably have too. I do it without really thinking about it. Except that these days I’m trying to think more about every line of code I write – inspired by some stuff I read (and now can’t find) where Corey Haines was talking about challenging yourself to answer the “Why stop now?” question when refactoring.

Continue reading »

Post Divider

Multiple Developer-Personality Disorder

In any software project there are at least five stakeholders in the technical development task:

  • The client, who has the vision of the finished features
  • The project manager, who has to organise technical resources and timetables
  • The architect, who designs the system at a macro level
  • The current coder, who implements each individual class and component
  • The future coder, who will maintain and enhance the software in the future
Stray as architect, current coder and future coder

Stray as architect, current coder and future coder

On the projects I work on, there’s some overlap of technical roles. Frequently I am – as a minimum – the architect and the current coder, and I’m likely to be the future coder as well.

One of the benefits of merging these roles is that there’s less conflict between the technical roles than there would be if the architect and current coder were different people. Not having to have meetings to explain things saves some time, and at least if you’re likely to be the future coder you can take some short cuts based on the inside knowledge you have of the code base…

…oh, wouldn’t it be great if that were true?

The consequence of merging the roles may well be a reduction in open conflict and time spent in discussion, but this is not a benefit, it’s a handicap.
Continue reading »

Post Divider

Working with your Complexity-dar

Managing complexity is what we do as programmers, right?

Whether you’re architecting a new application from scratch, or deep into writing a component or class or test method, complexity is the elephant in the room, and our job is to ignore it, or at least keep it in the corner, right?

I mean, complexity in software development is inevitable. Beyond “Hello World”, building and maintaining systems that solve interesting problems is like being in a boat full of holes. Every new thought the client has is another leak and we’re the poor sods standing in the middle with a bucket, scooping up the complexity and flinging it back into the sea as fast as possible, right?

You can tell by now that I’m about to say “think again”, can’t you?

Listen to your complexity-dar

Your brain is an amazing thing. Tiny fluctuations in relative levels of substances such as dopamine alert you to changes in patterns that you’re not even aware of observing. The difference between a great fighter pilot and a terrible freeway driver is partly the level of attunement to those chemical changes. Fighter pilots don’t think they need to take evasive action, they feel it – and they act upon that feeling.

Continue reading »

Post Divider

Why it’s 90% not about ‘less code’

I hear a lot of talk about ‘less code’ being something we should favour.

[Edit - I should qualify that by 'favouring less code' I mean favouring a shorter class file or fewer classes in the code base, not splitting long methods into shorter methods or large classes into single responsibility classes, both of which I'm absolutely sold on.]

I disagree, and out of curiosity I just did a little experiment to see whether my feeling was well founded.

I wrote a ruby script which counts the words in source files. It’s not perfect but it’s good enough for this purpose because if it’s inaccurate it’ll err on the side of over-counting rather than under-counting. It counts = as a word if it’s surrounded by white space for example.

I can touch-type at 80 wpm. Here’s how that expands up if we imagine that I can type constantly, machine like, while I’m coding. (Of course I can’t, but bear with me).

  • 80 x 60 = 4800 words per hour
  • 60 x 8 =  38400 words per day

I just ran my script on the src and test folders of my main project. I’d estimate that this code base has taken me 200 (or more) working days to write. This 200 days excludes project management time, coaching other devs, client meetings etc. This is 200 days of quality time Stray spent with TextMate.*

The results from the script are kind of mind blowing:
Continue reading »

Post Divider

What’s in a name? (Or a package)

Last night, I put a shout out on twitter for some input into something I’ve been wrestling with:

On-screen text content, model or view?

I got some excellent input, learned a lot (you can embed XML direct in a class, pull in a text file at compile time as a ByteArray, and the flex framework ResourceBundle is a gross getInstance() Singleton) from a whole bunch of smart people. Thanks @benbjohnson @davidortinau @johnguenin @nodename @redannick @tjgillis @troygilbert – a good twitter geek network is like a super-seminar-o-matic.

The general consensus was that it belongs in the model package, but it brought to my attention an interesting question that I’d have assumed I had a smart answer to:

What makes a model a model?

Continue reading »

Post Divider