Skip to content

Instantly share code, notes, and snippets.

@kenkouot
Last active August 29, 2015 13:56
Show Gist options
  • Save kenkouot/8941869 to your computer and use it in GitHub Desktop.
Save kenkouot/8941869 to your computer and use it in GitHub Desktop.
Examples of different whitespace styles. I argue that the first style needlessly adds whitespace between symbols that don't improve readability and might even be confusing do to no precedent for such aggressive whitespace being present in C-like languages. An example of this can be seen on `ln 15`.
// Aggressive Whitespace - Cannot find industry precedent for this style
// Invocations
foo( 'bar' );
foo( { key: 'prop' } );
foo( { key: getValue( 'foo' ) } );
// Examples of operator precedence clarification wrapping
if ( ( x * y ) + 1 > ( z / 2 ) ) { /* ... */ }
( function () {
$( 'body' ).jQueryPlugin( {
// options
} );
} );
// IIFE
( function( $ ) {
// ...
}( jQuery ) );
// Readability focused Whitespace - jQuery style - Collapse block symbols and delimiters
foo( 'bar' );
foo({ key: 'prop' });
foo({ key: getValue( 'foo' )});
// Examples of operator precedence clarification wrapping
if (( x * y ) + 1 > ( z / 2 )) { /* ... */ }
// IIFE
(function() {
$( 'body' ).jQueryPlugin({
// options
});
});
(function( $ ) {
// ...
}( jQuery ));
// Crockford style
foo('bar');
foo({key: 'prop'});
foo({key: getValue('foo')});
// Examples of operator precedence clarification wrapping
if ((x * y) + 1 > (z / 2)) { /* ... */ }
(function () {
$('body').jQueryPlugin({
// options
});
});
// IIFE
(function () {}
());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment