

ES6 Coding Style Guide - elierotenberg
https://github.com/elierotenberg/coding-styles/blob/master/es6.md

======
AprilArcus
I agree with and appreciate nearly all of these suggestions. Just a few well-
intentioned quibbles:

> Arrays MUST be created using the Array syntax literal.

This does enhance readability when vending an empty array, but when you know
how large an array will need to be in advance, new Array(someLength) is an
important pattern. Consider this naïve implementation of Clojure's
"reductions" or Haskell's "scanl":

    
    
      let reductions = (callback, initial, array) =>
        array.reduce( (memo, element) => {
          memo.push( callback(memo[memo.length - 1], element) );
          return memo;
        }, [initial]);
    

This will call push() array.length times. If the backing store for Array is a
typical vector implementation that reallocates every time its length exceeds a
power of 2, this means incurring log₂(array.length) reallocations, and
suffering the concomitant heap fragmentation. However, if we pre-allocate an
array of the appropriate size once before entering the loop,

    
    
      let reductions = (callback, initial, array) => {
        let result = new Array(array.length + 1);
        result[0] = initial;
        array.forEach( (element, index) =>
          result[index + 1] = callback(result[index], element)
        );
        return result;
      };
    

we can avoid creating unnecessary work for the VM.

> Regular (named and hoisted) function declarations SHOULD be used instead of
> anonymous functions by default.

I think this is really bad advice. Hoisting makes imperative code harder to
reason about; any time that it would actually make a difference, the un-
hoisted behavior is the one I would want. The verbosity of let myFunction =
function(x,y) {}; over myFunction(x,y) {} is definitely unsightly, but it's
worth my peace of mind.

> undefined MUST NOT be used, void 0 MUST be used instead. [...] Pure
> convention. Also void 0 looks more l33t.

undefined should be preferred on grounds of readability. If ES3 compatibility
is really important, you can configure babel to emit void 0 in place of
undefined with the spec.undefinedToVoid optional transformer.

------
cnp
Really nice (and a fantastic JavaScript overview in general), though the MUST
and SHOULD's get a bit wearing on the eyes after some time; perhaps a simple
__bold __would suffice?

------
glaciusNexus
Nice !

