Skip to content

Instantly share code, notes, and snippets.

@arrested-developer
Last active September 20, 2019 07:49
Show Gist options
  • Save arrested-developer/866d5b6e1713cfd55f0620bdd413a7d1 to your computer and use it in GitHub Desktop.
Save arrested-developer/866d5b6e1713cfd55f0620bdd413a7d1 to your computer and use it in GitHub Desktop.
Code Standards

Code Standards

Working in a team, it is important to agree and stick to code standards. This helps a team in many ways:

  • No disagreement between team members about code style - it's agreed already
  • No need to spend your time thinking about code style - once it's agreed, you can focus on writing the code

Perhaps most importantly though:

  • Once code standards are set, a Git commit shows only what changed in the way the code works and not what changed in the way the code looks

Consider a team of two developers - one insists on using semicolons at the end of each line, while the other believes it's better practice to omit them. Every time one team member works on code that was written by their partner, their auto-formatter will remove all the semicolons, or add all the semicolons to every line of code in the file meaning that every time one of them git commits their work, the commit looks as if every line of code in the file has changed

Autoformatting

Install prettier extension for your code editor and set up auto-format on save. Try auto-formatting your code from this week.

  • Does it change? How?
  • What do you like about using this?
  • Is there anything you dislike?
  • How do you choose your own settings for Prettier?

Style guides

Take a look at some existing style guides to see what conventions are commonly used.

Our code standards

We need to agree as a group what our code standards / style will be. If possible, involve your Beamery buddies in the conversation so you can get a sense of what is the commonly agreed style at Beamery. The W3 Schools page on JS standards has a lot of useful info.

  • ES6 function definitions const myFunc = () => {} - when should you use them? Always? Or in certain cases?
  • Semicolons or no semicolons?
  • Line indent - tabs? spaces? how many?
  • == / != allowed? or not allowed?
  • var - allowed? not allowed?
  • Naming conventions - camelCase? kebab-case? Where might you use them?

Come up with a list as a group of 10 or so rules that we will stick to in our code this week. Make sure all the code in your project meets these rules by the end of today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment