-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed ES6 Styleguide #3
Comments
For |
For the usage of |
There are some subtle differences between Object.assign() and hoek's merge:
-mdn In most cases I think Object.assign() is preferable |
Nice coverage on ES6 features! |
Yeah I like this. For me, the highest priority features to adopt are arrows, const/let, object literal shorthand, and template strings. So I'm good with this :) |
Proposal - ES6 Features Styleguide and Preferences
Any performance notes are for Node and are likely drawn from the Six-Speed test.
This is primarily concerned with Node projects and may require additional notes for use with Frontend patterns.
The language of this guide
In compliance with RFC2119,
"Must" - Required for compliance
"Should" - Required in most situations, exceptions may exist but should require consideration
"May" - Not required in any way, optional, allowable but may be ignored.
The features
Strict mode
Must use
You probably should of been using this before, but this is required for several features to operate correctly in the current Node LTS
Object.assign()
Should use
This should replace most utility methods or awkward shims from ES5
const
Should use
Currenty offers no performance benefit but may help catch bugs. Please remember in JS this is only a constant reference, the properties of a constant object can be still be altered.
let
Should use when not able to use 'const'. May not be able to enforce this via linting
var should never be used anymore. Let follows expected scoping rules.
Map and Set
I'm not sure if we are using any large object literals, but these offer significant performance and a clean API.
Math/Number upgrades
Overview here
Should use
Pretty much just additional features and improvements here. Remember JS is not appropriate for real math.
Template Strings
Should use over string concatenation in most situations, avoid any logic in templated sections.
Template strings are only very slightly slower and much easier to read.
Classes
Should use for Object Oriented sections.
Object literal shorthand
Should use when possible
Significantly reduces redundant code, helps enforce good variable naming.
Arrow Functions
function
for any exported methods or methods that require their own scopePowerful but implicit return is a very new feature to JS and may confuse some programmers.
Symbols
Should use when appropriate, likely not needed in our codebase (appropriate use is when decorating foreign objects, etc)
Better then using obnoxious property names or underscores to try and hide features, but this pattern is not typical in our code base.
Parameter defaults
Should use, should come after required params
Exception:
Redux's reducer pattern on the frontend breaks this. This is allowable.
Redux aside, this removes silly code and is sufficiently intuitive for most developers. Optional params should always follow required ones.
Destructuring
May use, be cautious of complexity or magic behavior
Potential for misuse here but compared to the spread operator not terribly dangerous or unwieldy.
Spread
May use, be cautious of complexity or magic behavior
Very powerful, but can be difficult to understand. No performance gain, so should only prefer in obvious cases.
Rest
Should use over
Arguments
.Arguments is an array-like, and is awkward to work with. Rest is clean and fairly straightforward.
For...of
Should use when appropriate. Should not use on hot paths or large collections (11x slower than most loops)
For of is painfully slow, but handles a lot of awkward cases and is syntactically enjoyable. As long as it's not used on a hot path or large collections the performance hit should not affect us.
Generators
Generators are a powerful but hard to grasp pattern. They may be very beneficial in some places but need to be used responsibly.
The text was updated successfully, but these errors were encountered: