- I for one think the message/error is pretty clear. You turned on an option to disallow the use of ++ . Then you used ++ . That seems unexpected to me. ItMessage 1 of 8 , Dec 13, 2010View SourceI for one think the message/error is pretty clear. You turned on an option to disallow the use of '++'. Then you used '++'. That seems 'unexpected' to me.
It is not the way in which you use '++' that is unexpected, but that you use it at all.
From: grahamj_42 [mailto:grahamj42@...]
Sent: Mon, 13 Dec 2010 15:55:32 +0100
Subject: Re: [jslint] Unexpected use of ++
--- In firstname.lastname@example.org, Brant Gurganus <brant@...> wrote:
> Besides what grahamj_42 indicated, citing a reference for a different
> language doesn't make sense. If such a thing existed, cite K&R
> seen encourage bad practices. However, that's a discussion for some
> other list.
However, you missed the irony in my post. As anyone who has learned C finds this way of writing a loop natural, 'i++' is to be expected, and if JSLint doesn't like this perfectly unambiguous expression, it should criticise it in different terms.
[Non-text portions of this message have been removed]
> 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?
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.