The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

logic

Last post 12-14-2012 10:34 PM by savar. 24 replies.
Page 1 of 1 (25 items)
Sort Posts: Previous Next
  • 12-13-2012 9:39 AM

    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?

    Randomize can be used to simplify almost any business problem; it is your friend!
  • 12-13-2012 9:43 AM In reply to

    Re: logic

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

  • 12-13-2012 9:45 AM In reply to

    Re: logic

    C-Octothorpe:

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

    Well he specifically said he shortened the variables for readability...
  • 12-13-2012 9:49 AM In reply to

    Re: logic

    Sutherlands:
    C-Octothorpe:

    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"...
  • 12-13-2012 10:00 AM In reply to

    Re: logic

    C-Octothorpe:

    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.
    <stryhf> why do people persist in continuing to write SHIT APPLICATIONS IN JAVA
    <stryhf> writing SHIT in JAVA doesn't make it ANY LESS SHITTY
    <stryhf> IT JUST MAKES IT SLOW ASS SHIT
  • 12-13-2012 10:16 AM In reply to

    • emurphy
    • Top 100 Contributor
    • Joined on 01-14-2005
    • Granada Hills, CA
    • Posts 576

    Re: logic

    "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...

     

  • 12-13-2012 10:28 AM In reply to

    Re: logic

    The_Assimilator:
    C-Octothorpe:

    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!

     


    HardwareGeek:

    <blink> and you're dead!



    "Where is grumpy cat?"
    - Mozilla's MOST ADVANCED USER!
  • 12-13-2012 10:35 AM In reply to

    Re: logic

    Lorne Kates:
    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.

    Signatures are stupid.
  • 12-13-2012 11:44 AM In reply to

    • Anketam
    • Top 150 Contributor
    • Joined on 10-12-2011
    • Nar Shaddaa
    • Posts 484

    Re: logic

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

    Project Manager: I don't know. I'm not allowed to talk directly to the customer. Apparently my grip on reality is too tight.
    - Weng
  • 12-13-2012 11:46 AM In reply to

    Re: logic

    Anketam:

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

    Maybe he has a Lisp.

    Signatures are stupid.
  • 12-13-2012 12:31 PM In reply to

    • Adriano
    • Not Ranked
    • Joined on 04-24-2008
    • Chile
    • Posts 43

    Re: logic

    Lorne Kates:

    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.
    Saludos
    Adriano
  • 12-13-2012 12:54 PM In reply to

    Re: logic

    The_Assimilator:
    C-Octothorpe:

    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...

  • 12-13-2012 1:06 PM In reply to

    Re: logic

    Adriano:
    Lorne Kates:

    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!

  • 12-13-2012 2:04 PM In reply to

    Re: logic

    He really needed to do async: super-false
  • 12-13-2012 2:12 PM In reply to

    Re: logic

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

     

  • 12-13-2012 2:38 PM In reply to

    Re: logic

    Almost as bad as method/property chaining.

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

  • 12-13-2012 2:43 PM In reply to

    Re: logic

    @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).

    Randomize can be used to simplify almost any business problem; it is your friend!
  • 12-13-2012 3:33 PM In reply to

    • Zecc
    • Top 25 Contributor
    • Joined on 06-12-2007
    • and hasn't left since.
    • Posts 2,063

    Re: logic

    Adriano:
    Lorne Kates:

    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.

     

    If mixed metaphors were illegal, I'd be having an indigestion.
    typeof NaN == 'number'
    var ò_ó, ಠ⁔ಠ, ᄒᆺᄒ, ᅙᅳᅙ, ᖛᨓᖜ, ꖴᅩꖴ, ఠᨋఠ; // Naming your variables is serious business
  • 12-13-2012 8:26 PM In reply to

    Re: logic

    Adriano:
    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.

     

  • 12-14-2012 7:43 AM In reply to

    Re: logic

    snoofle:

    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.
  • 12-14-2012 7:48 AM In reply to

    Re: logic

    Lorne Kates:

    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?
  • 12-14-2012 1:57 PM In reply to

    Re: logic

    Lorne Kates:

    The_Assimilator:
    C-Octothorpe:

    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...

     

    [quote user="blakeyrat"]Fuck you plant math article[/quote]
  • 12-14-2012 2:12 PM In reply to

    • Zecc
    • Top 25 Contributor
    • Joined on 06-12-2007
    • and hasn't left since.
    • Posts 2,063

    Re: logic

    fire2k:
    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.

    If mixed metaphors were illegal, I'd be having an indigestion.
    typeof NaN == 'number'
    var ò_ó, ಠ⁔ಠ, ᄒᆺᄒ, ᅙᅳᅙ, ᖛᨓᖜ, ꖴᅩꖴ, ఠᨋఠ; // Naming your variables is serious business
  • 12-14-2012 2:47 PM In reply to

    Re: logic

    Zecc:

    fire2k:
    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... 

     

    [quote user="blakeyrat"]Fuck you plant math article[/quote]
  • 12-14-2012 10:34 PM In reply to

    Re: logic

    C-Octothorpe:

    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.
Page 1 of 1 (25 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems