Research: code standards, style and editors - imkarin/bloktech GitHub Wiki

Code standards

Conventions to maintain code quality.

  • Keep the code clean, self-explanatory, logical and consistent.
  • The code needs to work.
  • Make sure your code well organised and appropriately documented.
  • Pure functions: function that does only 1 thing. This makes it easier to find errors and fix them.

Good coding style allows developers to understand each other's code easily, find and fix errors faster and save time.

Coding style

Variable names

In Javascript, variable names start with a lowercase letter. Variables that consist of multiple words are written in camelcase, and the words are connected (no spaces).

let age = 21
let firstName = 'Max'

Spaces around operators

Always put spaces after operators (+ - * / =) and after commas.

var a = b + c;
let names = ['Max', 'Nick', 'Joe']

Identation

For identation of code blocks and nesting, there are two common practices:

  • Use two spaces
  • Use tab (however, tab might be interpreted differently depending on your code editor)
function square(value) {
  return value * value;
}

Statement rules

It is not uncommon (but heavily discussed) to end simple statements with a semicolon.

const firstName = 'Max';

For complexer statements:

  • Put the opening bracket at the end of the first line.
  • Use one space before the opening bracket.
  • Put the closing bracket on a new line, without leading spaces.
  • Don't end a complex statement with a semicolon.
if (kilos < 20) {
  category = 'lightweight';
}

Objects

  • Use a space before the opening bracket.
  • Use a comma after each property-value pair, except the last one.
  • It's stylistic to start each property-value pair on a new line.
  • Put the closing bracket on a new line, with no leading spaces, followed by a semicolon.
const person = {
  name: 'Max',
  age: 21
};

Short objects can also be written on one line.

Line length

For readability, avoid lines with more than 80 characters.

Sources:

Code editors

VSCode

  • Price: Free
  • Pros: Powerful multilanguage IDE, fast, supports Typescript and IntelliSense, built-in terminal, embedded Git control
  • Cons: Slow launch time, memory hog, code check not powerful
  • Tools that integrate with this editor: GitHub, .NET Core, Microsoft...

Sublime

  • Price: $70, free trial
  • Pros: Lightweight, plugins, super fast
  • Cons: Tough to learn, not beginner-friendly, many plugins doing the same thing, no Git support
  • Tools that integrate with this editor: .NET Core, Grails, WakaTime...

Atom

  • Price: Free
  • Pros: Open Source, hackable, many packages
  • Cons: Slow with big projects, high memory usage, slows down with plugins
  • Tools that integrate with this editor: GitHub, WakaTime, TSLint...

Several alternative text editors are Sublime, cell, Vim, Notepad++, Codeshare.io etc.

For this project, I choose to use the code editor VSCode. This appears to be the most beginner friendly code editor with a decent amount of functionalities and extensions. It also supports GitHub, which is essential during this (partially team)project.

Sources: