Really dynamic webpages



  • Just started a new job (which I absolutely hate and might quit, but that's another story) on Monday.  I found these  admist a huge Classic ASP application (I'm talking over 13,000 ASP files and over 1,000 folders).  Not sure if they're really WTFs, but they sure seem WTF-y to me; I've never seen anything like this before. Sorry, I don't know how to format the code all pretty-like:

    Function GetRequiredColor(byval blnRequired)
     'response.write(blnRequired)
     If blnRequired Then
      GetRequiredColor = "#FF0000"
     Else
      GetRequiredColor = "#FFFFFF"
     End If
    End Function

    Function RequiredMarker(byval blnRequired)
     If blnRequired Then
      RequiredMarker = "<font color=""#FF0000"">*</font>&nbsp;"
     Else
      RequiredMarker = "&nbsp;&nbsp;"
     End If
    End Function

    Function PrintWindowBottomButton(str_DirLevel, str_Caption, str_Position, str_Title, str_PageHeader, str_PageFooter, str_portrait, str_CloseBottomWindow, str_LeftMargin, str_RightMargin, str_TopMargin, str_BottomMargin, str_BackBtn)

    If str_DirLevel = "" Then
     str_DirLevel = "../../../"
    End If

    If str_Caption = "" Then
     str_Caption = "Print"
    End If

    If str_Position = "" Then
     str_Position = "Center"
    End If

    If str_Title = "" Then
     str_Title = "Click here to print!"
    End If

    If str_PageHeader = "" Then
     str_PageHeader = ""
    End If

    If str_PageFooter = "" Then
     str_PageFooter = "Page &p of &P"
    End If

    If str_Portrait = "" or LCASE(str_Portrait) = "true" Then
     str_Portrait = "true"
    Else
     str_Portrait = "false"
    End If

    With Response
     .Write "<script> " & vbcrlf
     .Write "function PrintBottomWindow(strPrintHead, strPrintFoot)"  & vbcrlf
     .Write "{ "  & vbcrlf
      .Write "if (navigator.appName == 'Microsoft Internet Explorer')" & vbcrlf
      .Write "{ "  & vbcrlf
      .Write "document.factory.printing.header = '" & str_PageHeader & "'; " & vbcrlf
      .Write "document.factory.printing.footer = '" & str_PageFooter & "';" & vbcrlf
      .Write "document.factory.printing.portrait = " & str_Portrait & ";" & vbcrlf
      If Len(str_LeftMargin) > 0 Then .Write "document.factory.printing.leftMargin = " & str_LeftMargin & "; " & vbcrlf
      If Len(str_TopMargin) > 0 Then .Write "document.factory.printing.topMargin = " & str_TopMargin & "; " & vbcrlf
      If Len(str_RightMargin) > 0 Then .Write "document.factory.printing.rightMargin = " & str_RightMargin & "; " & vbcrlf
      If Len(str_BottomMargin) > 0 Then .Write "document.factory.printing.bottomMargin = " & str_BottomMargin & "; " & vbcrlf
      .Write "document.factory.printing.Print(true); " & vbcrlf
      .Write "} " & vbcrlf
      .Write "else "  & vbcrlf
      .Write "{ "  & vbcrlf
      .Write "window.print();" & vbcrlf
      .Write "} "  & vbcrlf
      .Write "} " & vbcrlf
     .Write "</script> " & vbcrlf
     .Write "<" & str_Position & "> " & vbcrlf
     .Write "<input type='button' name='btnPrintBottom' id='btnPrintBottom'  class='formbutt' title='" & str_Title & "' value='" & str_Caption & "' onclick='PrintBottomWindow();'>"
     If str_CloseBottomWindow <> "" and LCASE(str_CloseBottomWindow) <> "true" Then
      .Write "&nbsp;&nbsp;<input type='button' name='btnCloseBottom' id='btnCloseBottom'  class='formbutt' value='" & str_CloseBottomWindow & "' onclick='window.close();'>"
     End If
     If str_BackBtn <> "" and LCASE(str_BackBtn) <> "false" Then
      .Write "&nbsp;&nbsp;<input type='button' name='btnBack' id='btnBack'  class='formbutt' value='" & str_BackBtn & "' onclick='history.back();'>"
     End If
     .Write "</" & str_Position & "><br>" & vbcrlf
    End With
    End Function</" ? & str_Position>



  • That looks... ugh... lovely.  Why on earth would you output Javascript from VBScript?? 

    Reminds me of why I dislike Classic ASP - I can work with it if I have to, but I like it about as much as a visit to the dentist.



  • @ObiWayneKenobi said:

    That looks... ugh... lovely.  Why on earth would you output Javascript from VBScript?? 

    Reminds me of why I dislike Classic ASP - I can work with it if I have to, but I like it about as much as a visit to the dentist.

    I would take a visit to my dentist over that *thing* any time



  • Yes this is a WTF.

    The required colors/markers should be handled with CSS. The directory level should always assume from root., if the root of the app is not the root of the web, then a global.asa file can set the web root (similar to .Net where you use the web.config file).  The rest of it?  An attempt to format a page specifically when you never really know what browser the user is using and what resolution they have, this is just asking for trouble.



  • @ObiWayneKenobi said:

    That looks... ugh... lovely.  Why on earth would you output Javascript from VBScript?? 

    Reminds me of why I dislike Classic ASP - I can work with it if I have to, but I like it about as much as a visit to the dentist.

    I had an outsourced programmer produce the *exact* same kind of code, except it was javascript wrapped in PHP echoes, rather than VBScript.  The boss canned him a month or so later.

     
    About two years later, the boss decided to start outsourcing to the lowest bidder.  Again.  The lowest bidder produced terrible code.  Again.

    I found a new employer.
     



  • Yep the only time I have used vbscript or PHP to output javascript was to fill data for some arrays (think marquee styled stuff) that was dynamic based on what was pulled from the DB on page load. Not the greatest, but only way that I could think to do it. (And I only did the array load in code, the rest of the routines and such went into the .js file)

    This stuff is just horrible.



  • Well, don't forget AJAX. In such a setting, generated JS CAN be useful (if you want to output JSON for example). But never ever outside, agreed. And that guy had no clue of CSS for real.



  • Since this is classic ASP, the code may be quite old.  Despite CSS being older than that, perhaps the person who wrote it wasn't quite used to using CSS and preferred to use FONT tags.  This is not a WTF unless you think that driving an older car with no airbags is a WTF.

    I (used to) do a lot of classic ASP and outputting JScript from VBScript was a very useful technique.  Using two languages, made it much easier to keep the server-side and client side environments separated in my head.  If you were writing in PHP, you wouldn't try to output client-side PHP would you?  However in this case, the language-not-specified-so-assume-JavaScript script doesn't use any ASP variables or database data so it should not have been wrapped in response.write.  The code should drop out of server-side ASP and just put in a normal script tag. Even better, it should be moved to a linked .JS file.



  • @ObiWayneKenobi said:

    Reminds me of why I dislike Classic ASP - I can work with it if I have to, but I like it about as much as a visit to the dentist.

    What you see here has nothing to do with any aspect, good or bad, of ASP-classic. This "programmer" would have produced the exact same crap if he'd been coding VB.Net, or C#.Net, or PHP, or Ruby, or Lisp.

     

    Well.

     

    Maybe not Lisp.



  • @dhromed said:

    Maybe not Lisp.

    Stupidity can be implemented in every turing-complete language. 



  • @ammoQ said:

    @dhromed said:

    Maybe not Lisp.

    Stupidity can be implemented in every turing-complete language. 

    Stupidity has been implemented in every turing-complete language. Also in pretty much every other language that humans can write.



  • I'm dealing with Clbuttic ASP too. Aargh, such pain!!



  • I've actually seen good Classic ASP code... once.  In a book.  Or maybe on a webpage.  But most of it has been scary stuff.  Like I said above, the code here (well actually I just left the job for a variety of reasons) has includes that reference other includes that reference other includes, with some variables not being in any common includes but still set somewhere.  They used what they called a "Page Set" which meant you had for example:  foo.asp (handles layout, although everything is done via function calls that write out HTML), foo_inc.asp (variables/methods for foo.asp, usually one long method/logic), foo_js.asp (JavaScript for foo.asp - why on earth this wasn't in its own JS file is beyond me [I guess so you couldn't view it directly in the browser?] especially since most of the xxx_js.asp files had similar javascript).  The fact that foo.asp and foo_inc.asp both included page logic made it a treat to look through.

    I so much prefer ASP.NET.  Much cleaner and friendlier to separate logic and presentation without resorting to Clbuttic ASP weirdness



  • Fro what I've seen ASP.NET seems to have its own share of WTFs though. I mean, ViewState, anyone?



  • @PSWorx said:

    Fro what I've seen ASP.NET seems to have its own share of WTFs though. I mean, ViewState, anyone?

    Touche.   But still not as bad as Clbuttic ASP.

    Oh, I have another brief bit from this same huge app:  A comment that reads something like "We will uncomment this variable once we have checked the code to make sure it's not declared anywhere else".  You'd think that would be a sign that something needs to be consolidated.  It's also a big red flag when being asked to change a line of text takes over a day and a half to locate the variable where the text is set, and still being unable to find it.



  • @TheRubyWarlock said:

    It's also a big red flag when being asked to change a line of text takes over a day and a half to locate the variable where the text is set, and still being unable to find it.

    Don't you have a Search feature?



  • @dhromed said:

    @TheRubyWarlock said:

    It's also a big red flag when being asked to change a line of text takes over a day and a half to locate the variable where the text is set, and still being unable to find it.

    Don't you have a Search feature?

    Yes, but it was not found in any of the files I looked at.  I did a Search, and it said not found.  So there was over 13,000 files to look through to try and find it.


Log in to reply