Posts Tagged ‘best programming practices #1’

Best Programming Practices #1 – multiple files

Tuesday, December 29th, 2009

When I first started out as a programmer, I didn’t have much of a concept of best programming practices. If anything, I saw them as barriers in the way of doing what I really wanted to do. And although there are plenty of people on the web willing to yell at you when you don’t follow good programming practices, there aren’t so many good explanations for beginners on what makes those practices good. So this is the start of a series of quick tips on good programming practices and what makes them good.

Tip #1: Divide your program up into multiple files.

This used to drive me crazy when I first started as a programmer. I would go in to work on a program and find five hundred separate little files, which would force me to hunt laboriously through them in order to find what I wanted. I disliked this practice so much, I would often rewrite other people’s programs to put all the little files into one big one. But guess what? There were good reasons behind it all:

  • Debugging:  If something goes wrong with your program –and it will– it’s much easier to disable one included file at a time then to search through a single massive program.
  • Reusability: Some portions of your code will be used over and over again, either within the same program or in a wholly separate project.  Save that code as a separate file, and you can use it anywhere, no cutting and pasting involved.
  • Structure:  A properly named and organized system of subdirectories can make the organization of your program clear at a glance.

Of course, the key to making this tip work for you is organization.  It isn’t helpful at all to look through five hundred mysteriously named and ordered subroutines.  But if each separate file has a name that clearly identifies what it does, and is placed in a folder with other similar files, it eliminates a lot of the fruitless searching.