6 ms·
Google JavaScript style guidelines
- andreyf 16y agoI wonder what an IDE that enforces all of these guidelines would be like?
- goodside 16y agoIf guidelines were meant to be enforced, they'd be syntax.
- kwamenum86 16y agowell said
- pgbovine 16y agonot necessarily ... official language standards bodies might make decisions much more slowly than individual hackers or groups, and even when a feature is officially baked into a new version of the syntax, it might take compilers/interpreters several more years to all implement them properly. there's definitely a need for good lightweight static checking of guidelines in IDEs
- maw 16y agoNo, because guidelines can be overridden when there's a good case for doing so. Not so with syntax.
- j_baker 16y agoAgreed. "Style is only necessary where understanding is lacking." - Doug Hoyte
- deleted 16y ago[deleted]
- banuelios 16y agoYou don't need an IDE for that, but some code analyzers do give you hints/warnings. There's something for Python (google it)
- riprock 16y agoWhile it doesn't enforce the guidelines, their Closure Compiler enforces the variable types and encapsulations declared in the JSDoc comments with warnings. http://code.google.com/closure/compiler/ http://code.google.com/closure/compiler/ On another note, a Google engineer argues against Crockford's arguments for functional inheritance while pitching the benefits of the Closure Compiler and Library: http://www.bolinfest.com/javascript/inheritance.php http://www.bolinfest.com/javascript/inheritance.php I find his points are well made.
- gmosx 16y agoAlso check out Bolin's "Closure: The definitive guide" book, available as a rough cut. A great book indeed.
- exit 16y agowhy does javascript have a const keyword which shouldn't be used?
- goodside 16y agoThe inclusion of const in JS predates its use by Microsoft in Internet Explorer, which doesn't support it (at least up to IE6). It's not that it won't respect its const-iness; it won't even do the initial assignment. The original designers at Netscape couldn't have foreseen this, so it's in the language.
- markkanof 16y agoThe document says not to use const but you can use @const when appropriate. Can anyone explain what @const does? In the documentation example code it looks like it is just in the comments.
- riprock 16y agoMy other comment touches on this but the Closure Compiler parses the JSDoc comments and gives warnings for rules that are violated in the code.
- axod 16y agomany of the reserved words in js are taken from java. abstract goto debugger enum native implements protected synchronized throws transient volatile ^^ All 'reserved' for future use. const is used in the js 2.0 spec though.
- theycallmemorty 16y ago> Relying on implicit insertion can cause subtle, hard to debug problems. Don't do it. You're better than that. I loved that quote.
- jasonkester 16y agoNice. I'd never before seen a company language style guide where I agreed with every single point (Though I do tend to use "this" within my own classes, so I guess we're not in complete agreement). Great, concise explanations of why each point is good or bad (or not an issue). Opting for readability and debugability every time there's a choice. Favorite quote: "You're better than that."
- Amnon 16y agoThe "tips and tricks" section is interesting. I didn't know that iterating over node lists can take O(n^2). Also the Closure Compiler was new to me.
- WilliamLP 16y agoWith JavaScript, there is an interesting contrast between what its fans say are its strengths and what battle-hardened experience actually requires you to do. For example: - Prototype object systems are great... except don't actually use this, it doesn't really work. Use our simulation of a classical object system instead. - Lambdas are wonderful and powerful when combined with closures... except they leak memory. Don't use them, but declare named functions. - The 'this' parameter was a stupid idea. Use it as little as possible, except when absolutely necessary. - Be really conscious all the time, because of a stupid and misguided semi-colon insertion feature that will mess you up. - Don't bother trying to use anything other than C style for loops over collections. They mess you up. - The dynamic type system is nice... however experience shows us that what we really want is actually a static system, so JavaDoc types of everything with a cumbersome and extremely verbose syntax instead. - Extending prototypes of existing objects is an amazing and powerful feature. Please don't ever use it.
- andreyf 16y agoPrototype systems are great. I use them all the time, even in other languages. Extending prototypes of existing objects is amazing and powerful, and can be used for some beautiful data structures.
- cabalamat 16y ago> Extending prototypes of existing objects is amazing and powerful What can you do with it that you can't do in class-based OO languages?