Sunday, October 09, 2005

Coding Style

coding style is an important factor in producing an efficient code that can be reused or modified eaisly.

I will review here basic hints in coding styles:
  1. naming variables: best way to name a variable is to choose first an abreviation for it based on its type like "str" for "String" and "num" for "Numebers", then add a descriptive name for the variable ex: if you are declaring a variable for the Monthly Income its name may be like "numMonthlyIncome", take care that to make the variable readable Start every descriptve word in it with a capital letter and the varaiable abbreviation must be in small letters.

  2. naming Functions: try to name Functions so that describe their operation and target and avoid ambigous names, and concentrate on choosing a name that describes the output not the input since the input will be described in the parameteres declaration in the function ex: int GetAverageIncome(string strEmployeeName).

  3. Return Codes: it is a coding style where all the functions in the code always returns an integer value describing the status of the result or any other related message like errors that may occure or confirmation messages or you can combine between the return value of a function and its return codes like in the example of the previous function declaration, we know that an average value of an income must be always a postive value so we can return negative values describing error messages like -1 for "That employee does not exist in the database" and so on.

No comments: