Make your code easy to read. Trust me, it’ll help you and everyone else that has to work with your code later. Try to avoid excess layers in your code, and make your variables, functions and classes all have reasonable names.
Point in case: don’t have every single page in your site be based on the index.php page. Just because you can abstract out the views and then include them later doesn’t mean you should. Go ahead, have an about.php page, a contact.php page, a download.php page. The next programmer that comes along will appreciate it.
Programmers and DBAs (or just those that like to work with databases) have a tendency to go a little overboard on normalization. It’s OK if you copy/paste a function here or there or have the same variable declared in a couple different spots – if it makes your code easier to read, easier to debug, and simpler for anyone else to handle, then it’s good code.
Avoid hidden functions and features. Don’t hide a function inside of a header file if it’s being used in your model code. I don’t want to have to do a grep to try to figure out where something lives. If you have a bunch of functions that live by themselves, make a functions.inc.php file. It’ll be easy to find and easy to work with.
Name your files, variables, functions, methods, classes with worthwhile and meaningful names. Don’t go nuts spending hours trying to come up with the perfect name for things, but simple things like resetting a password could be called $userObj->sendPasswordReset(); instead of $u->pr(); or $user->sendpasswordresetnowviaemail().
Try to include some kind of a “common” file in your system. It will help you and other programmers figure out where key things live, like functions files, class files, and any database connections or custom settings. Then make sure that common file is included from all other pages that are executed. Makes live easy.
Just remember when writing code: if I had to tell another programmer what I did and why, would I look foolish?
Michael Berding March 29th, 2013
Posted In: Syntax