Golden Rule

Enforce these, or your own, agreed upon guidelines at all times. Small or large, call out what's incorrect. For additions or contributions to this Code Guide, please open an issue on GitHub. When in doubt or not explicity specified, use existing common patterns.

Part of being a good steward to a successful project is realizing that writing code for yourself is a Bad Idea™. If thousands of people are using your code, then write your code for maximum clarity, not your personal preference of how to get clever within the spec.

- Idan Gazit

General Preferences

Editor preferences

Set your editor to the following settings to avoid common code inconsistencies and dirty diffs:

Tip: Document and apply these preferences to your project's .editorconfig file. For an example, see the one in this repo. Learn more about EditorConfig.

Whitespace

Only one style should exist across the entire source of your code base. Always be consistent in your use of whitespace as it helps improve readability.

Tip: configure your editor to "show invisibles". This will allow you to eliminate end of line whitespace, eliminate unintended blank line whitespace, and avoid polluting commits.

Commenting Code

Commenting code is an important and effective tool for communicating deeper what can't always be said with code. I've found that Sarah Drasner's article on The Art of Comments details the best way to comment code.

Code can describe how, but it cannot explain why.

Consider a few things when writing code and attempting to decide whether or not it deserves some comments:

  1. Future you doesn't always remember why present you decided to write something a particular way. Code styles change, support requirements change, and sometimes what was seemed clear and legible at the time is not always by everyone else.
  2. Not everyone comes from the same backgrounds nor experiences. Don't assume that because you understand it, everyone on the team will. That doesn't make them less smart, but maybe makes your solution a bit more creative. Explain the why so everyone can learn.
  3. Comments allow one to break up code into smaller readable chapters of code. Smaller sections of code provide a developer with easier and more manageable chunks to read through.
  4. Sometimes deadlines come up faster than expected; leaving comments can provide a roadmap for what was done given the divergence from what was intended.
  5. Did you take a snippet from another site? Or did you copy a solution from StackOverlow? No problem. Write a comment to leave a paper trail for others to follow or to credit the source.
  6. If there is an open discussion on GitHub or StackOverflow about the code or approach you're using, include the link in your comment.

Tip: Keep your README.md updated as a project evolves.

Choosing Dependencies

Consider a few things when choosing dependencies: