📜 ⬆️ ⬇️

Translation Airbnb Style Guide



We, like everyone else, initially used standards for writing code in the development, but in fact they were limited to something like this:

- In the Camelkeys write?
- Yes, as usual, in the Camekake
… two weeks passed…
- We are in Camelcase agreed !!!

')
In our case, it wasn’t that last phrase.
I have long wanted to systematize this somehow, but I didn’t get around to choosing between styles from jQuery, Google, ideomatic.js and Crockford.

When a month ago, a guide from AirBnB got into the ghithab trending, it immediately caught our eye ...
A week ago we transferred it , primarily for our own needs, but we could not share it with the community.

I strongly advise you to read at least all beginner js developers.


How is it so different from other manuals, and how did it like us so much?
The fact is that it is not so much indicative of how to style the code stylistically, as it tells how to correctly write in JavaScript. This is not only a list of guidelines for JSLint, but a platform to start writing well: this text, which can be thoughtfully read in an hour, gives trainees more insight into JavaScript than their own day of trial and error and questions to older colleagues.

Regarding design, this guide uses “popular” choices.
Examples:
2 spaces tab is used, also in Google, npm, Node.js, Idiomatic
Always use a semicolon like Google, Node.js, Crockford
Declaring Variables with Hanging Commas in One Var, as in Idiomatic, jQuery
What is interesting here is indicated even a similar point:
Declare variables that are not assigned a value at the end. This is useful when you need to set the value of one of these variables based on the values ​​already assigned.

camelCase for variables - like in Google, npm, Node, Idiomatic
At the same time, this guide clearly states:
Use camelCase to name objects, functions, and variables.
Use PascalCase to name class constructors.


Some points are clearly and clearly explained, for example:

Additional comma at the end of objects: None. It can cause problems with IE6 / 7 and IE9 in compatibility mode. In some implementations of ES3, a comma at the end of an array increases its length by 1, which can cause problems. This question has been clarified only in ES5 (original):

Revision ECMAScript 5 unequivocally establishes the fact that the comma at the end of the ArrayInitialiser should not increase the length of the array. This is a non-semantic change from ECMAScript 3 Revision, but some implementations have previously incorrectly resolved this issue.


The mechanisms of the work of “ascent” of declarations of variables and functions within the scope are clearly explained.
Declaring an anonymous function raises the variable itself, but not its value, to the top of the scope.
Named functions raise the variable to the top of the scope, but not its value. The name of the function is not available in the scope of the variable and is only available from the inside.
Function declarations raise the name and its value to the top of the current scope.


Each example is clearly and vividly illustrated with a test block of code, many things chosen for speed or performance reasons are accompanied by references to jsPerf, ECMAScript specification (for those incredulous bothers who are not sufficiently simple) or some very interesting articles on this topic.

In general, at least, this is a very interesting piece of reading, and if you have long wanted to formalize the style of writing code, now is the time.
Included is a set of links to other basic guides, a list of commands that already use this style of writing code, sites that are worth reading and many more useful links, and most importantly - the configuration for JSLint in Sublime.

Here is a brief summary of the content for the busiest:


From ourselves we added literally several explanatory blocks and made one change: in the original it was proposed to use comments // FIXME and // TODO, but IDE and code editors usually highlight only // TODO, so instead of // FIXME it is proposed to use // TODO FIXME for easier navigation through the automatically generated index.

Just in case, duplicate links:

Source: https://habr.com/ru/post/204848/


All Articles