PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/manual/en-US/coding-standards/chapters/comments.md

http://github.com/joomla/joomla-platform
Markdown | 97 lines | 52 code | 45 blank | 0 comment | 0 complexity | b51d64bed3065095ae4a87e07b12a170 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. ## Comments
  2. This chapter covers inline commenting in more detail. Inline comments are all comments not included in doc blocs. The goal of in line commenting is to explain code in context. Such explanation may take many different forms.
  3. Comments that are written in a readable and narrative style, especially when explaining a complex process, are encouraged. In general they should be placed close to the code explained rather than before the entire block of code.
  4. Comments should be as sentence like as possible, which is to say that they should be complete and readable, not in short hand.
  5. Comments are not a replacement for detailed doc blocks. Comments serve to explain the logic and structure of code itself rather than the use of code.
  6. ## Formatting of Comments
  7. Comment blocks that introduce large sections of code and are more than 2 lines long should use `/* */` (C) style and should use `*` on each line with the same space/tab rules as doc blocks. If you need a large introduction consider whether this block should be separated into a method to reduce complexity and therefore providing a full docblock.
  8. Comments should precede the code they refer to. As a corollary, comments should not be on the same line as the code to which they refer (which puts them after the code they reference). They should be on their own lines.
  9. Dont use a blank line between comments and the code they refer to (no space underneath a comment block).
  10. Always have a single blank line before a comment or block of comments.
  11. Comments should align with the code they refer to, using the same indenting as the line that follows the comment.
  12. Comments should be indented with tabs (like code, not like doc blocks).
  13. ## Content of comments
  14. Comments should use en-GB (See below).
  15. Always have a space between // and the start of comment text.
  16. New lines should always start with an upper case letter unless The line is a continuation of a complete sentence The term is code and is case sensitive.
  17. Code that is included specifically to assure compatibility with other software (for example specific browsers or a specific version of the CMS or for backward compatibility reasons) should be clearly marked as such. If there is the intention to remove specific code at a future point, state that but do not use a deprecation tag or specify a release (this can be hard to predict).
  18. Check spelling and grammar on all comments (see below).
  19. Only end a line with a period if it is a full sentence.
  20. Rather than use docblock tags use See:, Link: and Note: for comments if appropriate.
  21. Do not use HTML in comments unless specifically related to the comment content.
  22. Do not leave commented code unless there is a clearly explained reason for doing so. In such a case, a comment saying "Code intentionally commented" will prevent accidental removal.
  23. Comments may include forward looking statements of how something will be extended or modified in the future, but not todos indicating that code is not complete or ready to use.
  24. Remember that humor and sarcasm are difficult to translate.
  25. ## Acronyms
  26. Capitalise all letters of acronyms such as HTML, XML, SQL, GMT, and UTC. This is an exception to the general use of en-GB rules.
  27. ## Common spelling and grammar errors for which to check.
  28. Joomla contributors include many non-native speakers of en-GB which makes it understandable that there are sometimes spelling and grammar errors. At the same time, some people reading comments also are non native speakers and may even use automated translation to understand comments. This makes it very important that comments should follow proper en-GB spelling and grammar rules. Unfortunately, these can be tricky.
  29. Wikipedia provides a good summary of common differences between en-US and en-GB. http://en.wikipedia.org/wiki/American\_and\_British\_English\_spelling\_differences Note that there are some instances where en-GB common usage (but not actual rules) varies slightly from en-AU and using en-AU is considered acceptable.
  30. ### S vs Z
  31. en-GB most commonly uses `ise` where en-US would use `ize`, such as `normalise` instead of `normalize`. (Note that there are some exceptions to this rule and some differences between en-GB and en-AU in common usage.)
  32. Use of apostrophes is one of the trickier parts of English.
  33. ### Lets versus lets
  34. Lets means permits or allows to:
  35. ```php
  36. // This lets the user enter data
  37. ```
  38. Lets is a contraction for let us and means we are going to do this now:
  39. ```php
  40. // Let's validate the field
  41. ```
  42. ### Its versus its
  43. Its is the possessive form of it:
  44. ```php
  45. // Get its ID
  46. ```
  47. Its is a contraction of it is
  48. ```php
  49. // It's time to save
  50. ```
  51. ### The correct Joomla spelling of some commonly used words.
  52. - Dependant