Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added curly braces around all if/else statements
- Loading branch information
Showing
7 changed files
with
149 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of surprised at this change. Yes it's better readability but last time I checked, YUICompressor can't remove them all.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ew no i hate this.. makes it much harder to read, this is why jquery is not readable IMO, way to much cruft
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@visionmedia, funny you say that; this change was probably made for readability's sake. I for one think it's a good idea. Using IF/ELSE statements without curly blocks is generally considered bad practice. And, frankly, @aheckman, if YUICompressor can't handle these changes, then we should stop using it. Closure Compiler FTW!
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see how people think swarms of braces increase readability. jQuery is a fantastic library but VERY unreadable IMO. This is like saying Ruby's do / end is readable, its just cruft.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamespadolsey - I not sure if Closure Compiler can handle jQuery at all. I've seen some posts around the internets pointing out bugs with it.
http://www.sitepoint.com/blogs/2009/11/12/google-closure-how-not-to-write-javascript/
http://stackoverflow.com/questions/1691861/jquery-compiled-with-google-closure-compiler
It seems the "advanced" setting is what really provides the file size boost, but, that is the mode that causes the most problems.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@visionmedia, I guess it's a personal thing. For some projects, where I don't have to worry about other developers working on my code, I will frequently not bother with many best practices like curly braces... but, at the end of the day, for the majority of people, they do enhance readability. Using curly braces allows viewers to break up the code into separate logical pieces more easily. To be honest, using curly braces on single lines like:
... is quite pointless, but I guess if you've decided to "go curly", you may as well go all the way...
I found this to be an interesting read: http://stackoverflow.com/questions/359732/why-is-it-considered-a-bad-practice-to-omit-curly-braces
@aheckmann, even using the simple setting shaves off a few kb. I imagine that John will be looking into those bugs prior to the 1.4 release, although, it's not really his problem. Google should fix the closure compiler.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record, I was just trying to align jQuery core with its own Style Guidelines:
http://docs.jquery.com/JQuery_Core_Style_Guidelines#Blocks
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this way is much more concise and easy to read.. braces just clutter the code and make it harder to scan. example: http://gist.github.com/255605
Hell if you could use try / catch without braces I would lol but ya its preference I suppose... I used to write like you guys, maybe 3 years ago
but I have more of a functional approach with every language I write in now
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should paint it red.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad we weren't accepting these kind of "patches" to Prototype back when they were all the craze.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@visionmedia It sounds like you wish you were writing Python not JavaScript ;)
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how so? the grammar allows this.. lol so why not utilize it? I think its stupid not to. Taking a functional approach with any language is a good thing not a bad thing. But yes Python stuff looks alot better than jQuery :P
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to say, calling "readability" on either side is just BS.
Neither of the above is "more readable". The latter may be quicker to "scan" for a "block", but any basic syntax highlighting, even just bold keywords, will recover ease of scan for the prior.
The hated case:
This is unrealistic. Firstly it is very badly formatted code. Secondly this code stands out like a massively to me, even as a ruby developer where it would be legal. The reason it stands out, is because of the parenthesis. One rule that my mind has generated is that conditional blocks with parenthesis and no curly braces cannot be used in the above fashion, and warning bells go off when I see it.
The point merely is, that the readability of these things is trainable, and to claim that one is more readable than another really shows nothing but a lack of experience. There are areas of language grammars that might be generally considered more or less readable, but frankly, these very, very common constructs should be practically common knowledge by now, and as such should not be subject to any lack of readability for someone with a reasonable portion of experience.
A claim of "I prefer braces" or "I like braces" is perfectly respectable, and acceptable, but calling readability on this, I just find amusing.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And when writing code, I generally try to do as little work as possible.....
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is certainly more consistent. Consistency is good.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consistency is good for sure, im all for that. I find even the strange whitespace within the parens a little weird too.. but hey. Not sure I have ever seen
thats just bad, maybe
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency, lol.
...
Different code needs different approaches. Having several different forms of definition for conditional blocks is not inconsistent. If you think so, then please use ONLY if statements OR boolean conditionals (&&) in your code, not both. Using two different forms is inconsistent.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are talking about consistency with styling ... not the code itself
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mislav Andrew and Tobie have done plenty of code consistency commits. Consistency is a good thing.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+5; I love to see consistency in a framework or library, and the fact that it's the "correct" way to do things is an added bonus.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency ftw.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those interested, the "jQuery Core Style Guidelines" can be viewed here: http://docs.jquery.com/JQuery_Core_Style_Guidelines#Blocks
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha ew... i understand there is no turning back now from what has been done but damn those are ugly conventions.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the minus side, I hate curly braces.
On the plus side, I hate painting bikesheds. Style guides, while vaguely creepy and authoritarian, definitely minimize the number of painters we need to keep around.
(And fwiw, consistency could be maintained with mixed braces, so long as they were used in a regular fashion. It's irregularity that creates inconsistency and importantly, confusion.)
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely missed this brouhaha. There is no possible way in which actually using braces is worse for jQuery. It standardizes the code base and it makes it easier to understand. We're not going back to the dark ages of mixed braces and multi-level deep no-brace statements.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coding standards: use them, no exceptions.
ddb86f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+5; painting it red!