Last active
August 29, 2015 13:56
-
-
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`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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