Live data from Hacker News

Best Practices Exist For A Reason

tomdale.net

31–40 of 105 posts

Re: Best Practices Exist For A Reason

#31
post #27
post #17

Earlier quoted context omitted.

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 experiment…

Indeed the link I gave demonstrates how the right IDE also solves this problem. The fact that there are many ways of solving the problem does not mean that it isn't a real problem that formatting can help address.

It means that there are ways of solving the problem that don't involve rewriting the code in a way that initially will confuse 99.999% of other developers.

And it is important in our industry to write MAINTAINABLE code.

Re: Best Practices Exist For A Reason

#32
post #11

Earlier quoted context omitted.

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.

You can only put var at the beginning of variable declarations, but there are many other places that commas are used as a separator. So that "solution" doesn't apply in general.

Re: Best Practices Exist For A Reason

#33
post #26
post #16

Earlier quoted context omitted.

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

I have found that this is much less likely in practice. Lists usually grow on the end, not the beginning. (I use this kind of formatting for SQL, for a similar reason.)

There's nothing like spending hours tracking down a bug that shouldn't occur in normal practice.

Re: Best Practices Exist For A Reason

#34
post #11

Earlier quoted context omitted.

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.

Most people also apply this to object literals. There are no var statements in this situation.

Re: Best Practices Exist For A Reason

#35
post #10

Earlier quoted context omitted.

The problem here is viewing software development as some sort of monolithic phenomenon. "Software development" is a crude moniker that covers an incredibly wide variety of efforts, varying in scale, detail, and significance across a much wider range than anything else we consider to be a single discipline. "Best practices" for development of an iphone game may not be the same as for flight software for an orbital roc…

The problem is that the industry, as a whole, is still extremely young, and simply hasn't had the time to develop a standard set of good, let alone best, practices. Tools and processes are changing at a rapid rate, and it will simply take time for best practices to sort themselves out. >"Best practices" for development of an iphone game may not be the same as for flight software for an orbital rocket or for an intern…

Or, for that matter, not designing programming languages such that they violate the principle of least surprise with reckless abandon.

Re: Best Practices Exist For A Reason

#36
post #14

Earlier quoted context omitted.

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…

What's harder, finding an extra trailing comma, or finding a missing semi-colon in a JavaScript file that contains no semi-colons?

[deleted]

Re: Best Practices Exist For A Reason

#37
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…

This. I admire code that reads like english. Leading commas are a terrible idea in my humble opinion.

It's so ugly to me that the whole idea seems like it could be a troll.

Re: Best Practices Exist For A Reason

#38
post #20

Earlier quoted context omitted.

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.

Trailing commas is defined in ECMAScript 5. The issue is that IE8 and earlier choke on them.

Isn't ES5 only supported since IE9?

Not to mention, IE8 was released half a year before ES5 (according to a quick check on Wikipedia). So yes, pre-ES5 I'd say it's a normal thing to do not to allow trailing commas.

Re: Best Practices Exist For A Reason

#39
post #38

Earlier quoted context omitted.

Trailing commas is defined in ECMAScript 5. The issue is that IE8 and earlier choke on them.

Isn't ES5 only supported since IE9? Not to mention, IE8 was released half a year before ES5 (according to a quick check on Wikipedia). So yes, pre-ES5 I'd say it's a normal thing to do not to allow trailing commas.

I think if you re-read my comment, you'll find I'm saying the same thing.

Re: Best Practices Exist For A Reason

#40
post #37

Earlier quoted context omitted.

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…

This. I admire code that reads like english. Leading commas are a terrible idea in my humble opinion. It's so ugly to me that the whole idea seems like it could be a troll.

I use leading commas in any list that is not one liner in C++. This way the code looks pretty, and that is way more important that code that reads like english. :) (I shudder from dread every time I look at applescript...)
Post reply on HN