If I had more time I would have written less code
Join the DZone community and get the full member experience.Join For Free
in a a blatant rip-off of the t.s eliot quote: “if i had more time, i would have written a shorter letter” i had a thought the other day, perhaps:
if i had more time, i would have written less code
it seems to me the more time time i spend on a problem, the less code i usually end up with; i’ll refactor and usually find a more elegant design – resulting in less code and a better solution. this is at the heart of the programmer’s instinct that good code takes longer to write than crap. but as uncle bob tells us :
the only way to go fast is to go well
how then do we square this contradiction? the way to go fast is to go well; but if i sacrifice quality i can go faster – so i’m able to rush crap out quickly.
what makes us rush?
first off – why do developers try to rush through work? it’s the same old story that i’m sure we’ve all heard a million times:
- there’s an immovable deadline: advertising has already been bought; or some external event – could be y2k or a big sports event
- we need to recognise the revenue for this change in this quarter so we make our numbers
- somebody, somewhere has promised this and doesn’t want to lose face by admitting they were wrong – so the dev team get to bend so those who over committed don’t look foolish
what happens when we rush?
the most common form of rushing is to skip refactoring. the diabolical manager looks at the red, green, refactor cycle and can see a 33% improvement if those pesky developers will just stop their meddlesome refactoring.
of course, it doesn’t take a diabolical manager – developers will sometimes skip refactoring in the name of getting something functional out the door quicker.
it’s ok though, we’ll come back and fix this in phase 2
how many times have we heard this shit? why do we still believe it? seriously, i think my epitaph should be “now working on phase 2″.
another common mistake is to dive straight in to writing code. when you’re growing your software guided by tests , this probably isn’t the end of the world as a good design should emerge. but sometimes 5 minutes thought before you dive in can save you hours of headache later.
and finally, the most egregious rush i’ve ever seen is attempting to start development from “high level requirements”. as the “inconsequential little details” are added in, the requirements look completely different. and all that work spent getting a “head start” is now completely wasted. you now either bin it and do-over, or waste more precious time re-working something you should never have written in the first place.
does rushing work?
this is the heart of the contradiction – it feels like it does. that’s the reason we do it, isn’t it? when compelled by the customer to finish quicker, we rush – we cut corners to try and get things done quicker.
it feels like i’m going quicker when i cut corners. if only it wasn’t for all those unexpected delays that wasted my time then i would have been finished quicker. its not my fault those delays cropped up – i couldn’t have predicted that.
it’s the product manager’s fault for not making the requirements clear
it’s the architect’s fault for not telling me about the new guidelines
its just unlucky that a couple of bugs qa found were really hard to fix
when you cut corners, you pay for it later. time not spent discussing the requirements in detail leads to misunderstandings; if you don’t spot it later on, you might have to wait until the show and tell for the customer to spot it – now you’ve wasted loads of time. time not spent thinking about the design can lead to you going down an architectural blind alley that causes loads of rework. finally time not spent refactoring leaves you with a pile of crap that will be harder to change when you start work on the next story, or even have to make changes for this one. of course, you couldn’t have seen these problems coming – you did your best, these things crop up in software don’t they?
but what if you hadn’t rushed? what if rather than diving in, you’d spent another 15 minutes discussing the requirements in detail with the customer? you might have realised earlier that you had it all wrong and completely misunderstood what she wanted. what if you spent 30 minutes round a whiteboard with a colleague discussing the design? maybe he would have pointed out the flaws in your ideas before you started coding. finally, what if you’d spent a bit more time refactoring? that spaghetti mess you’re going to swear about next week and spend days trying to unravel will still be fresh in your mind and easier to untangle. for the sake of an hour’s work you could save yourself days.
how much is enough?
of course, it’s all very well to say we will not write crap any more; but it’s not a binary distinction, is it? there’s a sliding scale from highly polished only-really-suitable-for-academics perfection; to sheer, unmitigated, what-were-you-thinking-you-brain-dead-fuck crapitude.
if spending more time discussing requirements could save time later, why not spend years going through a detailed requirements gathering exercise? if spending more time thinking before coding could save time later, why not design the whole thing down to the finest detail before any coding is done? finally if refactoring mercilessly will save time, why not spend time refactoring everything to be as simple as possible? actually, wait, this last one probably is a good idea.
professional software development is always a balancing act. it’s a judgement call to know how much time is enough.
how long does it take?
when working through a development task i choose to expend a certain amount extra effort over and above how long it takes me to type in the code and test it; this extra time is spent discussing requirements, arguing about the design, refactoring the code etc etc. ideally i want to expend just enough effort to get the job done as quickly as possible (the lazy and impatient developer). if i expend too little effort i risk being delayed later by unnecessary rework; if i expend too much effort i’ve wasted my time.
however, i don’t know in advance what that optimum amount of effort is – it’s a guess based on experience. but i expect the amount of effort i put in to be within some range of the optimum – the lowest the point on the graph:
all other things being equal, i’d expect the amount of time it actually takes to complete the task to be within some margin based on how close i got to the optimum amount of effort. sometimes i do too little and waste time with rework. other times i spend too long – e.g. too much detail in the design that didn’t add any value – so the extra time i spent is wasted.
this is by no means all the uncertainty in an estimate; but this is the difference between me not doing quite enough and having to pay for it later (refactoring, debugging or plain rework); versus doing just enough at every stage so that no effort is wasted and there’s no rework i could have avoided more cheaply. in reality the time taken is likely to be somewhere in the middle: not to great but not too shabby.
there’s an interesting exercise here to consider the impact experience has on this. when i was first starting out i’d jump straight into coding; my effort range would be to the left of the graph: i’d spend most of my time re-writing what i’d done so the actual time taken would be huge. similarly, as i became more experienced i’d spend ages clarifying requirements, writing detailed designs and refactoring until the code was perfect; now my effort range would be to the right of the graph – i’d expend considerable upfront effort, much of which was unnecessary. now, i’d like to think, i’m a bit more balanced and try to do just enough . i have no idea how you could measure this, though.
reducing effort to save time
what happens when we rush? i think when we try to finish tasks quicker, we cut down on the extra effort – we’re more likely to accept requirements as-is than challenge them; we’re more likely to settle for the first design idea we think of; we’re more likely to leave the code poorly refactored. this pulls the effort range on the graph to the left.
to try and get done more quickly, i’ve reduced the amount of effort by “shooting low”: i cut corners and expend less effort than i would have done otherwise.
the trouble is this doesn’t make the best-case any better – i might still get the amount of effort bang on and spend the minimum amount of time possible on this task. however because i’m shooting low, there’s a danger now i spend far too little extra effort – the result is i spend even longer : i have to revisit requirements late in the day; make sweeping design changes to existing code; or waste time debugging or refactoring poorly written code.
this is a classic symptom of a team rushing through work: simple mistakes are made that, in hindsight, are obvious – but because we skipped discussing requirements or skipped discussing the design we never noticed them.
when i reduce the amount of extra effort i put in, rather than getting things done quicker, rushing may actually increase the time taken. this is the counter-intuitive world we live in – where aggressive deadlines may actually make things go more slowly. perhaps instead i should have called this article:
if i had more time i would have been done quicker
Opinions expressed by DZone contributors are their own.