Tips on coding style..
Well his post will be regarding some tips on coding style. I googled about this topic, checked many sites, read many posts, finally made a list on them...
- Meaningful names to variables -- i.e., name them meaningfully so that it corresponds as closely as possible to verbal description of its usage.
- Maintain a labbook from the beginning of a project to the end.
- Code each variable so that it corresponds as closely as possible to a verbal description of the substantive hypothesis the variable will be used to test.
- Errors in code should be corrected where they occur and the code re-run.
- Separate tasks related to data-manipulation vs data-analysis into separate files.
- Each program should perform only one task.
- Do not try to be as clever as possible when coding. Try to write code that is as simple as possible.
- Each section of a program should perform only one task.
- Use a consistent style regarding lower and upper case letters.
- Use variable names that have substantive meaning.
- Use variable names that indicate direction where possible.
- Use appropriate white-space in your programs, and do so in a consistent fashion to make them easy to read.
- Include comments before each block of code describing the purpose of the code.
- Include comments for any line of code if the meaning of the line will not be unambiguous to someone other than yourself.
- Rewrite any code that is not clear.
- Verify that missing data is handled correctly on any recode or creation of a new variable.
- After creating each new variable or recoding any variable, produce frequencies or descriptive statistics of the new variable and examine them to be sure that you achieved what you intended.
- When possible, automate things and avoid placing hard-wired values (those computed `by-hand') in code.