facebook

Javascript validation: Using ++ and — is considered harmful

  1. MyEclipse Archived
  2.  > 
  3. Web Development (HTML, CSS, etc.)
Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #243258 Reply

    Sveinn Jonsson
    Participant

    The javascript validation in MyEclipse 4.1 M2 warns about using ++ and — operators, why?

    I use the ++ operator in all my for-loops [in both Java and Javascript] and I’ve never considered them harmful.

    #243265 Reply

    Greg
    Member

    Here is a quote from the JSLint guys concerning javascript.

    The ++ (post-increment) and — (post-decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces.

    So our validator by default marks them as warnings. However, you can remove them from being marked during validation by going to the Preferences > MyEclipse > Editors > Javascript > Content Assist & Validation and you can uncheck that option for ++/–. Then you can right click your file in the package explorer and run “MyEclipse > Remove All Validation Markers” and those warnings should go away.

    #250494 Reply

    mr_hyro
    Participant

    But JSLint document complains mostly about post-increment/post-decrement operators (i++), and allows pre-increment/pre-decrement operators (++i), while MyEclipse marks both cases as a warning.

    #250962 Reply

    LOGUSR
    Member

    Hi,

    I have the same warning. I want to disable it by changing the properties but the path you gave: “Preferences > MyEclipse > Editors > Javascript > Content Assist & Validation” is not existing the myEclispe I use (4.1.1 GA)

    Any suggestion ? I tried to find these settings in Project Properties -> Java Complier -> Errors/Warning without success (these are only for Java and not javascript).

    Thanks

    #251227 Reply

    rateoty
    Member

    Preferences->MyEclipse->Editors->Javascript->Javascript Source

    regards Jürgen

    #251230 Reply

    LOGUSR
    Member

    Ok sorry,

    😳

    I had confusion between project properties and preferences because these windows looks the same…

    Thanks for help.

    Patrick – newbie in Eclipse

    #251422 Reply

    “The ++ (post-increment) and — (post-decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces.”

    This is a really, really dumb warning to have on by default. ++ and — can be used to make tricky code. I almost invariably only use them in loop increments where they are not dangerous AT ALL.

    Someone’s strange idea that they are so dangerous they should be flagged as warnings any time they are used anywhere is a very poor default.

    #251837 Reply

    I am going to have to agree with Jacob – this warning should not be on by default.

    This bit of brain-damage is one of the very first things I saw when firing up MyEclipse for the first time – not encouraging.

    #252959 Reply

    Roguen
    Member

    /agrees,
    I don’t really see the justification here, and imho I don’t think this should be a default warning.

    #257654 Reply

    As a subscriber to the Professional MyEclipse License, I agree whole-heartedly. pre- and post-increment (decrement) operators are the NORM. JSLint folks are in the extreme minority and these should be off by default. I use MyEclipse extensively and therefore create Many workspaces for various projects and clients. It is a very bothersome chore to have to remember to go in and set defaults to what should be considered STANDARD BEST PRACTICE. Please listen to your customers and change these defaults.

    In fact, I’ll go one better. Why not introduce something like the Bug Parades that other projects use? Then, you could get a realistic picture of how various settings are affecting your client-base.

    And because of my rant, let me be clear: I have used Eclipse for more than 2 years now. I was introduced to MyEclipse by a recent customer (March 2006); and haven’t looked back. Overall, this is a great value! Thanks for the hard work and excellent product!

    #259816 Reply

    jurriaan
    Member

    @support-greg wrote:

    Here is a quote from the JSLint guys concerning javascript.

    The ++ (post-increment) and — (post-decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces.

    There are no JSLint guys. It is just one guy: Douglas Crockford. While he is obviously very well versed in JavaScript, his opinions should not be taken seriously. Just to illustrate why Mr. Crockford should be considered harmful himself, here’s a very simple implementation of the factorial function:

    function factorial(n) {
        var f = 1;
        for( var i=1; i<n; i++ ) {
            f = f * i;
        }
        return f;
    }
    

    Mr. Crockford wants us to believe this is harmful and proposes a “better” implementation on http://javascript.crockford.com/little.html.

    function y(le) {
        return function (f) {
            return f(f);
        }(function (f) {
            return le(function (x) {
                return f(f)(x);
            });
        });
    }
    
    var factorial = y(function (fac) {
        return function (n) {
            return n <= 2 ? n : n * fac(n - 1);
        };
    });
    

    I dare say that nobody except the five lispers left in this world would find the latter piece of code more concise or clear or understandable than the first.

    Worse, Mr. Crockfords code is orders of magnitudes slower then the simpler one in any JS engine that I know of; and it is incorrect: Mr. Crockford’s implementation computes factorial(0) wrongly as 0, instead of 1.

    That said, Mr. Corckford’s JSLint validator is much better than the MyEclipse validator. For example: JSLint understands extern function calls; JSLint understands W3C DOM constructions such as document.defaultView that ME does not.

    #259818 Reply

    jurriaan
    Member

    Oops, that should be

    for( var i=1; i<=n; i++ )


    Guess I’m harmful myself as well… but I stick to the point I wanted to make.

    #260847 Reply

    jyutzler
    Member

    I think having this warning turned on by default is a bit much. Instances of people creating bugs by confusing prefix and postfix incremental operators have got to be extremely rare. If you are going to be excessively pedantic, you might as well flag something that is actually dangerous like:

    for(i = 0; i <= n; i++)

    where ‘i’ is not declared as a local variable and might stomp on (or be stomped on by) some other bit of code. A significant percentage of the infinite loops caused by JavaScript code can be traced back to this easily flagged mistake.

    #264676 Reply

    I’d just like to add that I also find it rather silly for this to be a default-on warning …

    #273835 Reply

    sszabo
    Member

    In my humble opinion, the core issue here that the editor’s validation is TOO simple. Rather than having a warning for ON or OFF, why cant the validator check to see if the operator is contained within brackets or other risky position before presenting a warning?

Viewing 15 posts - 1 through 15 (of 21 total)
Reply To: Javascript validation: Using ++ and — is considered harmful

You must be logged in to post in the forum log in