0

Possible Duplicate:
How come JQuery doesn't pass JSLint?

The jQuery style guideline referenced here

gives a spacing style that breaks jslint.

I realize I can just have it ignore "messy white-space" but my bigger concern is such:

JavaScript is widely popular as is jQuery and jslint.com. How can jQuery consider this "good style" while jshint.com considers it messy.

More so, how should I write my own code and feel that it is "in good style" when two very popular JavaScript resources can not agree on such a thing.

I feel the jQuery spacing guideline is over the top with too much spacing, is this some sort of rogue document that needs to be taken down?

Also, while looking at a jQuery effects function I noticed that jQuery did not follow it's own spacing guideline at times.

In short,

Community
  • 1
  • 1
  • Do you jslint.com considers it messy or jslint.com? I think jquery uses jshint rather than jslint. – Larry Battle Jul 29 '12 at 23:22
  • 1
    *Which style is better?*: While there are some sound reasons for certain style decisions, overall, *style* is highly subjective. That's why there many different coding guidelines and not only one (why choose an inferior one?). Use what you agree most with or create your own ;) For the fun of it, [here is Google's](https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml). – Felix Kling Jul 29 '12 at 23:29
  • And reading the jQuery "standards", I partially agree; there's some pretty "dumb" stuff in IMO (`if ( this === that ) {` Spaces separating the conditions from the parentheticals? Really? `TAB`s are required over four spaces? REALLY?) But that's my opinion. I'd never use it, but I have a finely honed sense of whitespacery. LOL – Jared Farrish Jul 29 '12 at 23:31
  • The style guide isn't a resource for you to use, it's rules that people who wish to contribute to jQuery are expected to follow. If you're not going to submit changes to jQuery, you can ignore anything in the document you don't like. While jQuery is certainly a massively popular library, a code style guide is still an utterly arbitrary choice amongst technically equivalent options. You're free to make your own choice there. – millimoose Jul 29 '12 at 23:38
  • @All...I just don't think there needs to be 2 styles...it is such a simple think to agree on, I imagine if industry can't agree on something as simple as style...that things as complex as architecture...have a long ways to go...I'm going to argue that all the extra spacing is wasteful..in keystrokes..and in memory and does not contribute to readability (+ jQuery code does not even follow it's own style).... –  Jul 30 '12 at 00:11
  • @Jared and others - open this back up so others can learn to style there code well, and not be mislead. –  Jul 30 '12 at 00:20
  • 2
    Dude. Argue with the jQuery developers. It's *not constructive* to ask a question which is explicitly meant to evangelize or promote subjectiveness. Sorry, but it's textbook "not a good fit" for SO. `:)` – Jared Farrish Jul 30 '12 at 00:23
  • Two styles? There are many different coding styles. It's not at all a simple question. There is no one answer. I don't like jQuery's rules, and I definitely don't like JSLint. Eliminating choice is probably the worst scenario I could imagine. Thank goodness I'm not required to follow Crockford's or jQuery's idea of what is the appropriate coding style. –  Jul 30 '12 at 01:18
  • As @JaredFarrish alludes to, this question is textbook "not constructive". Valentinas' answer is the only possible "good" one - use whichever you like. This is not a site for 'discussion' or opinion of this sort. As a helpful addition, the close votes point you to a question concerning *why* the disparity, which is the only objective issue here. – Andrew Barber Jul 30 '12 at 13:16
  • Well...the reason I brought this up...is b.c. if I write code for one project...and later I want to use it in another project...I don't want to have to spend hours...adjusting white space to conform to project 2's.....style guideline...having a single coding style would save the development community immense amounts of time and make code more compatible...sad people don't seem to acknowledge this....not too sure how saving time is not constructive... –  Jul 30 '12 at 16:13
  • I think this question aptly brings out the fact that people can't agree on simple things....coding style doesn't really matter as long as it is reasonable...what does matter is the incompatibility caused by having multiple types 1. for each language. and 2. for all languages....Closing this question and calling it unconstructive...is simply...an expression of coder group think in general...you can't go wrong by agreeing with the group. –  Jul 30 '12 at 16:19

1 Answers1

1

Whichever you like better. The more important thing is consistency. It is important to have a coding style and as long as it's consistent across the project (or team) it's all good. If the project is public you should also publish the coding standards (if it's not public you should still have a coding standards document for your team and yourself to refer to), so participating people reading and writing your source would be aware of what the style should be.

valentinas
  • 4,277
  • 1
  • 20
  • 27