jslint plusplus

Today, my coworker asked why he can’t use ++ operators. I responded that jslint’s plusplus configuration ban it. He certainly was annoyed by such change in the configuration. A quick look into the reasoning behind the ban reveals the following statement from Douglas Crockford’s JSLint – JavaScript: The Good Parts:

The ++ (increment) and — (decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling viruses and other security menaces. The JSLint option plusplus prohibits the use of these operators.

Perhaps this ban is necessary for folks who have shown tendencies to develop obscure code in an attempt to deceive or trick others. At the same time, it also bans simple usages such as the one shown below:

var a = 0;
for (var i = 0; i < 5; i++) {
  a = a + i;
}  

In order to pass jslint, the for loop may have to look like the following:

var a = 0,
    i;
for (i = 0; i < 5; i = i + 1) {
    a = a + i;
}

Without ++ operators, code will no longer looks the same or as elegant as it used to be. Now that I have my 30 sec on this topic, life goes on with working code! 😉

One thought on “jslint plusplus

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s