The Need to write Clean and Maintainable Code

Building software nowadays getting more and more difficult. Developers has to keep up with the always changing frameworks and technologies. We always feel that, "Can I keep up with these changes and stay competitive?" There is plethora of tools and frameworks to choose from to solve a problem, and still there are very few or none to solve the biggest issue, the issue of writing a good code which is flexible and easy to maintain. Every developer, while executing a project has to go through various stages. Before writing any code, He has to gather and understand all the requirements, he has to choose required tools and framework, he need to make sure that he meets the deadline and after doing all this, there is Maintenance. If deadlines are strict developers tends write code in a hurry which just works. Such kind of approach results in a code which after some time becomes hard to understand, hard to maintain and can take more time and energy to add simple feature to the software. In such situations even adding or extending the code can break some other part of the software. Another major problem with this approach is, new developers who are on boarded, find it very difficult to work with such codebase and if the new developers are not skilled it will be a giant mess. After all this Management decides to clear the mess (which is very difficult now) by hiring skilled developers, but the skilled developers can’t do anything but to duct tape. It’s a common story for many projects.

                          Reference  : Clean Code: A Handbook of Agile Software Craftsmanship

Writing perfect code is a myth. The good code is the code which evolves over the time with the understanding of the domain. Adding features to such kind of code is easy. If the code is self-explanatory and can be read as a textbook paragraph, then there is no overhead of documenting the code. Anyone can read this and understand it without any extra efforts. There are many principles like SOLID, YAGNI (You aren't gonna need it), DRY (Don't repeat yourself) etc., which help developers to write a good code which is highly scalable and easy to maintain. In my opinion this is a pragmatic approach a developer should follow. Before starting the project the team should set basic rules like what and how the naming convention is going to be, how many lines of code a class or a method should have etc.
Whenever required a developer should refactor the code. The code evolves over time, and it’s quite common that a code written with one context in a mind has to be refactored while in the other. You might follow all the principles and patterns and yet sometimes you may still feel that you have done it all wrong. In such situation refactoring the code is the best approach.
Writing a good and maintainable code is an Art, a craftsmanship. There are many resources covering this topic, below are some which I really find helpful to develop these skills.
1)      Clean Code: A Handbook of Agile Software Craftsmanship by Robert c. Martin
2)      Code Complete: A Practical Handbook of Software Construction by Steve McConnell
3)      The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt
4)      Refactoring: Improving the Design of Existing Code by Martin Fowler

Comments

Post a Comment

Popular posts from this blog

Threading in .Net – Part I – The Basics.

Writing High Quality Functions