How can this run without an error?? Or: Why 'On Error Resume Next' + Poor Programmer = WTF



  • More reason why, while VBScript is NOT the real WTF, most programmers who "program" (and I use that term loosely) in it are.

    Found this from the guy I replaced (indentation and spacing, or lack thereof, is left as-is): 

    if pIdCustomer=0 then
    pPriceColumn="retail"
    else
    mySQL="select priceColumn from customers where idCustomer='" & pIdCustomer & "'"

    call getFromDatabase(mySQL, rsTemp, "ViewItem_1")

    pPriceColumn=rstemp("pricecolumn")
    end if


    if pIdCustomerType=4 or pIdCustomerType=5 or pIdCustomer=17873 or pIdCustomer=21385 then
    mySQL="Select accessLevel,groupId from customers where idcustomer="&pidCustomer

    call getfromDatabase(mySQL, rstemp, "comersus_customerUtilitiesMenu.asp")

    end if
    if not rstemp.eof then
    paccessLevel=rsTemp("accessLevel")
    pIdGroup=rsTemp("groupId")
    else
    paccessLevel=1
    pIdGroup=0
    end if

    Basically to sum it up: The way this is written, without On Error Resume Next (which every page has) it will fail if the type/id check doesn't get called, because "rstemp" (what a descriptive name, eh?) would only have the value of the prior query checking for the priceColumn, and wouldn't have any columns called "accessLevel" or "groupId".  Not to mention that it's not using Option Explicit, so any variable declared inside the If block is automatically what amounts to global level and visible to everything.

    sigh It's days like this I hate being a programmer. 

     EDIT:  And, just for bonus WTFery, here's some javascript from the same page (The real WTF is the naming):

    <!--
    function smt(){
    //alert("fired")
    document.getElementById("frm").submit();
    }
    function rpt(){
    //alert("fired")
    document.getElementById("frm2").submit();
    }
    function namrpt(){
    //alert("fired")
    document.getElementById("frm3").submit();
    }
    //-->

     



  • @ObiWayneKenobi said:

    More reason why, while VBScript is NOT the real WTF, most programmers who "program" (and I use that term loosely) in it are.

    Found this from the guy I replaced (indentation and spacing, or lack thereof, is left as-is): 

    if pIdCustomer=0 then
    pPriceColumn="retail"
    else
    mySQL="select priceColumn from customers where idCustomer='" & pIdCustomer & "'"

    call getFromDatabase(mySQL, rsTemp, "ViewItem_1")

    pPriceColumn=rstemp("pricecolumn")
    end if


    if pIdCustomerType=4 or pIdCustomerType=5 or pIdCustomer=17873 or pIdCustomer=21385 then
    mySQL="Select accessLevel,groupId from customers where idcustomer="&pidCustomer

    call getfromDatabase(mySQL, rstemp, "comersus_customerUtilitiesMenu.asp")

    end if
    if not rstemp.eof then
    paccessLevel=rsTemp("accessLevel")
    pIdGroup=rsTemp("groupId")
    else
    paccessLevel=1
    pIdGroup=0
    end if

    Basically to sum it up: The way this is written, without On Error Resume Next (which every page has) it will fail if the type/id check doesn't get called, because "rstemp" (what a descriptive name, eh?) would only have the value of the prior query checking for the priceColumn, and wouldn't have any columns called "accessLevel" or "groupId".  Not to mention that it's not using Option Explicit, so any variable declared inside the If block is automatically what amounts to global level and visible to everything.

    sigh It's days like this I hate being a programmer. 

     EDIT:  And, just for bonus WTFery, here's some javascript from the same page (The real WTF is the naming):

    <!--
    function smt(){
    //alert("fired")
    document.getElementById("frm").submit();
    }
    function rpt(){
    //alert("fired")
    document.getElementById("frm2").submit();
    }
    function namrpt(){
    //alert("fired")
    document.getElementById("frm3").submit();
    }
    //-->

     

     

     

    On Error Resume Next is cruise control to cooooooool....

    Oh yeah, I copied/pasted the OP.  I thought I'd give MasterAsshat something to do. 



  • @Lysis said:

    //alert("fired")
     

    Perhaps this is how he keeps from getting fired, despite this WTF? 



  • Good god, I think I've worked with whoever developed this before!  I dunno, the variable names are a bit too descriptive, though... 



  • @Lysis said:

    Oh yeah, I copied/pasted the OP.  I thought I'd give MasterAsshat something to do. 

    You are pulling on everybody's nerves here, just to get at MasterPlanSoftware? What a moron you are. I pity you.



  • The Real WTF is the indentation and the proper use of capital letters, or rather lack of them.

    <font size="-3">W00t, my tag made it to the front page, so the rebalancing is complete. Although, somehow, the cloud doesn't look more balanced than it was. Anyway, one last time,..</font>



  • I love it when people name their recordsets "rs". But, alas, what if I use more than one in a page? Ah, solution!

    Set rs = CreateObject("ADODB.RecordSet")

    Set rs1 = CreateObject("ADODB.RecordSet")

    Set rs2 = CreateObject("ADODB.RecordSet")

    That's right, it's even zero-based.

     And don't forget to set up 3 different sql variables for those recordsets so each query is kept separate. What's with the close method? Why would I need that, doesn't the ASP clean up its own garbage at the end of the page? The server only processes one page at a time, right?



  • @Arenzael said:

    I love it when people name their recordsets "rs". But, alas, what if I use more than one in a page? Ah, solution!

    Set rs = CreateObject("ADODB.RecordSet")

    Set rs1 = CreateObject("ADODB.RecordSet")

    Set rs2 = CreateObject("ADODB.RecordSet")

    That's right, it's even zero-based.

     And don't forget to set up 3 different sql variables for those recordsets so each query is kept separate. What's with the close method? Why would I need that, doesn't the ASP clean up its own garbage at the end of the page? The server only processes one page at a time, right?

    My quote above actually referred to this very practice.  I worked with a developer who (I guess) learned VB before he learned PHP.  His PHP code all looked like:

    $r = mysql_query('select id from '.$_GET['tbl'].' where name=''.$_GET['name'].''', $DB));

    while ($oRS = mysql_fetch_object($r)) {

        $oRS1 = mysql_fetch_object(mysql_query('select foo from '.$_GET['tbl'].' where id='.$oRS->id, $DB));

        echo('<table><tr><td>'.$oRS1->foo.'</td></tr></table>'); 

     

    If that looks illegible to you because you don't know PHP, don't worry, it actually is!  And yes, this developer passed table names as GET vars.  And yes, he did not know about query escaping.  And yes, he would actually select out ids from a table and then select out individual fields in a loop -- sometimes the loops were several levels deep, resulting in 14,000+ queries on a page!  And yes, he used tables with one row and one column instead of divs because "divs are rendered too slow".  Oh, and this guy really had a problem with people of Irish descent because their names always seemed to break his "perfect code".  He actually told me once "those PHP guys need to do something about these Irish people because they keep breaking our applications!"  I guess he figured genocide was the only option... 



  •  Being pretty knowledgeable of VBariants I'm on VB boards a lot (especially devshed where I moderate VB) I can't tell you how many times someone has posted a code snippet with the infamous "doesn't work" error. After going around in circles for a while someone usually says:

    "I can't believe you aren't getting an error"

    Then the OP posts more of the code

    Then we see ...

    On Error Resume Next

    If the OP had simply been willing to listen to the error messages VB throws out usually they'd find the obvious. 

    I suggest that all instances of On Error Resume Next be replaced with On Error Shoot Developer In The Head

    Fools like this make us all look bad and help prop up the "VB is a script kiddie toy" image when, actually, it is rather useful for some things so long as idiots like this don't get near it.

     



  • I'm inclinded to agree - this guy seems to have either picked up a "Teach Yourself VBScript In 10 Minutes", or deliberately obfuscated his code for job security.  The whole fucking codebase is loaded with shit like this.  Loops within loops within three levels of if statements that do the exact same loop with a couple of lines changed, alternate between outputting all HTML in Response.Write and using the <%= %> tags, barely any indentation, variable names that read like heiroglyphics.

    Perhaps the biggest WTF of all is that there are several thousand pages of this stuff.  So even if I were to find the time to refactor them here and there to not be spaghetti, it would take me about 10 years to refactor all of it... assuming that I could refactor one page per day.



  • "I suggest that all instances of On Error Resume Next be replaced with On Error Shoot Developer In The Head"

    Search Google/codesearch and you'll find over 320,000 occurances of On Error Resume Next. Genocide of VB developers!

    http://www.google.com/codesearch?q=On+Error+Resume+Next&hl=en&btnG=Search+Code



  • @JonAxtell said:

    "I suggest that all instances of On Error Resume Next be replaced with On Error Shoot Developer In The Head"

    Search Google/codesearch and you'll find over 320,000 occurances of On Error Resume Next. Genocide of VB developers!

    http://www.google.com/codesearch?q=On+Error+Resume+Next&hl=en&btnG=Search+Code

    I always use it on my resize event handlers...
    and the correct search is: http://www.google.com/codesearch?hl=en&lr=&q=%22On+Error+Resume+Next%22&btnG=Search


  • @TheRider said:

    @Lysis said:

    Oh yeah, I copied/pasted the OP.  I thought I'd give MasterAsshat something to do. 

    You are pulling on everybody's nerves here, just to get at MasterPlanSoftware? What a moron you are. I pity you.
     

     

    QQ 


Log in to reply
 

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