How to parse integers in jscript



  •  I was working on some classic asp code today, and, apparently the application has a lot of code that looks like this:

    var variableName = 0;     

    variableName = parseInt(Request.QueryString("variableName")(), 0);                

     

    Overwriting of default value set at variable creation? Check.

    Unnecessary () after the QueryString call? Check.

    Attempted use of radix (2nd parameter) as default value? Check. 

    Found everywhere in the codebase? Check. 

     

     Luckily, for some of these variables, someone thought to put an isNaN check later.



  • @NickAragua said:

    variableName = parseInt(Request.QueryString("variableName")(), 0);

    When I delete something like this from the code I work on, I feel I can breathe a bit better.  Does anybody else have a physical reaction to bad code? 



  • @arty said:

    Does anybody else have a physical reaction to bad code?

    Not really.. just emotional. I usually get pissed off.

    Side note: Why would anyone use JScript (do not confuse that with JavaScript) in ASP? If it's server side, why not just use VBScript?



  • @arty said:

    When I delete something like this from the code I work on, I feel I can breathe a bit better.  Does anybody else have a physical reaction to bad code? 

     

    I have many.. I think during the state of my nervous system is directly proportional to (amount_buggy_code * challenge_to_fix). Once I figure out the solution, or have a good idea, my stress levels go way down. Until then... theres no telling how unhealthy it is for me :)



  • @AbbydonKrafts said:

     

    Side note: Why would anyone use JScript (do not confuse that with JavaScript) in ASP? If it's server side, why not just use VBScript?

     

    In spite of its shortcomings, it is actually better than vbscript.

    Off the top of my head:

    • the ability to use try{...} catch{...}, instead of the abomination of "on error resume next"
    • semi-object oriented.  Custom JScript objects can make life a little easier.  VBScript can't do it at all.
    • Not forgiving of things like "domFoo" vs. "domFOO".  Makes code a little cleaner (personal pet peeve.)

    There are other reasons, but I can't be bothered to think of them right now.  I'm only glad I don't have to maintain ASP code at all any more...

     

    Also, there's no way to make VBScript not suck... 



  • VBScript has classes, actually. But I was surprised to learn that it has no "<font face="Courier New">On Error GoTo</font> somewhere" functionality. What's the purpose of the <font face="Courier New">Err</font> object, then?



  • @flinnb said:

    Not forgiving of things like "domFoo" vs. "domFOO".  Makes code a little cleaner (personal pet peeve.)

     I never used VBScript, and hate VB, but can you use Option Explicit and Option Strict in VBScript ?  This should help the case and other annoyances, but I agree its still very limited and I wouldn't recommend it.



  • @pitchingchris said:

    @flinnb said:

    Not forgiving of things like "domFoo" vs. "domFOO".  Makes code a little cleaner (personal pet peeve.)

     I never used VBScript, and hate VB, but can you use Option Explicit and Option Strict in VBScript ?  This should help the case and other annoyances, but I agree its still very limited and I wouldn't recommend it.

    <font face="Courier New">Option Explicit</font> makes declaring all variables mandatory, it has nothing to do with case. <font face="Courier New">Option Strict</font> doesn't exist in VBScript.

    The Real WTF is that the forum's editor doesn't support the TT element.



  • @flinnb said:

    the ability to use try{...} catch{...}, instead of the abomination of "on error resume next"

    Ahh.. ok. That would be a good selling point.

    @flinnb said:

    semi-object oriented. Custom JScript objects can make life a little easier. VBScript can't do it at all.

    As Spectre pointed out, VBScript has classes. I used to make class includes for things like encryption.

    @Spectre said:

    But I was surprised to learn that it has no "On Error GoTo somewhere" functionality. What's the purpose of the Err object, then?

    Simple. After any line that you expect an error might occur, such as opening a database connection, the Err object can be checked:

    dbConn.Open()
    If Err Then
        '-- Houston, we have a problem
    End If

    EDIT: In no way am I condoning this as good practice. Fall-through error handling sucks. I'm glad C# uses the try/catch structure.



  • @AbbydonKrafts said:

    I'm glad C# uses the try/catch structure.
     

    As do all the .NET langauges.



  • @AbbydonKrafts said:

    Simple. After any line that you expect an error might occur, such as opening a
    database connection, the Err object can be checked

    <smacks himself on the head>

    But comparing VBS to C# is silly, VB uses Try/Catch as well.



  • @MasterPlanSoftware said:

    As do all the .NET langauges.

    @Spectre said:
    But comparing VBS to C# is silly, VB uses Try/Catch as well.

    I know VB.NET does. I followed the old VB line, though (GWBASIC, Q-BASIC, VB3, VB6/VBA/VBS) and went straight to C#. So, to avoid the technicality that was brought up, I should've said:

    I'm glad that .NET uses the Try/Catch structure.


  • @AbbydonKrafts said:

    So, to avoid the technicality that was brought up, I should've said:
    I'm glad that .NET uses the Try/Catch structure.
     

    Yes you should have.

    </Pedantry>



  • @AbbydonKrafts said:

    Side note: Why would anyone use JScript (do not confuse that with JavaScript) in ASP? If it's server side, why not just use VBScript?
    Hey! Just because you link to a sweet piece of Irish lass in your signature, don't expected us to tollerate this kind of talk!



  • @flinnb said:

    There are other reasons, but I can't be bothered to think of them right now.
     

    No array sorting, for one, which leads to some [url="http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=83"]interesting workarounds[/url], such as "just use JScript." 



  • @Zecc said:

    Hey! Just because you link to a sweet piece of Irish lass in your signature, don't expected us to tollerate this kind of talk!

    Hey. It was simply an inquiry. I wanted to be informed as I haven't ran across JScript ASP code before. I had always used VBScript (reason stated above).



  • @arty said:

    Does anybody else have a physical reaction to bad code? 

     

    Yes, and it normally goes along the lines of "aaarrghh it burns, IT BURNS!!!"

    I read some Perl the other day, and my hair actually started smouldering. 



  • You still have hair?  </obligatory>


Log in to reply