Now lets say you believe that messy code is a significant impediment.and also you accept that only way to go faster is to keep your code clean.Then here comes the question you need to ask your self
“How do I write clean code.?” Its no good trying to write clean code if you do not know what it means for code to be clean!
Writing clean code is a lot like painting a picture. Most of us know when a picture is bad by looking at it self. this doesn’t make us to be a good painter or know how to paint. So too being able to recognize clean code from dirty code doesn’t mean that we know how to write a clean code!
Writing clean code requires the disciplined use of extremely great number of little techniques applied through painstakingly “acquired” sense of cleanliness.The “code-sense” is the key.
Some of us are luckily born with it. Some of us have to fight to acquire it.Not only it lets us to see whether a code is good or bad, but also shows us the strategy for applying the
discipline to transform bad code in to clean code.
A Programmer with out “code-sense” can look at a messy code and can recognize the mess but will have no idea what to do about it.But a Programmer with Code-Sense will look at a messy module and see options and variations and can choose the best variation to solve that mess
“Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines
of control.”-Grady Booch,
Have you ever worked on a code that should have taken hours to compete and you took days to complete it. Have you seen what should have been a one-line change but that change impacts many modules and hundred of lines have to be changed to achieve that.
Why do you think that happens ? is this because of bad code? I am sure at first you might of taken care of writing good code and what happened to that good code? what contributed you writing bad code
Many of us might complain its because of change in requirements, or tight schedules to do the things right. But I believe its because of us the developers. developers should take blame for this rotten code, NOT the managers or customers.
its our responsibility to tell our managers that “hey this code is shit, we need to refactor it first before we do any changes to it”, when your manager says finish this at any cost.and believe me most of the time your manager would listen to you, even they are obsessing about the schedule.
to drive this point, consider what if you are a doctor and had a patient who demanded that you stop all the silly hand washing in the preparation of surgery because its taking too much of his time . would you listen to him? since he is the boss!. it would have been unprofessional(rather a crime!) if you would have listened to him.
So too its unprofessional for programmers to bend to the will of Managers who don’t understand the risks of making a mess.
All the developers with more than few years of experience know that bad code slows you down,and yet we choose to make messes in order to meet deadline.
True Professionals do not make a mess of a code in order to meet a deadline. They know that the mess will slow them down eventually and will miss them to miss the deadline. So they know out of their experience that – the only way to go fast – is to keep the code as clean as possible at all times.