If your are a programmer, then I guess you know, there had been some debate over “What’s the clean code mean?” or simply “How to write clean codes?”. What I have learned from my experience (not just from work, but doing independent programming: that means programming for college project to some free-lancing) and reading, coding is not just about writing big – big lines of code, fill them with algorithms and jargons. Developing software means life time maintainability and support. The life of a software depends upon how it was develop? How maintainable it is? Software isn’t one time created product to be forgotten.
Now question arises “What clean code has to do with software life?”. It has many thing to do.
Many view “clean coding” as they want to perceive the meaning. It goes as there is saying “The beauty is in the eye of the beholder.” So the meaning and in the manner the clean coding is understood, entirely depends upon the person to person. Personally I believe, there is a common ground where at some point, some programmers always agree. This agreement comes, if the two different programmers are of same levels. The level is just term to refer the experience of person.
I was struck with lighting bolt(not actually) when in a particular forum, I had to discuss about “What’s clean coding is?” for long. Everyone expressed there views, from beginners to experts. It was tense discussion for me as I was lil shy about such activity. But everyone silently agreed to a point, there are many things that contribute to clean code. It’s not just about efficiency or beautifully written code.
//code to be added
Look, at the code above and think which code listing is cleaner? I would say example 1 is better. It may look more complex but it is more efficient, as avoidable use of conditions have been removed. Example 2 might be the choice for beginners (that’s what I did as beginner), as it is easier to understand each line. Conditions are break down into simplest and tiniest part. But hey, do you really believe it is better. It is what many experience programmer would call cluttered and waste of time.
Why dirty code?
“Why we get dirty code?” that’s a million dollars question with various answers. Or the question can be “How?”. Let us divide the reasons and try to explore it briefly.
Training! Training!! and again Training!!!
You may have learned coding from college or school, chances are you really don’t learn how to write clean code. I did it from college and I never learn how to write clean codes! Part of this is time pressure on the educational institution. There is only so much that can be taught in a period of time, and coding style, readability, and other things that typically contribute to clean code get dropped from the instruction process, just as process gets dropped when the deadline approaches on a project.
If you look at the syllabi from programming courses at various educational institutions, you will find several that list programming style as one of the course topics or goals. For most that I’ve looked at more deeply, however, it seems that instructors seldom follow through on this goal. Assignments and grading criteria don’t mention any penalty or reward for clear, readable, well-written code. Commercial offerings of programming courses are even worse than the academic ones. They usually have less time for the course and are focused on giving you the bare essentials to enable you to go back to your office and start being productive in the language du jour.
The author hopes to continue the subject matter in future with more deep assesment and analysis.