Logic



  • Useful variable and function names shortened for readability (the if-part of this was all on a single line nearly 1,000 characters long):

       if (a(!b(!c(d(e()[f()])).g(h(),i(),j(k()[2])))) > m(n(),o(),p(q().r()))) {...}

    OBTW, e(), h() and q() are hierarchies that contain database hits.


    Why oh why do people write code like this?



  • That looks like minified JS.  Someone actually did this by-hand and intentionally?!



  • @C-Octothorpe said:

    That looks like minified JS.  Someone actually did this by-hand and intentionally?!

    Well he specifically said he shortened the variables for readability...



  • @Sutherlands said:

    @C-Octothorpe said:

    That looks like minified JS.  Someone actually did this by-hand and intentionally?!

    Well he specifically said he shortened the variables for readability...
    Ah, parsing error on my part.  I read it as the author of the code shortened the variables for "readability"...



  • @C-Octothorpe said:

    That looks like minified JS.  Someone actually did this by-hand and intentionally?!

    JS that does DB calls? I don't think my mind can fully comprehend such horror.



  • "JS" only came into the conversation from the "minified JS?" comment; the code could just as easily be Java or one of the C family. Of course, this is a snoofle WTF, so JS doing a DB call isn't entirely implausible...

     



  • @The_Assimilator said:

    @C-Octothorpe said:

    That looks like minified JS.  Someone actually did this by-hand and intentionally?!

    JS that does DB calls? I don't think my mind can fully comprehend such horror.

     

    Not directly (as far as I know and hope), but you can do this:

    var a_returner = false;
    function a()
    {
       $.ajax({
         url:"snooflecorp.com/WebService/GetDataBaseResultsForA.java",
         async: false,
         success: function() { a_returner = true; },
         fail: function() { a_returner = false; }
       });
      
       return a_returner;
    }

    // Copy and paste for each other variable

    That way not only do you have 26 database hits, but you also have 26 asynchronous web requests!

     


  • Winner of the 2016 Presidential Election

    @Lorne Kates said:

    That way not only do you have 26 database hits, but you also have 26 asynchronous web requests!

    Don't forget 26! = 403291461126605635584000000 possible orderings of return callbacks.



  • Good grief.  Has this programmer not heard of using temporary variables?!


  • Winner of the 2016 Presidential Election

    @Anketam said:

    Good grief.  Has this programmer not heard of using temporary variables?!

    Maybe he has a Lisp.



  • @Lorne Kates said:

    var a_returner = false;
    function a()
    {
       $.ajax({
         url:"snooflecorp.com/WebService/GetDataBaseResultsForA.java",
         async: false,
         success: function() { a_returner = true; },
         fail: function() { a_returner = false; }
       });
      
       return a_returner;
    }

    // Copy and paste for each other variable

    That way not only do you have 26 database hits, but you also have 26 asynchronous web requests!

     

    That "async: false," bit makes it a bit less asynchronous than you'd expect, I think.



  • @The_Assimilator said:

    @C-Octothorpe said:

    That looks like minified JS.  Someone actually did this by-hand and intentionally?!

    JS that does DB calls? I don't think my mind can fully comprehend such horror.
    I said it looks like minified JS, not that it is.

    In any case, I've known developers who would think that a "one-liner" like this is elegant, or worse yet, that this saves memory because you're not creating local variables...



  • @Adriano said:

    @Lorne Kates said:

    var a_returner = false;
    function a()
    {
       $.ajax({
         url:"snooflecorp.com/WebService/GetDataBaseResultsForA.java",
         async: false,
         success: function() { a_returner = true; },
         fail: function() { a_returner = false; }
       });
      
       return a_returner;
    }

    // Copy and paste for each other variable

    That way not only do you have 26 database hits, but you also have 26 asynchronous web requests!

     

    That "async: false," bit makes it a bit less asynchronous than you'd expect, I think.

    Well, if he expected to do such a long if-clause with asynchronous calls, then I honestly don't know what he expected!



  • He really needed to do async: super-false



  • @snoofle said:

    Why oh why do people write code like this?
    Because somebody made fun of them for writing code that was clear, but verbose.

     



  • Almost as bad as method/property chaining.

    someobject.someProperty().someOtherProperty().yetAnotherMethod().andStillOneMore().andAFinalOneForShitsAndGiggles().toString().toLower().equals('...");



  • @All: It's pure Java. The variable names were shortened by me for posting. The run time for this one "line" of code is, on average, approximately 94.7 seconds (yes, ninety four point seven seconds).

    True, the db hits are fairly reasonable for what they do, and the caching of the query results are side affects (seriously!) buried deep in the bowels of the system, but still, this could trivially have been broken down into something way more readable (I wound up breaking it down into a bunch of sequential statements, each making a single call).



  • @Adriano said:

    @Lorne Kates said:

    var a_returner = false;
    function a()
    {
       $.ajax({
         url:"snooflecorp.com/WebService/GetDataBaseResultsForA.java",
         async: false,
         success: function() { a_returner = true; },
         fail: function() { a_returner = false; }
       });
      
       return a_returner;
    }

    // Copy and paste for each other variable

    That way not only do you have 26 database hits, but you also have 26 asynchronous web requests!

     

    That "async: false," bit makes it a bit less asynchronous than you'd expect, I think.

    It allows returning a meaningful a_returner though.

     



  • @Adriano said:

    That "async: false," bit makes it a bit less asynchronous than you'd expect, I think.
     

    It makes is synchronous enough for this small function become thread safe. There can still be 26 requests running at the same time, with the number of possible execution orderings calculated by joe.edwards.

     Also, thank god browser tabs are single threaded. Otherwise you'd at least double the possible execution orderings.

     



  • @snoofle said:

    Useful variable and function names shortened for readability (the if-part of this was all on a single line nearly 1,000 characters long):

       if (a(!b(!c(d(e()[f()])).g(h(),i(),j(k()[2])))) > m(n(),o(),p(q().r()))) {...}

    OBTW, e(), h() and q() are hierarchies that contain database hits.


    Why oh why do people write code like this?

    I don't think code like that is ever really so much written as grown. It's organic, like toe jam.



  • @Lorne Kates said:

    var a_returner = false;
    function a(sql)
    {
       $.ajax({
         url:"www.snooflecorp.com/WebService/QueryDatabase?sql=" + sql,
         async: false,
         success: function(data) { a_returner = data; },
         fail: function() { a_returner = null; }
       });
      
       return a_returner;
    }


    That way not only do you have 26 database hits, but you also have 26 asynchronous web requests!

    FTFY. Do you think the masterminds at SnoofleCorp would tolerate copy-pasting if you can make it generic?



  • @Lorne Kates said:

    @The_Assimilator said:

    @C-Octothorpe said:

    That looks like minified JS.  Someone actually did this by-hand and intentionally?!

    JS that does DB calls? I don't think my mind can fully comprehend such horror.

     

    Not directly (as far as I know and hope), but you can do this:

     

     

    Ever heard of Node.js? Sure, your code needs a webserver in some form, but since you are running a DB-server anyway...

     



  • @fire2k said:

    Ever heard of Node.js? Sure, your code needs a webserver in some form, but since you are running a DB-server anyway...
    You don't need Node.js, a web server or a database server. All you need is a standalone JS implementation with a sqlite binding.



  • @Zecc said:

    @fire2k said:

    Ever heard of Node.js? Sure, your code needs a webserver in some form, but since you are running a DB-server anyway...
    You don't need Node.js, a web server or a database server. All you need is a standalone JS implementation with a sqlite binding.

     

    Yes, technically SQLite is a database. Yes, there are also bindings to NoSQL and stuff.  I doubt the original "haha, javascript is awful"-poster does consider these things to be real and probably meant to say "calls to a relational database" or something like that... 

     



  • @C-Octothorpe said:

    That looks like minified JS.  Someone actually did this by-hand and intentionally?!

    To me, it has the aura of a long Excel formula. On the rare occasions that I find a spreadsheet with actual formulas in it, I usually find some horrendous, deeply nested formula written on one line just like this. Something as simple a switch statement becomes an abomination when expressed in Excel syntax, and if you mix in some string processing and error handling, its a migraine waiting to happen.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.