Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.
25% off Hosting at HostGator.com:
Use Code techbits25



Some tips for quicker programming

Last updated: 06/17/2009

I've been programming for about 20 years now, going back to my days using basic on my commodore 64. 

Here are a few tips I use regularly to speed up coding and debugging of my applications.  I usually use php / perl in a web environment, but these apply to wide range of programming languages.

  1. Code in small chunks - When I was in college, some Comp Sci. majors would write their programs using what we called the "Big Bang" approach.  They would code the whole thing (maybe a few hundred lines), then try compiling / running it.  Then they spent the next few days poring over pages of errors, trying to figure out why it didn't work.  The method I use is to write a few lines of code, save it, run it, and test the results.  I make sure variables contain what I expect, test functions, etc. This results in an application that works from the start, and as I add functionality, I continually test each piece - the minute something breaks I know it's got to be with the last few lines of code I added. 
  2. Print often - I use lots of print statements to show what values each variable has, and what conditions are being triggered.  This assists with step 1 above, in knowing exactly what is going on with your application as you code it.
  3. Save your work often - I'm in the habit of hitting save (:w for vi users) on a regular basis (every few minutes for sure).  Especially when working remotely via ssh, or rdp, you can never be sure when a connection might lock up on you, or a server crash.  This means you'll never lose very much code if something should happen.
  4. Use appropriate comments and variable names - Ideally, you should comment often, but let's face it, nobody does.  You *should* comment things that are not obvious.  When you revisit the code 6 months later, you'll be glad you did.  Also, use well named variables so they will make sense to anyone reading the code.  Only use $x or $i for junk incrementers or looping variables.  Usually, I find the variable names much more helpful than comments for figuring out what's going on.
  5. Be a code surgeon - when debugging a live application, or adding a new feature, spend time figuring out what the code is doing, and exactly where you should put your changes / bug fixes.  If you start coding too quickly, you'll usually put too much code in and make a mess of things.  Make surgical changes, and only touch what you need. 

I hope you find these useful.  I try to follow these guidelines every day!

 

blog comments powered by Disqus
Have your own Tech-bit to contribute? Submit it here

Other questions in this category:
Getting started in e-commerce
Fighting Spam on your website
Search Engine Optimization Tips
Mirroring your website with wget
How to Migrate your website to a new hosting provider.
How much will I pay in merchant fees for taking credit cards?



Powered by KnowledgebasePublisher 1.1
Host Gator
Content provided by Roberts WebForge, Inc.