Loading ...
Sorry, an error occurred while loading the content.

2551Re: Formatting question

Expand Messages
  • g2223060
    Aug 4 1:26 PM
    • 0 Attachment
      Douglas- I'm not trying to convince you of anything ;)

      As background, I work as a user interface architect for a large financial services company that uses offshore developers. In our group, there are about 12-15 JavaScript programmers, working on 4 or 5 projects. My concern is the quality of the code they deliver. All of our JavaScript programmers are required to watch your videos as well as some internal videos that were inspired by you about our internal frameworks. We also have a policy that all JavaScript must pass JSLint before committing. I typically receive several requests for assistance each day. Some of them are due to inexperience with JavaScript and some of them are errors returned by JSLint that are not obvious. Most of the JSLint problems are truly problems- I can use it as a teaching opportunity, they correct their code, it passes JSLint and we move on. Others issues, such as this one, require me to do some research about the meaning of the error.

      So, as to this issue, if a variable is being initialized on the 'var' statement, that line may well exceed 50-60 characters, for example:

      var elementInWebPage = YAHOO.util.Dom.get('someElementID'), i, j;

      That first variable declaration is 59 characters. If I enforce {vars: false} then they are required to continue with one var statement, even though their editor/formatter may wrap the line.

      Long story a little longer (thanks for reading): Now that I know the real reason JSLint complains that 'j' should be in column 5, not column 8 I can inform our offshore staff to declare the uninitialized variables first. If they REALLY want to know why this is valid:

      var i, j,
      elementInWebPage = YAHOO.util.Dom.get('someElementID');

      and this is not:

      var elementInWebPage = YAHOO.util.Dom.get('someElementID'),
      i, j;

      I can tell them. But to say that the first way is "better" from a code quality or readability perspective, I just don't see that.


      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
      > --- In jslint_com@yahoogroups.com, "g2223060" <g2223060@> wrote:
      > > Wow. So if I have a variable that is initialized on the var statement and it is 50-60 characters long, I should declare it LAST on the var statement, otherwise I will have to have a bunch of lines with one variable on each line, like:
      > > i,
      > > j,
      > > k,
      > > ...etc...
      > >
      > > For the life of me, I can't see how this JSLint rule helps readability or code quality. But that's just me... Thanks for your explanation!
      > Are you trying to convince me that you are stupid enough to have a 60 character variable name and one character variable names in the same function? I'm not buying it. I don't think you are *that* stupid.
    • Show all 16 messages in this topic