CODING 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. Like every serious project, there are guidelines.
  2. "Coding Standards" for serious.
  3. Guidelines
  4. ----------
  5. 0. Before reading any further please observe
  6. PEP 8: Style Guide for Python Code
  7. http://www.python.org/peps/pep-0008.html
  8. In particular this means no lameCaps
  9. 1. When using dirnames, don't expect the dir to end
  10. with a trailing slash, and please use the dirnames
  11. in inaryconfig. Use util.join_path instead of os.path.join
  12. 2. Python indentation is usually 4 spaces.
  13. 3. Follow python philosophy of 'batteries included'
  14. 4. Use exceptions, don't return error codes
  15. 5. Don't make the INARY code have runtime dependencies on
  16. a particular distribution (as much as possible).
  17. 6. Don't assume narrow use cases. Allow for a mediocre
  18. amount of generalization in your code, for pieces that
  19. will be required later.
  20. 7. If you are changing something, check if that change
  21. breaks anything and fix breakage. For instance a
  22. name. Running the tests is not always enough!
  23. 8. A good design ensures separation of concerns. Every module
  24. has a specific documented responsibility. Don't make the
  25. horse clean your windows.
  26. 9. To ensure readability avoid nesting python constructs
  27. more than 3 levels deep. Python is a good language (unlike C),
  28. so you can define inner functions in a convenient way, use
  29. such decomposition techniques to break down your code into
  30. manageable chunks. The worst code you can write is one huge
  31. procedure that goes on for 1000 (or more) lines.
  32. 10. Use a particular abstraction like a class or function only
  33. if it makes sense. Don't just define things because they can
  34. be defined. Define only things that will/may be used.
  35. 11. If you are doing an expensive task like searching through
  36. 10000 text chunks, please use an efficient data structure
  37. and algorithm. We are not MS engineers who know no data
  38. structure beyond doubly linked lists and no algorithm beyond
  39. quicksort.
  40. 12. Resist the temptation to develop kludges and workarounds in
  41. response to pressure. Take your time to solve the problems by
  42. the book. The payoff comes later.
  43. 13. Same thing goes for premature optimizations. Knuth and Dijkstra
  44. are watching over your shoulder. :)
  45. Branches and SVN
  46. ----------------
  47. There are two branches of inary, one is called inary-devel and
  48. new features that are large enough to cause instability go
  49. into that branch. The trunk version is supposed to be stable at
  50. all times. This means that you *must* run unit tests and other
  51. test scripts after committing any change that cannot be tested
  52. in isolation. Run the unit tests periodically to catch unseen
  53. bugs. A release from the stable branch *must not* break any tests
  54. whatsoever, so extensive use of the test suite must precede any
  55. release.
  56. Unit testing
  57. ------------
  58. Unit tests are located in unittests directory. Running the tests is
  59. trivial. But you must synchronize your code and data with the test
  60. code, which can be a tedious work if you lose discipline.
  61. Sample data files are located in the same directory with test modules.
  62. For running the entire test suite, use the following command:
  63. $ ./tests/run.py
  64. The following command will run tests in specfiletests and archivetests
  65. in unittests dir:
  66. $ ./tests/run.py specfile archive
  67. Do not depend on the output of unittests. Instead of producing an
  68. output message/data in your tests, check the data internally. By
  69. definition, unittest should just report succeeding and failing cases.
  70. If you didn't, take a look at the links below for having an idea of
  71. unit testing.
  72. http://www.extremeprogramming.org/rules/unittests.html
  73. http://www.extremeprogramming.org/rules/unittests2.html
  74. Other tests
  75. -----------
  76. There are a couple of nice test scripts for testing the basic
  77. capabilities of the command line interface such as building and
  78. upgrading. Unlike unit tests, you have to take a look at the output
  79. to understand that the scripts are doing well :)
  80. Misc. Suggestions
  81. -----------------
  82. 1. Demeter's Law
  83. In OO programming, try to invoke Demeter's law.
  84. One of the "rules" there is not directly accessing any
  85. objects that are further than, 2/3 refs, away. So the
  86. following code is OK.
  87. destroy_system(a.system().name())
  88. but the following isn't as robust
  89. destroy_system(object_store.root().a.system.name())
  90. As you can tell, this introduces too many implementation
  91. dependencies. The rule of thumb is that, in these cases
  92. this statement must have been elsewhere.... It may be a
  93. good idea to not count the object scope in this case,
  94. so in Python self.a means only one level of reference,
  95. not two.
  96. One quibble with this: it may be preferable not to insist
  97. on this where it would be inefficient. So if everything
  98. is neatly packed into one object contained in another
  99. object, why replicate everything in the upper level? If
  100. the semantics prevents dependency changes, then chains
  101. of 3 or even 4 could be acceptable.
  102. OTOH, in Python and C++, it's not always good to implement
  103. accessor/modifier pairs for every property of an object.
  104. It would be much simpler if you are not doing any special
  105. processing on the property (e.g. if what the type system
  106. does is sufficient).
  107. The main rule of thumb in Demeter's Law is avoiding
  108. putting more than, say, 10 methods in a class. That works
  109. really well in practice, forcing refactoring every now
  110. and then.
  111. 2. We all know, you're using LISP but didn't want to tell
  112. us. Don't be scared, as a success story and for your encouragment
  113. there are tens of people somewhere with LISP releated jobs.
  114. 3. If you are studying Data structures and Algorithms, and if
  115. your first assignment is to implement a basic FIFO queue,
  116. don't implement it. Just show your teacher the syntax of LISP,
  117. tell him how beautiful it is, and show how an autistic person
  118. can count lots of parenthesis with a "one second" look, you'll
  119. probably get A+.
  120. 4. If you are interested in "Playstation 2 Linux Games Programming"
  121. or "How to extend C programs with Guile", please don't exercise
  122. your valuable skills in this project.
  123. !!!PLEASE BEFORE FIRST INSTALLING START INARY-SYSTEM TEST!!!