Skip to content

Comments ​

Comments are rare. A comment states one technical fact in plain language. The comments skill is the full version, and it applies to PHP, TypeScript and Vue.

  • Explain why, never what. Skip a comment that repeats the next line.
  • Comment a non obvious decision, an ordering constraint, a workaround or a dense expression such as a regex.
  • In AST code, name the PHP syntax a PhpParser node represents. Say why a fast path, such as reflection, runs before a slow path, such as the AST.
  • Do not mention tickets, issue links or the request that led to the code.
  • Do not compare with earlier code. State only the current fact.
  • Do not leave TODO notes.
  • Use simple language. No metaphors and no idioms.
  • Do not use a semicolon or a colon in a comment. A colon inside a URL is fine. Split the idea into two sentences instead.
  • An inline comment is one line or three lines. A one line comment has up to 74 characters.
  • In a three line comment, each line is slightly shorter than the one above, at about 74, 71 and 69 characters. Such a comment may break between any two words.
  • A PHPDoc block states the contract, which means parameters, return value and exceptions. It does not describe the steps. Put steps inline next to the code.
  • In TypeScript and Vue, use // inline and /** */ for exported functions and types.
  • Do not leave notes for a tool or a reviewer in the code. Every comment must be about the code.