Duplication of effort



  • Extracted from some code I'm working on

    1
    2
    3
    4
    5
    6
    7
    8
    function shutup(i) {
        var o = document.getElementById(i);
        if (o) o.style.display = "none";
    }
    function shutup2(i, j) {
        document.getElementById(i).style.display = "none";
        document.getElementById(j).style.display = "none";
    }
    

    I just don't understand what prompts people to do these things... Can anyone think of a good reason for someone to do something like this?

    Also interesting to note that the second version does not check for the existence of the element, and that the check in the first function will probably result in an exception anyway.



  • @Aeolun said:

    I just don't understand what prompts people to do these things...
     

    Shits given: 0


  • ♿ (Parody)

    @Aeolun said:

    I just don't understand what prompts people to do these things... Can anyone think of a good reason for someone to do something like this?

    I think you just don't understand the importance of optimization. Extra function calls and existence checks can be the difference between a sleek, smooth user experience and a sluggish computer that no one wants to use.



  • @dhromed said:

    @Aeolun said:

    I just don't understand what prompts people to do these things...
     

    Shits given: 0

    shutup2.



  • Nice formatting. No idea why it's like it is but I have a feeling it's a poor man's $('#' + i + ', #' + j).hide();.



  • @MiffTheFox said:

    Nice formatting. No idea why it's like it is but I have a feeling it's a poor man's $('#' + i + ', #' + j).hide();.
     

     

    Using jQuery seems to be more "poors man" solution. Or more "lazy man" solution.

    I wonder why people use jQuery, with all overhead, in cases where standard JavaSccript is enough.



  •  I'm betting it's debug code. OC can call those functions to turn off annoying elements while s/he's worring about other stuff.  Are the functions called at all?

     

    ~Sticky



  • @spamcourt said:

    @MiffTheFox said:

    Nice formatting. No idea why it's like it is but I have a feeling it's a poor man's $('#' + i + ', #' + j).hide();.
     

     

    Using jQuery seems to be more "poors man" solution. Or more "lazy man" solution.

    I wonder why people use jQuery, with all overhead, in cases where standard JavaSccript is enough.

    People use what they know. If the only thing you know is a hammer, everything becomes a nail.



  • @The_Assimilator said:

    @spamcourt said:

    @MiffTheFox said:

    Nice formatting. No idea why it's like it is but I have a feeling it's a poor man's $('#' + i + ', #' + j).hide();.
     

     

    Using jQuery seems to be more "poors man" solution. Or more "lazy man" solution.

    I wonder why people use jQuery, with all overhead, in cases where standard JavaSccript is enough.

    People use what they know. If the only thing you know is a hammer, everything becomes a nail your thumb.

    FTFY :)



  • @spamcourt said:

    Using jQuery seems to be more "poors man" solution. Or more "lazy man" solution.

    I wonder why people use jQuery, with all overhead, in cases where standard JavaSccript is enough.

    Sorry this is a load of bullshit, I also usually want to punch developers in the face that say this. jQuery basically stops you from having to worry about the fact the fact that every browser goes and implements every feature slightly differently. I supposed you can go around patching stuff and writing your own methods which aren't as well tested and it is dubious to whether they are any faster.

     



  • @spamcourt said:

    I wonder why people use jQuery, with all overhead, in cases where standard JavaSccript is enough.

    Because DOM blows? Because the overhead of jQuery isn't much? Hell, you don't even know how big this project is, but if it's more than 100 lines it's worth having jQuery.



  • @lucas said:

    Sorry this is a load of bullshit, I also usually want to punch developers in the face that say this. jQuery basically stops you from having to worry about the fact the fact that every browser goes and implements every feature slightly differently. I supposed you can go around patching stuff and writing your own methods which aren't as well tested and it is dubious to whether they are any faster.

    "I wonder why people use C, with all overhead, in cases where standard assembly is enough."


  • Considered Harmful

    There are legitimate situations where you want to avoid depending on largish external libraries, but they're less common. I try to use native DOM in my Greasemonkey scripts, for example, because I've found that importing jQuery can either slow or completely break certain sites; luckily, I can depend on the user-agent being well-defined, so I can safely assume features like querySelectorAll, so it's not terrible. Another such situation is when you're writing another library for other people to use, you can a) extend jQuery and limit your userbase, b) support several popular frameworks and maintain all of them, or c) write your own very lightweight helpers and scope them privately.



  • @joe.edwards said:

    There are legitimate situations where you want to avoid depending on largish external libraries, but they're less common. I try to use native DOM in my Greasemonkey scripts, for example, because I've found that importing jQuery can either slow or completely break certain sites; luckily, I can depend on the user-agent being well-defined, so I can safely assume features like querySelectorAll, so it's not terrible. Another such situation is when you're writing another library for other people to use, you can a) extend jQuery and limit your userbase, b) support several popular frameworks and maintain all of them, or c) write your own very lightweight helpers and scope them privately.

    Of course there are always edge cases (although if I was making a library to redistribute I'd just use jQuery, because who the fuck isn't using it nowadays?) but your default mode should be to use jQuery unless there's a very good reason not to.


  • Considered Harmful

    @morbiuswilters said:

    (although if I was making a library to redistribute I'd just use jQuery, because who the fuck isn't using it nowadays?)

    AFAIK, there are still people using Prototype, YUI, mooTools, et al and then there's a new wave of MVC templating engines like AngularJS.



  • @joe.edwards said:

    Prototype, YUI, mooTools

    There are still people who shit in an outhouse and wipe their asses with a corncob. Why do I care about backwards-ass fuckwits?

    @joe.edwards said:

    ..then there's a new wave of MVC templating engines like AngularJS.

    Yeah, but a lot of those work alongside jQuery, or even depend on it outright. jQuery is there to provide a compatibility layer and to make working with the DOM less shitty. It's not a full application framework.



  • @morbiuswilters said:

    @lucas said:
    Sorry this is a load of bullshit, I also usually want to punch developers in the face that say this. jQuery basically stops you from having to worry about the fact the fact that every browser goes and implements every feature slightly differently. I supposed you can go around patching stuff and writing your own methods which aren't as well tested and it is dubious to whether they are any faster.

    "I wonder why people use C standard assembly , with all overhead, in cases where standard assembly

    handcrafted binary opcodes and operands is enough."

     

    Better..

    0100
    0101 1170
    0102 7001
    0102 3170
    0103 1170
    0104 7710
    0107 7402
    0170 0000

     (Written from memory and not tested).

     Any yes, I cheated and used Octal!

     


  • Considered Harmful

    @TheCPUWizard said:

    Written from memory

    You never miss any opportunity to flash us your e-peen, huh?



  • @joe.edwards said:

    @TheCPUWizard said:
    Written from memory

    You never miss any opportunity to flash us your e-peen, huh?

    Is that what that is? I thought an earthworm got left in the sun and shriveled up and died on the forum sidewalk.



  • @lucas said:

    @spamcourt said:

    Using jQuery seems to be more "poors man" solution. Or more "lazy man" solution.

    I wonder why people use jQuery, with all overhead, in cases where standard JavaSccript is enough.

    Sorry this is a load of bullshit, I also usually want to punch developers in the face that say this. jQuery basically stops you from having to worry about the fact the fact that every browser goes and implements every feature slightly differently. I supposed you can go around patching stuff and writing your own methods which aren't as well tested and it is dubious to whether they are any faster.

     

    Using jQuery also makes people think that they know JavaScript because they can use jQuery when really they have no fucking idea what they're doing :)


  • Considered Harmful

    @gu3st said:

    @lucas said:

    @spamcourt said:

    Using jQuery seems to be more "poors man" solution. Or more "lazy man" solution.

    I wonder why people use jQuery, with all overhead, in cases where standard JavaSccript is enough.

    Sorry this is a load of bullshit, I also usually want to punch developers in the face that say this. jQuery basically stops you from having to worry about the fact the fact that every browser goes and implements every feature slightly differently. I supposed you can go around patching stuff and writing your own methods which aren't as well tested and it is dubious to whether they are any faster.

     

    Using jQuery also makes people think that they know JavaScript because they can use jQuery when really they have no fucking idea what they're doing :)


    If there's one thing jQuery has done for the kiddie level scripters, it's made people use actual closures instead of eval-y things like setTimeout with a (usually poorly constructed) string argument.



  • I wonder if the opponents of jQuery are the people that cut their teeth with DHTML (is that even a term anymore?) 15 years ago with shit like:

    MoveElement(obj, x, y)

    {
     if (document.layers)
     {
      document.layers[obj].left = x;
      document.layers[obj].top = y;
     }
     else if (document.all)
     {
      document.all[obj].style.x = x;
      document.all[obj].style.y = y;
     }
     else if (document.getElementById(obj))
     {
      document.getElementById(obj).style.x = x;
      document.getElementById(obj).style.y = y;
     }
    }

    and

    HideElement(obj)
    {
     if (document.layers)
     {
       document.layers[obj].visibility = "hidden";
     }
     else if (document.all)
     {
      document.all[obj].style.visibity = "hide";
     }
     else if (document.getElementById(obj))
     {
      document.getElementById(obj).style.visibility = "hide";
     }
    }

    Yeah, that's right, layers and document.all. If you could make something work in both NN4 and IE4, you were king shit back then.



  •  @gu3st said:

    Using jQuery also makes people think that they know JavaScript because they can use jQuery when really they have no fucking idea what they're doing :)

     One could make that statement about any programming language or framework.

     



  • @Nexzus said:

    Yeah, that's right, layers and document.all. If you could make something work in both NN4 and IE4, you were king shit back then.

    Higher in the food chain were the gurus who could write java applets (remember the lake)? Good times.



  • @joe.edwards said:

    @TheCPUWizard said:
    Written from memory

    You never miss any opportunity to flash us your e-peen, huh?

    Guys CPU Wizard owns his own company... in New York City! And Intel gives him prototype CPUs to test. You don't even come close to understanding how great TheCPUWizard is. The world literally revolves around him.



  • @blakeyrat said:

    Guys CPU Wizard owns his own company... in New York City!

    I own my own company, but we're incorporated in Slovenia (or Slovakia.. I can never remember which). That's because they have, like, the weakest enforcement of human trafficking laws you can imagine. I mean, it's almost a joke..



  • @morbiuswilters said:

    @blakeyrat said:
    Guys CPU Wizard owns his own company... in New York City!

    I own my own company, but we're incorporated in Slovenia (or Slovakia.. I can never remember which). That's because they have, like, the weakest enforcement of human trafficking laws you can imagine. I mean, it's almost a joke..

    As far as weak law enforcement goes, Haiti runs circle around Slov*a. Once their president hired street gangsters to rape and kill a stubborn female police officer. Only problem is that wine palm can be brutal on the liver and polluted water supplies make for lousy kidneys, so options are limited for organ shoppers.



  • @Ronald said:

    As far as weak law enforcement goes, Haiti runs circle around Slov*a.

    I don't want weak enforcement of all laws, just the human trafficking ones. Or else the Mafia will try to take a cut of my human trafficking profits.

    @Ronald said:

    Only problem is that wine palm can be brutal on the liver and polluted water supplies make for lousy kidneys, so options are limited for organ shoppers.

    Pfft.. only if you go for the adults.



  • @Nexzus said:

    I wonder if the opponents of jQuery are the people that cut their teeth with DHTML (is that even a term anymore?) 15 years ago with shit like:

    (snip)

    Yeah, that's right, layers and document.all. If you could make something work in both NN4 and IE4, you were king shit back then.

    I still like to throw around the term DHTML.

    I started using jQuery due to the difference that kicked off the second browser war [Citation Needed]:

    if (typeof XMLHttpRequest === "undefined") {
      XMLHttpRequest = function () {
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
        catch (e) {}
        try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
        catch (e) {}
        try { return new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) {}
        // Microsoft.XMLHTTP points to Msxml2.XMLHTTP and is redundant
        throw new Error("This browser does not support XMLHttpRequest.");
      };
    }


  • @spamcourt said:

    I wonder why people use jQuery, with all overhead, in cases where standard JavaSccript is enough.

    Because you're clearly a troll, that's why. You live under bridges and you left the darkspear tribe because you didn't think they were provocative enough.

    You know what? I'll keep an open mind. I'll assume there are cases somewhere out there where people have javascripts which don't want to interact with the DOM in any way (or at least barely at all). I know advertising code likes to avoid jQuery because of overhead (I like to stay away from advertising code... it's nearly always a minefield). You can document dot write that to the bank.



  • @Shoreline said:

    You can document dot write that to the bank.

    Best javascript joke since undefined!



  • @Shoreline said:

    You know what? I'll keep an open mind. I'll assume there are cases somewhere out there where people have javascripts which don't want to interact with the DOM in any way (or at least barely at all). I know advertising code likes to avoid jQuery because of overhead (I like to stay away from advertising code... it's nearly always a minefield). You can document dot write that to the bank.

    There's an entire industry of third-party JavaScript files which are installed on arbitrary sites. Those scripts can't assume the presence of jQuery or any other JavaScript library*. But they do interact with the DOM. Very few of them have anything to do with advertising.

    *) they also can't assume the load event has or has not happened at the time they first execute, only IE has a DOM call to check that information. Open source browsers will gain that critical functionality in approximately... heat-death of universe.



  • @blakeyrat said:

    *) they also can't assume the load event has or has not happened at the time they first execute, only IE has a DOM call to check that information. Open source browsers will gain that critical functionality in approximately... heat-death of universe.

    The only reason you would ever need to wait until the page completely finished loading - along with every image on the page - before allowing your interface to be usable would be if you were designing a Community Server clone.

    Blakey, this may come as a surprise to you, but scripts can access and modify the page while it loads. A script is guaranteed to be able to interact with anything lexically before it in the HTML immediately when the script starts execution. Well, at least in open source browsers. Not sure about IE.



  • @Ben L. said:

    The only reason you would ever need to wait until the page completely finished loading - along with every image on the page - before allowing your interface to be usable would be if you were designing a Community Server clone.

    I can think of several reasons why you'd want to know if the UI had finished loading..

    @Ben L. said:

    Blakey, this may come as a surprise to you, but scripts can access and modify the page while it loads. A script is guaranteed to be able to interact with anything lexically before it in the HTML immediately when the script starts execution. Well, at least in open source browsers. Not sure about IE.

    Oh shit. Blakey's gonna eviscerate him.



  • @eViLegion said:

    @dhromed said:
    @Aeolun said:
    I just don't understand what prompts people to do these things...
    Shits given: 0
    shutup2('dhromed', 'Aeolun').
    FTFY.

     



  • @Anonymouse said:

    @eViLegion said:

    @dhromed said:
    @Aeolun said:
    I just don't understand what prompts people to do these things...
    Shits given: 0
    shutup2('dhromed', 'Aeolun').
    FTFY.

     

    *glitch*

    I don't understand why boomzilla started this thread with a made-up quote. So weird.

     



  • @Shoreline said:

    You live under bridges and you left the darkspear tribe because you didn't think they were provocative enough.
     

    Have you read Ftrain?



  • @dhromed said:

    @Shoreline said:

    You live under bridges and you left the darkspear tribe because you didn't think they were provocative enough.
     

    Have you read Ftrain?

    I have now! Looks like some kind of US political satire.



  • @Shoreline said:

    US political satire.
     

    I'm super weirded out that you saw US politcal satire in there. 

    Hint: it's about operating systems.

     

    Maybe I should try to be less subtle next time.


Log in to reply