Skip to content

Instantly share code, notes, and snippets.

@soletan
Last active June 5, 2019 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soletan/2cdc9ef87961ba130a7e6620a22b6349 to your computer and use it in GitHub Desktop.
Save soletan/2cdc9ef87961ba130a7e6620a22b6349 to your computer and use it in GitHub Desktop.
On Cepharum Coding Style Guide

Javascript

When developing Javascript code you are advised to use our ESLint configuration to implement most parts of our coding style.

Why not using Standard JS?

Standard JS is an eligible coding style for most users. Nonetheless we consider Standard JS to include some oddities we basically dislike.

For example, we guess using single quotes for strings is due to making life easier for people with QWERTY layout by saving use of Shift-key. Javascript doesn't care whether using single or double quotes. Thus, from a Javascript developer's point of view this decision comes without little bias and that's why we guess the keyboard/convenience factor was used to decide on this one. However, this benefits doesn't apply to users working with different keyboard layouts. And most other languages care a lot about the used quotes. This is even true in the family of C-like languages Javascript belongs to. In C/C++ double quotes are required to wrap multi-character string literals. In PHP double quotes are required to have working escape sequences. In order to make the code more readable for those cross-language developers we rather stick with double quotes. From our point of view this won't even hamper with writing XML or HTML code, as well, since writing either code in Javascript is bad practice as of today. Nowadays there is a framework separating code from presentation such as Vue or Angular and even in browser using DOM API is preferred over pasting HTML code as innerHTML of some element. JSON relies on double quotes, but embedding JSON as a string in Javascript is pretty odd as well.

Another significant difference between Standard JS and our coding style regards use of semicolon. In Standard JS semicolon has to be removed in most cases. This is obviously to save typing, to save bytes of code. But since there might be situations when semicolon is still required and since there are developers that aren't familiar with Javascript odd behaviour of automatically inserting semicolon we assume enforcing semicolon to keep the code readable is more beneficial than saving some bytes.

Since most of us are working with different languages keeping code similar improves our efficiency on continuously switching between languages.

When it comes to bytes we also prefer code to contain more whitespace than Standard JS. This is definitely a matter of personal preference, for sure, but using whitespace helps reading code by providing space and structure.

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