Live data from Hacker News

Best Practices Exist For A Reason

tomdale.net

11–20 of 105 posts

Re: Best Practices Exist For A Reason

#11
post #7

Earlier quoted context omitted.

That example gist went a long way towards convincing me of isaacs' comma prefix style. To me, consistency is important. All of my codebase is traditional comma postfix, so I'll keep using that; however, maybe with some new projects I'll try on the comma prefix pants and see if it helps. Thanks for the link!

To play at devil's advocate, please don't. Otherwise you should have written your comment like this: To me , consistency is important . All of my codebase is traditional comma postfix , so I'll keep using that ; however , maybe with some new projects I'll try on the comma prefix [...] ... using typography in a typographically sensible way is far more important to readability than an arbitrary "consistency" of punctat…

Why does nobody ever mention the obvious solution? Separate var statements.

They're always correct, they copy without any editing, and the "var"s line up to show that it's a block of assignments the same as commas or whitespace.

Re: Best Practices Exist For A Reason

#12

The main problem with appealing to "best practices" is this: One man's best practice is another man's anti-pattern. Between semicolon-free folks and JavaScript traditionalists, who gets to play the role of the expert? If Node.js is popular, does that mean that Isaac's comma-first style is "correct"? ( https://gist.github.com/357981 ) In the absence of a quantitative engineering method with which to evaluate either ap…

I think using comma-first syntax as a counter example is disingenuous. Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Omitting semi-colons, however, can cause novice JavaScript programmers serious grief. Nevermind novice JavaScript programmers – they cause me grief, and I put semi-colons everywhere! That's b…

[deleted]

Re: Best Practices Exist For A Reason

#13
JavaScript and semicolon controversy aside - I'm always happy when I read a post written in this style. It's clear (at least to me) that the author has taken the time to think about what they're saying, and they present clear arguments. I always hope that more people write this way; in the style of what I feel is real discussion.

Re: Best Practices Exist For A Reason

#14

The main problem with appealing to "best practices" is this: One man's best practice is another man's anti-pattern. Between semicolon-free folks and JavaScript traditionalists, who gets to play the role of the expert? If Node.js is popular, does that mean that Isaac's comma-first style is "correct"? ( https://gist.github.com/357981 ) In the absence of a quantitative engineering method with which to evaluate either ap…

I think using comma-first syntax as a counter example is disingenuous. Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Omitting semi-colons, however, can cause novice JavaScript programmers serious grief. Nevermind novice JavaScript programmers – they cause me grief, and I put semi-colons everywhere! That's b…

Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable.

Really?

The comma first style makes it less likely that your list will end with a trailing comma, which can cause IE-specific bugs. If you're trying to track down the IE breakage a couple of weeks after you wrote down the code, it can be fun to track down the extra comma. If you don't know that this bug is possible (as I'm guessing you don't), multiply the hair-pulling by 10.

See the cautionary story in http://www.enterprisedojo.com/2010/12/19/beware-the-trailing... for a real life example.

With the comma first style, that bug would never have been introduced. Neat, huh?

Re: Best Practices Exist For A Reason

#15
post #7

The main problem with appealing to "best practices" is this: One man's best practice is another man's anti-pattern. Between semicolon-free folks and JavaScript traditionalists, who gets to play the role of the expert? If Node.js is popular, does that mean that Isaac's comma-first style is "correct"? ( https://gist.github.com/357981 ) In the absence of a quantitative engineering method with which to evaluate either ap…

That example gist went a long way towards convincing me of isaacs' comma prefix style. To me, consistency is important. All of my codebase is traditional comma postfix, so I'll keep using that; however, maybe with some new projects I'll try on the comma prefix pants and see if it helps. Thanks for the link!

That example gist went a long way towards convincing me of isaacs' comma prefix style.

What convinced you? I read it and saw something wildly different, which is best reserved for a good reason. The reason appears to be visual recognition of delimiter mistakes that the parser will catch anyway.

The gist contains examples of various mistakes in both styles. Most of the errors are syntax error which will be immediately rejected by a parser. While the comma first errors are generally more obvious, they are silently bad by unexpectedly returning undefined. The standard "var" example is silently bad by leaking vars into the global scope when chaining initializers on a single "var". My conclusion from these samples is that comma prefix formatting only practically helps to prevent hidden mistakes in chained "var"s. Putting each variable declaration on a line of its own is far less distracting than reformatting every list and object.

Sample comma first style error. This seems like a strange thing to do, but I'm unfamiliar with this style.

    return
      { a : "ape"
      , b : "bat"
      } // returns undefined,
        // then creates a block with two named statements.
Sample standard style error:

    var a = "ape eat banana",
      b = "bat, allowed to fly",
      c = "cat toy",
      d = "dog chasing the mailman,"
      e = "elf lord",
    ....
    // leaks "e" into global scope

Re: Best Practices Exist For A Reason

#16
post #14

Earlier quoted context omitted.

I think using comma-first syntax as a counter example is disingenuous. Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Omitting semi-colons, however, can cause novice JavaScript programmers serious grief. Nevermind novice JavaScript programmers – they cause me grief, and I put semi-colons everywhere! That's b…

Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Really? The comma first style makes it less likely that your list will end with a trailing comma, which can cause IE-specific bugs. If you're trying to track down the IE breakage a couple of weeks after you wrote down the code, it can be fun to track down the ex…

You also gain a new possible bug--the leading comma.

Re: Best Practices Exist For A Reason

#17
post #14

Earlier quoted context omitted.

I think using comma-first syntax as a counter example is disingenuous. Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Omitting semi-colons, however, can cause novice JavaScript programmers serious grief. Nevermind novice JavaScript programmers – they cause me grief, and I put semi-colons everywhere! That's b…

Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Really? The comma first style makes it less likely that your list will end with a trailing comma, which can cause IE-specific bugs. If you're trying to track down the IE breakage a couple of weeks after you wrote down the code, it can be fun to track down the ex…

With the comma first style, that bug would never have been introduced. Neat, huh?

If you run any syntax checking or minification tools, this will be immediately obvious. If you test your site in IE at all, this will be immediately obvious. If you record JS errors on your site, this will soon be obvious. If you record any kind of usage statistic, this will eventually be obvious.

Take it from someone who has experimented with cutesy formatting in the past[1]: you don't need to use cutesy formatting to solve this problem.

[1 | You can end class declarations with _:0} instead of a bare } to avoid the trailing comma issue. ]

Re: Best Practices Exist For A Reason

#18
The real question is why anyone takes obviously wrong artifacts in JavaScript like omitting semicolons and flagrantly wrongly designed this binding seriously. This isn't an issue of best practices or personal preferences, it's aspects of a ubiquitous language that are simply and unequivocally broken.

Re: Best Practices Exist For A Reason

#19

The main problem with appealing to "best practices" is this: One man's best practice is another man's anti-pattern. Between semicolon-free folks and JavaScript traditionalists, who gets to play the role of the expert? If Node.js is popular, does that mean that Isaac's comma-first style is "correct"? ( https://gist.github.com/357981 ) In the absence of a quantitative engineering method with which to evaluate either ap…

The root problem is that we still don't know how to disagree when two sides look at the same set of data and believe two different things. We allow ourselves to descend into tribalism and assume the worst of each other.

If you look at the language Tom objects to the most, it's language Isaac uses that promotes this tribal attitude that the other side doesn't have your best interests at heart, and questions their motives.

We're just terrible at this, and I'm not sure any human society has ever really cracked it.

Re: Best Practices Exist For A Reason

#20
post #14

Earlier quoted context omitted.

I think using comma-first syntax as a counter example is disingenuous. Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Omitting semi-colons, however, can cause novice JavaScript programmers serious grief. Nevermind novice JavaScript programmers – they cause me grief, and I put semi-colons everywhere! That's b…

Whether you're a novice programmer or an expert programmer, using comma-first or comma-last isn't going to bite you in a way that isn't immediately solvable. Really? The comma first style makes it less likely that your list will end with a trailing comma, which can cause IE-specific bugs. If you're trying to track down the IE breakage a couple of weeks after you wrote down the code, it can be fun to track down the ex…

With a decent language that allows trailing commas (eg. everything other than JS or SQL), it would never have been a problem in the first place.
Post reply on HN