Comments on: Move that parenthesis! https://j11y.io/javascript/move-that-parenthesis/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: Durgesh https://j11y.io/javascript/move-that-parenthesis/#comment-2431 Sun, 19 Aug 2012 18:10:53 +0000 https://j11y.io/?p=2084#comment-2431 I agree. I really cant understand few things in JSLint.Like:

When I write
var x = function(){alert(“Hello”)}

Lint shows me errors like:
Expected exactly one space between ‘function’ and ‘(‘.
Expected exactly one space between ‘)’ and ‘{‘.
Missing space between ‘)’ and ‘{‘.

Can any body let me know why these spaces are needed.

]]>
By: Herbert Peters https://j11y.io/javascript/move-that-parenthesis/#comment-2430 Mon, 16 Jul 2012 00:38:41 +0000 https://j11y.io/?p=2084#comment-2430 I always thought that any formatting is very subjective. And even consistency is subject to change, as apparent when I view my older projects. Sometimes that change of style has been brought be new language features. For example the try/catch/finally has lead me to rethink my personal approach to code style. Starting to use jQuery was another reason for change of style, as its chaining ability has it’s own peculiarities on style.

IMO what we really need are text editors that allow the use of “style guides”. Preferably so that different developers can choose between different styles on the fly, even create their own set. Not just individualize coloring as many editors already allow us to do.

And when I finish my coding, things should be reformatted using the teams style guide.

]]>
By: Dale King https://j11y.io/javascript/move-that-parenthesis/#comment-2429 Tue, 15 May 2012 14:17:20 +0000 https://j11y.io/?p=2084#comment-2429 And I agree that the word “style” is not an appropriate word. It is better to think of them as coding best practices.

]]>
By: Dale King https://j11y.io/javascript/move-that-parenthesis/#comment-2428 Tue, 15 May 2012 14:15:28 +0000 https://j11y.io/?p=2084#comment-2428 The purpose of a coding convention should be to codify the practices which lead to more readable and maintainable code. It is not just to make the code more consistent as many claim. If the coding convention espouses practices that are less readable then it will make the code consistently harder to read (e.g. Microsoft’s type-base naming, often incorrectly referred to as Hungarian notation).

The question then is discovering what is more readable. I completely disagree with those that claim that readability is subjective and differs from person to person. Readability is objective and could theoretically be measured. Something is more readable if it is more easily comprehended by the most people. You could measure how fast and easily people comprehend various variations of code.

I’m not suggesting that such measurements are being performed or will ever be performed, but just stressing that readability is not subjective. So without objective measurements we have to apply logic to try to reason what is more readable for the greatest number of persons.

For example the convention that in C-style languages you use braces ALWAYS even for single statements is one that we can logically assume is more readable to the greatest number of people. You have a convention that basically visually tells a reader that there is a variation from straight through code flow. It also is more maintainable.

There are a number of other ways to evaluate whether something is more readable. If a coding convention goes against more readable it sometimes should not be followed.

The C-style for loop has always been a nightmare from a readability standpoint. I don’t agree that smooshing the ; next the parenthesis makes it more readable. In this case I might lean to changing to a while loop and moving the increment to the bottom of the loop.

Of course your readability would also be improved by avoiding the “hidden brace” style and move that opening brace to its own line 😉

]]>
By: Joe Zim https://j11y.io/javascript/move-that-parenthesis/#comment-2427 Tue, 15 May 2012 02:25:46 +0000 https://j11y.io/?p=2084#comment-2427 I completely agree with this article. It’s impossible to find a style guide that I can completely agree with. Heck I can’t even completely agree on my own style because I have so many different factors guiding how I do things. I think style guides should just be used in a group for the sake of consistency.

]]>
By: David Higgins https://j11y.io/javascript/move-that-parenthesis/#comment-2426 Mon, 07 May 2012 00:23:20 +0000 https://j11y.io/?p=2084#comment-2426 After all, we have to stress code being only a preference, not a coding convention.

I think people are forgetting that a preference differs slightly than a convention, in that you’re adopting your own style, not a codified “way” of doing things.

Google for “coding conventions javascript” and you’ll see many codified ways of writing JS.

]]>
By: Nik https://j11y.io/javascript/move-that-parenthesis/#comment-2425 Sun, 06 May 2012 20:13:55 +0000 https://j11y.io/?p=2084#comment-2425 I agree, to me, javascript from others isn’t as bad as CSS from others. First, one is dealing with an annoying language that is the CSS, second, do you put the curly one line down or next to the selector name? Do you just stuff everything in one line? And so on, I’d say, since this is formatting, unless I miss something, our text editor, sublimetext2/textmate2/vim or something, should support some sort of “Style Guide Formatting” so we never have to worry about how to style it. You can have you next line curly, I can have my single line selector.

]]>
By: Wolfram https://j11y.io/javascript/move-that-parenthesis/#comment-2424 Sun, 06 May 2012 18:49:37 +0000 https://j11y.io/?p=2084#comment-2424 It takes a bit to wrap your head around a style guide, accepting it, writing by it’s rules, and on top being fast in understanding the consistently written code, but it does reduce the number of additional brain cells required, coders won’t start reformatting code, there is just less to discuss/argue about, the actual use case becomes more important, as it should. we programmers are just great in bikeshedding irrelevant stuff. It took me years to accept that my personal prefs for how to write code are really less important than allowing a (big) team be able to work together, and the dojo project showed that very well, all rules were argueable but they were set and that made things easier, very quickly.

]]>