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

1676Re: Unexpected use of ++

Expand Messages
  • Douglas Crockford
    Dec 13 2:40 PM
      --- In jslint_com@yahoogroups.com, "grahamj_42" <grahamj42@...> wrote:
      > var i;
      > for ( i=0 ; i<10 ; i++ )
      > {
      > /* some code */
      > }
      > The i++ here is straight from K&R C, and so should be expected! I
      > haven't found a previous remark about this in the group, so is it a
      > new feature?

      K&R is an excellent book, but it is about an entirely different language. If you are going to be working with JavaScript, you need relevant documentation.

      One of the premises of a code quality tool is that there are features in languages that are problematic. The problem with bad parts isn't that they are useless, but that they are dangerous. They should be avoided if there are safer alternatives.

      In my opinion, ++ and -- are dangerous. They have been implicated in some of the worst OS security bugs. And they seem to confuse people who sometimes use i++ when the mean ++i (as you just did). Confusion leads to bugs.

      So JSLint has an option to warn when they are used. If you are wise, you will change your code to i += 1. But if you choose not to, then stop turning that option on.
    • Show all 8 messages in this topic