Programming principles

Something smells here… good

In other words – a little bit about development from two perspectives:

  • code smells
  • clean code

To make it be understandable for future generations, your code should fall within second one and you should prevent to have to much of first ones. Today I am going to show you how to make your code more friendly. In one of future posts I will get back with things, that you should beware of.

Clean code. Every developer dreams about meeting it on his career path during dozens of projects, but not every can preserve its sample principles. Let’s list the most important below:

  • DRY – Don’t Repeat Yourself. As a developer you should beware of duplicating code or information within application. In other words: “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system”. Antonym of DRY is WET and it stands for “Write Everything Twice”.
  • KISS – Keep It Simple, Stupid. It should be written so simple, so even mentioned Stupid will understand what this part of code is for. Side note: after several years in huge project even creator of specific part does not remember, what it was about. Following one guy from stackoverflow:
//When I wrote this, only God and I understood what I was doing
//Now, God only knows
  • YAGNI – You Aren’t Gonna Need It. In other words – don’t write unnecessary code. If it will be needed in the future, you will write it then. It happens very often in the early phase of development of product, that concept changes and even if you meant well, you would have to drop a lot of code, because it is never used.
  • SOLID – This one stands for 5 other principles:

At the very end – remember to behave in harmony with “The Boy Scout Rule”, which is not programming principle originally, but helps to maintain teamwork:

“Always leave the campground cleaner than you found it.”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s