Forget the complicated stuff, learn the basics first!

Author: Steven Neiland

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

I will be the first to hold my hands up and admit that I don't know everything about well anything. This includes web development. Frankly nobody can know it all especially on a subject that changes as quickly as technology.

One thing I do know though is how much I don't know (which is a lot). Unfortunately when I look at code written by many so called senior developers it seems that I am in the minority. Time and again I have come across code that does recursion, uses orm, websockets or some other advanced technology. Yet when I dig into it I find that variables are incorrectly scoped, built-in application functions are reinvented, too much data is being pulled etc. etc.

And don't get me started on some of the atrocities I have seen inside different databases. In fact lets start there.

Get the Database Right First

I like to think I know a few things about databases. Not everything mind, but enough to be dangerous. So when I see queries pulling 10,000's of records to display 25, recursive queries that build an entire tree to display a single leaf, cursors out the yingyang...well it make me sad.

If you want to work with a database please at least learn about the following:

  1. What a primary key is (Use them no excuses)
  2. Foreign Keys and relational integrity (It does matter)
  3. Normalization and Joins (Normalize till it hurts, de-normalize till it works)
  4. Indexes (Don't be scared they don't bite if you maintain them)
  5. SQL Injection It's a very bad thing and you want to stop it before it happens.

Databases are a big subject and you can make a career just from writing SQL, but if you study at least these few points you won't completely shoot yourself in the foot.

Fundamentals Matter

It seems obvious. Learn to walk before you try to run. And yet as programmers we often just jump straight to the 100 meter sprint. If you don't believe me, just look at all the terrible javascript code that exists in the wild.

I'll admit it. When it comes to javascript I have been hacking at it for years without any real understanding of it. Now that I am taking the time to learn it I realize just how bad what I have been writing really was.

The same holds true for other languages. I have seen some codebase's written by so called senior developers that are riddled with bugs, show a clear misunderstanding of the language in question and is frankly a mess.

If these developers took the time to stop to learn and really understand what they were writing who knows what they might have created. Instead we end up with horror stories that end up on sites like The Daily WTF. Do you want to write code that features there because I know I don't.

Write Less Do More

So what to do about it. Well if you want to write good code you should first learn that lines of code does not equal productivity. In fact I have often found that the more lines of code someone writes the worse the code often is. Learn to do more with less.

If you are writing functions and components with hundred's/thousands's of lines of code you should stop and reevaluate what you are doing. I promise you, throwing code at a problem until something sticks will only get you so far and in the end will cause even more work.

KISS: Keep It Simple Stupid

In seemingly direct contradiction to my last statement, it is sometimes better to write more code than be too smart for our own good.

You may be gods gift to programming able can hold a million lines of code in your head and churn out a single code file that does everything but whistle dixie...but if it can't be maintained by us mere mortals after you leave then what good is it?

When it comes to creating maintainable code complexity is not your friend. Yes solving a problem with a single line of code is awesome, but if it takes someone with a phd to understand that line does then its not maintainable.

The first step to fixing this problem is simple. Lose the ego. Stop trying to show off how smart you are and making everyone else feel inferior. Instead of trying to do everything at once break it done into smaller pieces of code that a regular maintenance programmer can understand without having to do a MRI of your brain. You might even be surprised that when you do that even more elegant solutions sometimes appear.

Oh and for the love of little puppies COMMENT YOUR BLOODY CODE!!!

Don't Reinvent The Wheel

Finally, it should go without saying that you should not go reinventing the wheel every time you do something. There is a whole world full of really smart people who have probably already done the heavy lifting for you. All you need to do is look for what you need and adapt it.

I could go on a lot more on this subject, but I think I have gotten enough off my chest for one night.

Reader Comments

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing