[thelist] Coning conventions, pet peeves

Will willthemoor at gmail.com
Mon May 2 11:53:55 CDT 2016

The Yoda convention is 'the law' in WordPress core. Backwards feeling it is
but the reasoning is sound—especially in projects with hundreds of
contributors and thousands of commits. I'm not a fan but get its purpose.
I'd say the fault is with languages that allow you define variables within
conditionals! Asking for trouble though linting on save can help here.

I use SCSS these days and make use of nesting but used to indent my CSS
like others have suggested here. My brain explodes though if there's more
than one declaration per line. I also alphabetize my properties.

On Fri, Apr 29, 2016 at 11:07 AM, erik mattheis <gozz at gozz.com> wrote:

> Two things I like to go against the grain on to make code more readable for
> myself -
> var message = 'This makes it easier for me to write HTML in JS';
> var mightDriveOthersCrazy = '<h1>'
>   + message
>   + '</h1>';
> Also -
> function functionWithManyArguments(
>   firstArg,
>   anotherArg,
>   thirdArg,
>   yetAnother
> ) {
>   console.log('Any more than three arguments becomes hard to read for me
> unless I use line breaks between them');
> }
I'm a big fan of both of these though sometimes I'll make the <h1> example
a single line.

For function args, arrays and variable definition lists, I've taken to
comma first.

function functionWithManyArguments(
  , anotherArg
  , thirdArg
  , yetAnother


var foo
  , bar
  , baz

It's a little weird at first but it means it's very simple to move stuff
around since nothing has a comma on the end (which would break if moved to
the bottom of the list in JS). Also very easy to see stuff like missing
commas. I first noticed it in Bootstrap's source.

Similarly, when chaining (jquery or whatevs)

    .html('lines are good')

+10 to the diff reasoning. Not only is it clearer but it's easy to see/use
in narrow side-by-side windows!

More information about the thelist mailing list