Posted on March - 08 - 2010
Naming Conventions and Design Patterns
Overall:
1. All the variable names are in camel notation (aName, totalAmount).
2. All the attribute names are in camel notation. That goes for forms, entity atrribute names, entity names. Say you have a entity called ‘person’ and it has some attributes, then we choose the attribute names this way – name, dateOfBirth, currentAddress. If we need a table for a relation between a person and a terrorist, we can name the relation like ‘personTerrorist‘ or ‘terroristPerson‘
3. Classes and Functions are in dot net notation (GetResults(), Client, Order, Print())
4. Everything must be built with OOP structure. Except for some occasional PHP works. When making a module for a already built system in PHP, then it must be made in OOP. There are no global variables/constants in OOP world. If you need those, you can make a abstract class with static members that meets the requirement. Exception is for very high performance software for which actually all the rules can be broken :p
5. All the classe names must have a prefix which is decided per project. Like if we are making a Game called Alex’s Treasure, we would choose a prefix ‘Alex’ before starting the project. So if we need a class called ‘Island’, we will have to use the name ‘AlexIsland‘ as the class name.
5. All the static and global variables are in capital letters with words separated by underscore. like ROOT_DIRECTORY, OBJECTS_CREATED
6. All the constants are written like no.5 with two underscores added to the ends. like _PI_, _MAX_LENGTH_
7. All the functions are actions. So name should sound like ‘do something’ or ‘something happened’. Order of the words cannot be different from how it should be told. Like you are working on some operations related to customers and banks. These names are ugly
CustomerBank(), CustomerAddress(), CustomerStatus(), CustomersMostImportant(),
problems with those names are
- they doesn’t sound like having an action
- the words’ order is not the way you say
- the seem to stick the customer at the beginning of the name!
So we replace them with this : GetCustomerBanksDetails(), GetCustomerAddress(), GetCustomerStatus(), GetMostImportantCustomers()
Database related:
1. Entity names must be in singular number. So ‘employees’ is not a valid entity name, ‘employee’ is the correct one.
2. Relation table names also in singular number.
3. after executing every query, you must at first check the error. In mysql and PHP, use ‘mysql_error()’ function. Don’t rely on other avaiable functions to determine the errors.
4. I don’t know how mysql_insert_id() handles race conditions. So, if you don’t know the internal code architecture of mysql, never use it without table locking (even if mysql developers use it without table locking). You need to lock all the tables that you use in a script for mysql if you need to lock at least 1 table. That’s a mysql weakness only.
PHP related:
1. Turn on all the error, notices, warnings from php.ini file for development and testing. You must eleminate every single notice/warning. (that relates to the logical errors)
2. Don’t rely on empty() function of php. search google for ‘why’. You must read very very carefully php’s function definitions and experiment with them. What you assume may not be what it actually is.
3. Do you know abour magic quotes?
Goals of naming convention:
1. Readability,
2. Manageability,
3. Reusability,
4. Perfect Prediction









































