Friday, 19 August 2011

Why Write "Good" Code?

As one of the more experienced developers on my team, I find part of my role becomes to promote good coding styles. Anything from separation of concerns, right through to simply breaking down large functions into smaller distinct parts.


Promoting the practices and explaining them is often the easy part, but explaining why is nearly always a challenge. Here are just a few reasons, and common responses that I've come across:


Testability
Put simply, if you've written your code well, your methods perform distinct testable functions, and your concerns are well separated from your UI, to business logic and data access, then your code libraries are well on their way to lending themselves to unit tests. Applications where business logic or even data access is hidden in UI code, or functions stretch to several hundred lines performing many different actions as they go, are virtually impossible to write unit tests for.


The most common response I have seen to this, is that we don't write unit tests. The simple answer to this that we should! And even if we're not now, we may in the future want to build a suite of unit tests to help us maintain the quality and functionality of our deliverables as we introduce change. If we don't code as if we're going to be unit testing, we'll never be able to.


Readability
Code that is laid out well, with short distinct functions, and that follows a consistent set of guidelines (e.g. naming conventions) is more readable. Fact. Applications with good separation of concerns and naming of libraries, are easier to navigate for the developer and make finding the relevant code easier. Single lines of code that perform several functions in one are often a nightmare to understand for other developers looking at your code.


It seems whenever I suggest that someone's code isn't very readable (or, more delicately, that it could be more readable), the response is always "I can read it fine". Well great! But what about the next person that picks up this code and has to figure it out? Readability is to some extent a subjective measure of code quality. Some people will find certain styles easier than others. However certain styles and standards have come to be because the majority find them easier, and find that it saves time when going back over code. Therefore it's a reasonably safe bet that following these standards will mean that the next person to see your code will find it to be readable.


Maintainability
This one's a real stinker. Because no developer ever believes their code will need to change. That belief is almost always wrong though, because requirement change, bugs will need fixing, and things will get refactored. Code libraries with concerns intermingled and with long multi-functional methods are a pig to cut through and change in any way. They just take a lot longer than well separated and laid out code. If I'm fixing a bug in the data layer, I don't want to go anywhere near the UI. Doing so introduces change to an area of the system that doesn't need changing. I want to go to the data layer, find the offending method, fix the bug, then run a unit test that proves the fix worked. The Coding Horror blog once posted that you should:


"Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live"


This, whilst written in jest, is something anyone who's had to maintain poorly written code can relate to. It's a frustrating process and one that will quickly drive you mad!


Pride
The last reason to write good code, is something very simple but sadly overlooked by many. I take pride in the work that I do, both the end results and the quality of the build that went into it. It's been suggested that the end result is all the matters, that the quality of the finished application is enough to be proud of. But a carpenter who builds a table, will take pride in every aspect. Not just the finish, but the joints, fixings, quality of wood, cuts, everything. Not just the parts we can see, but the entire article. They've built the table to the best of their ability, and it's built to last. 


The same is true of building applications. The finished product, whilst a very important part of the puzzle, is still just that, a part. The building blocks, the pieces that make up the finished whole, are just as important. A great application that's poorly written, will be overly costly to maintain. What's the point in building the latest and greatest word processor, if the next version will require a huge and costly development effort to add just a few new features?

For me, I take pride in building quality, functional and maintainable applications that not only fulfil the needs of end users, but also developers working on new features and maintaining the product. Through testable, readable and maintainable code, I know I've done my very best to ensure a quality result all round.

Friday, 31 December 2010

2010: The End is Nigh

So the end of 2010 is upon us. People the world over are preparing to welcome 2011 with cheer and gusto, or if you live in the UK, with a cough and a splutter it seems.

There are many things 2010 could be remembered for - the general election, spending cuts, the commonwealth games, the world cup... ok maybe not the world cup - but for me, what's fresh in my mind at the moment is simply that everyone seems to be celebrating Christmas and the end of the year with cold, flu or sickness of some kind!

Family, friends, colleagues, I can't think of a single household not affected by it in some way. The news may be telling us that the flu cases aren't at the highs we've seen in the past, but I can't say I believe it. Maybe reported cases are - and maybe that's because we've been better at vaccinating 'at risk' groups this year - but most people will just stay at home and stick it out if they're ill. There's nothing your GP can do unless you're dying, so why put yourself through the pain of getting out of bed to go and see them? If we could count up all the unreported cases too, I think we'd see a different picture.

So what does this leave us for 2011 then? Well hopefully not too much more of the same. More cold weather is on the way, which won't help, but eventually the viruses will back off and leave us to make up for lost time. On the plus side I guess we won't all be carrying an extra half a stone from Christmas over-indulgence!

Resolutions for the next year? I'm sure we'll all have a few, some we might even keep. I think my main one is probably to just "go after it". More a change in attitude than anything else, but the last few weeks have felt a bit flat with not a lot going on. That's partly due to the weather (stopping us getting out), but partly down to laziness and not really pushing myself to get on and do the things I want to. Time to put that right and go after the things I want - I'll be 27 soon afterall! :-S

So whatever 2011 has in store for you, I hope it brings all that you hope for and you welcome it in style tonight. Happy New Year!

Thursday, 16 December 2010

Define Yourself?

How do you define yourself? What do you do? What are you?

This evening I sat down and asked myself these very questions. I probably think of myself as a web developer, software consultant, climber and amateur sportsman. But can I be all of these things? What about my other interests? I like to cook, does that make me a chef too?

Many people might say that your job is what defines you and lets face it, what you do for a living becomes a large part of who you are. My job title is "Senior Developer", but what does that mean? In reality, I probably spend about half my time at work "developing" i.e. writing code, while the rest of my time is spent problem solving, communicating within the team, mentoring, managing expectations,  investigating things that go wrong, planning ahead and learning. Does that make me a developer? Well probably, but that only tells half the story doesn't it?

Maybe time for a different approach. Starting with a blank sheet of paper, I wrote down as many skills, qualities and personal attributes for myself as I could think of, doing my best to group things together where possible. I ended up with 4 distinct sections on the page: development, collaboration, consulting and personal. Working with this I could say yes, I am a developer, but I could also be a technical consultant, facilitator, team player or any number of different things! The page defines my skill set, but does it define me? Not really.

So how do you define yourself? Maybe I'm simply a nice guy, who's passionate about what I do and likes to be challenged to better myself. Maybe it's as simple as that. That'll do for now I suppose, until tomorrow... then maybe I'll be a developer for a bit.

Wednesday, 22 September 2010

Football

Is it just me, or is anyone else really not bothered this season? Too much money, cheating, arrogance and playing the media going on, and you can't watch a game without forking out for sky anyway.

To be honest, there are far more important things I'd rather be doing with my time and hard earned cash.

Monday, 2 August 2010

Racketlon

Table Tennis, Badminton, Squash and Tennis all in one tournament: http://www.englishracketlon.org/

I had a go at the Broxtowe racketlon tournament at the weekend... great fun! I lost in the first round (poor shows in Table Tennis and Tennis put paid to any chances of progressing), but went on to win the Plate (losers) tournament after that.

The only downside for the day really, was that it was a bit long, 5 games in all if you reached a final, and by the last game I was pretty drained.

If you play any kind of racket sport I'd strongly recommend having a go at one of these. Most tournaments are graded, so if you're only any good at one or two of the sports then don't be put off! You never know, you might surprise yourself :)

Monday, 26 July 2010

What a Weekend

After a day in Swindon on Saturday visiting my Mum and trying to help out with what I can, Sunday was time for a return to climbing.

A day at Curbar:

Cioch Wall (S 4a) - Lead
Wall End (VS 4c) - Second
Heather Wall (VS 4c) - Second
Mastiff Wall (VS 4c) - Lead
Gladiator Buttress (VS 4c) - Lead
Sorrell's Sorrow (HVS 5a) - 10 minutes of faffing around on the initial "fist jams" (arm bars) before backing off in pain to let Ali second the route instead

Today I'm in pain pretty much everywhere. Got a squash match tomorrow night, hope I've recovered a bit before then!

Wednesday, 16 June 2010

Growing My Own

It's an oddly satisfying feeling to know that the food you're eating came from your own garden. I imagine if the ingredient in question was even slightly more substantial than a few herb leaves then the feeling of satisfaction would be even greater.

Right now we've got Basil and Mint in the kitchen window, then Sage, Parsley and Thyme outside. Hoping to expand these with some Rosemary and Oregano soon too.

When we come to buy a house, there'll have to be space to grow some actual vegetables in the garden. Aside from the obvious satisfaction and sense of achievement in growing our own potatoes, we'll keep ourselves busy planting and harvesting, and save literally pence per week in the process.

Rock on, can't wait! ;-)