Home / E_LEARNING / COMPUTER PROGRAMMING II

COMPUTER PROGRAMMING II

PRINCIPLE OF GOOD PROGRAMMING

  • Keep it simple – Simplicity (and avoiding complexity) should always be a key goal.
  • Do the simplest thing that could possibly work – A good question to ask one’s self

when programming is “What is the simplest thing that could possibly work?” This helps

towards simplicity in the design.

  • Easy to read and understand:- The code should be easy to read and understood with a

minimum of effort required. If code requires too much thinking from an observer to

understand, then it can probably stand to be simplified.

  • Abstraction Principle – “Each significant piece of functionality in a program should be

implemented in just one place in the source code.”

  • Avoid Creating what you don’t need – You should try not to add functionality until you

need it.

  • Open/Closed Principle – Software entities (classes, modules, functions, etc.) should be

open for extension, but closed for modification. In other words, don’t write classes that

people can modify, write classes that people can extend.

  • Write Code for the Maintainer – Almost any code that is worth writing is worth

maintaining in the future, either by you or by someone else. The future you who has to

maintain code often remembers as much of the code, as a complete stranger, so you

might as well always write for someone else.

A memorable way to remember this is “Always code as if the person who ends up

maintaining your code is a violent psychopath who knows where you live.”

  • Principle of least astonishment – The principle of least astonishment is usually referenced in regards to the user interface, but the same principle applies to written code.

Code should surprise the reader as little as possible. This means following standard conventions, code should do what the comments and name suggest, and potentiallysurprising side effects should be avoided as much as possible.

  • Single Responsibility Principle – A component of code (e.g. class or function) should

perform a single well defined task.

  • Minimize Coupling – Any section of code (code block, function, class, etc) should

minimize the dependencies on other areas of code. This is achieved by using shared variables as little as possible. “Low coupling is often a sign of a well-structured computer system and a good design, and when combined with high cohesion, supports the general

goals of high readability and maintainability”.

  • Maximize Cohesion – Code that has similar functionality should be found within the same component.
  • Hide Implementation Details – Hiding implementation details allows change to the implementation of a code component while minimally affecting any other modules that use that component.
  • Avoid Premature Optimization – Don’t even think about optimization unless your code is working, but slower than you want. Only then should you start thinking about optimizing, and then only with the aid of empirical data.

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil” Knuth.

  • Code Reuse is Good – Not very pithy, but as good a principle as any other. Reusing code improves code reliability and decrease development time.

About Prince Idowu Oyewumi

FULL NAME : PRINCE MUHAMMED S. OYEWUMI BIO.: Graphics Designer, I.T Expert & Photograaphy Expert Edu Qual. Bsc, Diploma, Nim Follow us Twitter: @mdee_coded Facebook: @https://www.facebook.com/pxclusive/ Instagram: @mdee_Cool Tel.: +2348085570405

Check Also

You Must Know: List Of Schools Whose post utme form are out 2017

Nigerian Universities don’t have any outside agent to help with the 2017/2018 admission exercise. The …

You Must Know: Learn How To Make Cake Easily

Nigerian cake is simple and sweet. There’s not a lot going on in the cake …

Leave a Reply

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