Well Written Code

If you write any kind of computer “code” (HTML, PHP, JavaScript, C++) then learning to write clean well written code is imperative.   At a conference once, one of the speakers said when you’re finding your coding style, always imagine the next guy looking at the code is a psychopath who knows where you live.   In other words, you don’t want to torque that guy off.

Well written code is not only understandable, but well formatted and documented.   You can not over document your code.   The documentation will help, not just the next person who might need to look at your code, but it will help you if you end up returning to the code years later.    I can’t tell you how many times I’ve returned to something years later, and had to re-educate myself as to how it was done.    Good documentation makes that much much easier.

Good code is also “done right”… it doesn’t just “work” but you understand what it does.  It’s what separates a “hacker” from a “coder”.   When I started working with code, I taught myself by modifying message board software. By looking at the code, with a little knowledge, I was able to figure out what certain parts did and tweak it a bit to alter it to my needs.  This “worked” but wasn’t always the best way.  As I grew in my knowledge and transitioned from hacker to coder, I began to think things out a lot more clearly and write cleaner well thought out code.

Your code should also be extensible… easy for someone (or you) to add a feature or improve upon.  When I’m creating a function to do a certain task, I try to think through possible future needs, so that what I’m building is flexible enough to grow with the needs of the website.

Lastly, use function and variable names that make sense.  Why use $var1 when you could use $totalusers as a variable name.  Properly named functions and variables are almost self documented.  You can look at $totalusers and pretty much guess that would be the number of total users in the system – but you’d have no idea what $var1 is.

>> Joshua Pettit is Lead Developer and Project Manager at Sunrise Marketing.  http://www.sunrise-marketing.com/


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.