The Principles of Good Programming Part-1

Having understanding of programming principles always help us to write clean,functional and maintainable code. Below are some basic programming principles-

  • KISS –  KISS means Keep it simple and Stupid, That mean instead of making or writing complex code always we should keep it as simple as possible. Less code and simple code always has bugs and easier to modify. Always write your code as simple as it can be understand by any programmer in your team.

 

  • YAGNI – Do not be so much future orientated that mean “You are not gonna need it”. YAGNI stands for “Your are not going to need it”- do not implement something until it is necessary.

 

  • Separation of Concerns – Separation of Concerns is design principle for separating  the code into separate module or sections , each section/module can be called as separation concern. For example presentation layer logic need to keep separate from business logic. Change in any module should not directly impact the functionality of another module. Separation of concerns provide maintainability and easy Unit testing .

 

  • Keep Things DRY – Don’t repeat yourself ; Each signification piece of functionality in a programming should be implemented in just one place in the source .In simple do not duplicate your code or piece of logic in your code. Any reusable logic should be written in common place and need to be reuse instead of repeating again and again.

  • Code for The Maintainer – If we talk about SDLC life cycle ,Project maintenance is expensive phase of SDLC. Keeping this thing in mind our code should be written in such way that it should not become nightmare for project maintainer. Always write code to make everyone’s life easy who so ever deal with your code. Your code should be mode readable and understandable so that any one in your team can maintain your code if required. Do not show how much complex code your can write always thing about maintenance and extension of your code.

 

  • Avoid Premature Optimization – A famous quote by Donald Knuth :”Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.”  Understanding what is and isn’t premature is very much important.

 

  • Do The Simplest Things That Could Possibly Work- Again keep your code simple and always write simplest code or logic which possibly work instead of writing complex and tricky code.

  • Boy-Scout Rule – Personally I like this coding principle It says that we should always leave the code cleaner that we found it. Whenever we changes in the existing code the code quality tends to degrade. Always we should keep code quality in mind and always finish technical debt in every code commit. Whenever You find anything wrong or any dirty code in your code base always try to clean that mess before your commit your piece of work. That’s who one day your whole source code become clean else it would be rotten code.

 

Always keep in mind Your code is your Signature,Your code says about your way of thinking and mimic your problem solving capability. Programming design principles are always there to help us but we have to know it firstly and do implement it.

 

Happy Learning 🙂

 

 

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *