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.






  1. Maintain a labbook from the beginning of a project to the end.
  2. 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.
  3. Errors in code should be corrected where they occur and the code re-run.
  4. Separate tasks related to data-manipulation vs data-analysis into separate files.
  5. Each program should perform only one task.
  6. Do not try to be as clever as possible when coding. Try to write code that is as simple as possible.
  7. Each section of a program should perform only one task.
  8. Use a consistent style regarding lower and upper case letters.
  9. Use variable names that have substantive meaning.
  10. Use variable names that indicate direction where possible.
  11. Use appropriate white-space in your programs, and do so in a consistent fashion to make them easy to read.
  12. Include comments before each block of code describing the purpose of the code.
  13. Include comments for any line of code if the meaning of the line will not be unambiguous to someone other than yourself.
  14. Rewrite any code that is not clear.
  15. Verify that missing data is handled correctly on any recode or creation of a new variable.
  16. 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.
  17. When possible, automate things and avoid placing hard-wired values (those computed `by-hand') in code.

Comments

Popular posts from this blog

Oldest computer???