• (cs)

    [quote] ...whereas the two latter have been lost to the ages. [quote] Can you lose something you never wanted?

  • (cs) in reply to bstorer

    [quote user="bstorer"][quote] ...whereas the two latter have been lost to the ages. [quote] Can you lose something you never wanted?[/quote]

    Yes. " 14. To cause to be destroyed. Usually used in the passive: Both planes were lost in the crash."

  • Al (unregistered)

    Interestingly enough, similar excavations turned up a rather special end result to all this, expressed best through the use of code.

    Function replaceEmp( name )

    Dim employee employee = replace(employee, "old guy", "new guy")

    End Function

    Even if you hate VBScript, how can one not giggle at "Dim employee"?

  • (cs)

    I think what scares me is how much this natural progression resembles my first attempt at coding an isometric RPG game.

  • Al (unregistered)

    Forgive my lack of coffee. I meant to type this:

    Function replaceEmp( name )

    Dim employee employee = replace(name, "old guy", "new guy")

    End Function

  • Jonh Robo (unregistered)

    A Refactoring Conundrum

    ...but if you lose:

    If Session("Reprint") = "" Then Session("Reprint") = "" End If

    then how will Session("Reprint") ever get set to "" if Session("Reprint") is equal to ""?

  • (cs) in reply to Al
    Al:
    Interestingly enough, similar excavations turned up a rather special end result to all this, expressed best through the use of code. Function replaceEmp( name )

    Dim employee employee = replace(employee, "old guy", "new guy")

    End Function

    Even if you hate VBScript, how can one not giggle at "Dim employee"?

    One might not be giggling because they're too busy trying to figure out why a parameter was included and never used. ;-)

  • Rafael Larios (unregistered)

    WOW..... just..... WOW.

    When I write programs, I allways tell myself.. "There isn't any other easy way?"...

    seems that the programer at the snippet didn't question himself very often.

    What the hell is Gygax?

  • (cs) in reply to Rafael Larios

    Gary Gygax is the inventor of D&D, and many other roleplaying games.

    Or, it could be refering to Daniel Gygax, a Swiss football player....

  • (cs) in reply to vertagano
    vertagano:
    bstorer:
    ...whereas the two latter have been lost to the ages.
    Can you lose something you never wanted?

    Yes. " 14. To cause to be destroyed. Usually used in the passive: Both planes were lost in the crash."

    Don't cite dictionary definitions at me. You need to get meta!
  • (cs)

    yeah, basic string manipulation should have been tested before this joker was hired...

    If you hire someone who's LEARNING the skill set(s) required for the job, you should know beforehand (well, if you expect to make any money)!

  • (cs) in reply to Edowyth
    Edowyth:
    yeah, basic string manipulation should have been tested before this joker was hired...

    If you hire someone who's LEARNING the skill set(s) required for the job, you should know beforehand (well, if you expect to make any money)!

    But you make your money on the fact that you're paying the guy far less. Of course, if you're a company dumb enough to overpay for an employee with no experience, you get what you deserved.

  • (cs)

    I hate single letter varibles! Everytime I have to search code for a varible named 'a' I want to scream!

  • (cs)

    The dumb employee gets to train on the job and gets a paycheck.

    The company hopefully gets to pay him what he's worth (very little). They presumably get code that still works. The manager doesn't care how crappy and inefficient it is. It's not like he has to maintain it.

    We get to see more stupid code.

    It's a win-win-win situation!

  • (cs) in reply to rogueuser
    rogueuser:
    I hate single letter varibles! Everytime I have to search code for a varible named 'a' I want to scream!

    I love my single letter vars, they go on little single letter dates and have single letter sex creating nice multi letter vars. Where do you think well named vars come from?

  • (cs)

    Thank god they replaced those inscrutable single-letter variable names with longer, self-explanatory var names like "vlu"!

  • Massif (unregistered) in reply to KattMan

    Is that where two-letter commands come from? Are well-named variables several generations down?

  • rp (unregistered) in reply to Jonh Robo
    Jonh Robo:
    A Refactoring Conundrum

    ...but if you lose:

    If Session("Reprint") = "" Then Session("Reprint") = "" End If

    then how will Session("Reprint") ever get set to "" if Session("Reprint") is equal to ""?

    I'm not quite sure whether you're serious, but I hope you are.

    The trouble with refactoring is the hidden landmines (i.e. people don't document the invariants their code relies on). In this case, a string can compare equal to "" without actually being the same as "", for instance, when it's a null reference (Nothing in VB.NET), and then be passed to a piece of code that depends on such strings actually being the same as "". Try this at home:

    Option Strict On
    
    Imports System
    
    Public Module Main
    
        Private Function almostNoOp(ByVal s As String) As String
            If s = "" Then
                s = ""
            End If
            Return s
        End Function
    
        Private Function withLength(ByVal s As String) As String
            Return s & " (" & s.Length & ")"
        End Function
    
        Private Sub emitStringWithLength(ByVal s As String)
            Console.WriteLine(withLength(s) & Environment.NewLine)
        End Sub
    
        Public Sub Main()
            emitStringWithLength("starting")
            emitStringWithLength(almostNoOp(Nothing))
            emitStringWithLength("that was test 1")
            emitStringWithLength(Nothing)
            emitStringWithLength("that was test 2")
        End Sub
    
    End Module
    
    
  • TomB (unregistered)

    I'm pretty sure you need a return value for a function

    Function replaceEmp( name )

    Dim employee employee = replace(name, "old guy", "new guy")

    End Function

    should be

    Function replaceEmp( name )

    replaceEmp = replace(name, "old guy", "new guy")

    End Function

  • DingBat (unregistered)

    I dunno, the OP is using the word "refactor" in strange ways I've never heard before.

    Refactoring, as I understand it, is a developer tool used to keep code from getting to exactly the place this example arrived at. What do managers have to do with refactoring?

  • speaking of wtf's (unregistered)

    man does this forum software suck!

  • (cs) in reply to KattMan
    KattMan:
    rogueuser:
    I hate single letter varibles! Everytime I have to search code for a varible named 'a' I want to scream!

    I love my single letter vars, they go on little single letter dates and have single letter sex creating nice multi letter vars. Where do you think well named vars come from?

    Hmmm... perhaps we need a genetic algorithm to generate good variable names...

  • Jimmie (unregistered) in reply to speaking of wtf's

    ASP/VB is in major need of just one little thing...

    BRACES!!!!

    Wend?

    End Function?

    End If?

    OMG! That kind of coding structure is sooooo 1980!

    the real WTF is the VB syntax

  • (cs) in reply to DingBat
    DingBat:
    I dunno, the OP is using the word "refactor" in strange ways I've never heard before.

    Refactoring, as I understand it, is a developer tool used to keep code from getting to exactly the place this example arrived at. What do managers have to do with refactoring?

    Depends on your context. To a programmer, refactor means to fix the code, which in the end of the article it was refactored in this fashion. To a manager, refactor means to upgrade or add functionality. It is a danger of us techies using our language to explain something to non-techies.

  • (cs) in reply to Rootbeer
    Rootbeer:
    Thank god they replaced those inscrutable single-letter variable names with longer, self-explanatory var names like "vlu"!
    We all know that variable names should at least be four-letter-words! :P
  • (cs)

    Am I the only one who thinks that escaping quotes with a pair of quotes in quote-delimited strings is a bit stupid? I don't usually bash languages I don't know, but jeez.

  • (cs) in reply to Faxmachinen
    Faxmachinen:
    Am I the only one who thinks that escaping quotes with a pair of quotes in quote-delimited strings is a bit stupid? I don't usually bash languages I don't know, but jeez.

    That actually is the best way to escape anything unless you want to build all kinds of rule exceptions. Even C does this with the \ character; if you actually want it, then escape it with itself.

    For a real WTF, just take a look at the CSV format and find out how it wants you to escape things and decide how easy it would have been if they had just allowed ,, to escape the ,. The problem is this: You want a comma in your data, encase your data in quotes. Now you created a new problem, what if you want quotes in your data? You have to escape those now. Always easier to allow your delimiting character to escape itself or you are simply adding new delimiters.

  • erKURITA (unregistered)
    If Session("Reprint") = "" Then Session("Reprint") = "" End If

    Head->Desk

  • (cs) in reply to Faxmachinen
    Faxmachinen:
    Am I the only one who thinks that escaping quotes with a pair of quotes in quote-delimited strings is a bit stupid? I don't usually bash languages I don't know, but jeez.
    That's how you escape a single quote in a string in SQL. Some DBs will let you use \', too.
  • (cs) in reply to TomB
    TomB:
    I'm pretty sure you need a return value for a function

    Function replaceEmp( name )

    Dim employee employee = replace(name, "old guy", "new guy")

    End Function

    should be

    Function replaceEmp( name )

    replaceEmp = replace(name, "old guy", "new guy")

    End Function

    But then you loose out on the Dim employee.

    Function replaceEmp( name ) 
    
    Dim employee 'ToDo: Remove this variable
    
    replaceEmp = replace(name, "old guy", "new guy") 
    
    End Function 
    
  • Peter (unregistered)
  • Ed (unregistered)

    I'm guessing this is a typo..

    Function CheckString(s) p = InStr(s, "'") While p > 0 s = Mid(s, 1, p) & "'" & Mid(s, p + 1) pos = InStr(p + 2, s, "'") Wend CheckString = "'" & s & "'" End Function

    because if this code is run as above, it'll get stuck in an infinite loop.

  • JGM (unregistered) in reply to KattMan

    But if you allow ,, to escape , how do you specify an empty column?

  • (cs) in reply to bstorer

    [quote user="bstorer"][quote] ...whereas the two latter have been lost to the ages. [quote] Can you lose something you never wanted?[/quote]

    Mona Mayfair: "I didn't lose my virginity. I obliterated all traces of its existence."

  • (cs) in reply to JGM
    JGM:
    But if you allow ,, to escape , how do you specify an empty column?

    Well true. But you should have one escaping character and use it everywhere even when escaping itself. I admit my example was off the mark but it does show part of the problems with not defining an escaping character. There are other formats that come to mind, VB and SQL handling things in a similar fashion while C uses \ and \ to escape the escape character.

    Then XML comes to mind where there is no easy way to place a & in a field that needs to be parsed by XSL then used in the resulting HTML. For example you want to have a non-breaking space so the final HTML needs to show   but the XSL transform will escape it out to a space on it's own leaving you with literally a blank that might not get rendered so you have to encode this in the original XML as such:  . This means you have to know how many transforms you are going to go through from the begining before you can encode it properly. Got another level to transform through, then you need to encode it as such:  

    Things just get hairy when you don't have a good escaping format.

  • (cs) in reply to KattMan
    KattMan:
    That actually is the best way to escape anything unless you want to build all kinds of rule exceptions. Even C does this with the \ character; if you actually want it, then escape it with itself.
    Yes, but a string literal in C isn't enclosed in slashes.

    I can only guess how horrible a print-my-own-sourcecode program would look in VB.

  • (cs) in reply to Faxmachinen
    Faxmachinen:
    KattMan:
    That actually is the best way to escape anything unless you want to build all kinds of rule exceptions. Even C does this with the \ character; if you actually want it, then escape it with itself.
    Yes, but a string literal in C isn't enclosed in slashes.

    I can only guess how horrible a print-my-own-sourcecode program would look in VB.

    The only real problem there is if you were doing syntax highlighting. As all lines would be read in as strings already rather then you trying to build the string you need not worry about the " character, it is already contained in the string.

    What you do have to worry about is when you are doing syntax highlighting you need to look for " and read ahead one character to see if the next one is also a ", if it is print just one, if it isn't back up and change text color and move forward again. At least with C you know when you reach a \ you simply print the next character knowing it is still part of the string itself. You don't stop highlighting your string until you reach a lone ".

  • (cs) in reply to KattMan
    KattMan:
    JGM:
    But if you allow ,, to escape , how do you specify an empty column?

    Well true. But you should have one escaping character and use it everywhere even when escaping itself. I admit my example was off the mark but it does show part of the problems with not defining an escaping character. There are other formats that come to mind, VB and SQL handling things in a similar fashion while C uses \ and \ to escape the escape character.

    Then XML comes to mind where there is no easy way to place a & in a field that needs to be parsed by XSL then used in the resulting HTML. For example you want to have a non-breaking space so the final HTML needs to show   but the XSL transform will escape it out to a space on it's own leaving you with literally a blank that might not get rendered so you have to encode this in the original XML as such:  . This means you have to know how many transforms you are going to go through from the begining before you can encode it properly. Got another level to transform through, then you need to encode it as such:  

    Things just get hairy when you don't have a good escaping format.

    The same would be the case if you used, say, "\ " to do a non-breaking space. The XSLT would convert it to a space, so you'd have to do "\ " instead. And if you had two levels of transformation, you'd have to have "\\ ". Not exactly a better solution, eh? The key is to keep the XSLT from transforming the escaped characters on every pass, say through using CDATA. More specifically, through the cdata-section-element attribute of the xsl:output element. I'd provide a complete example, but I don't work in XSLT unless I'm getting paid to do so.

  • Aaron (unregistered)

    The fact that a good majority of the "code WTFs" are in VB doesn't help my opinion that VB is an inferior language. :P

    (catpcha: onomatopoeia -- come ON... if a captcha decoder script can read 5 letters written as normal text, what makes you think it can't read 12...is it necessary to make me type long words?)

  • Opie (unregistered)

    Using quotes to escape themselves is not readable - that's the problem. It's pretty hard to look at a bunch of quotes stuck together and know exactly what they represent.

    However, slashes are extremely easy to count. They only start to get ridiculous around 6 or so, and really how often do you encounter that many? The most I've ever been forced to use (due to ajax and passing special strings back and forth) is 8 (\\\\), and that's a hell of a lot easier than reading """""""", especially if your text editor doesn't use a monospace font.

  • (cs) in reply to Aaron
    Aaron:
    The fact that a good majority of the "code WTFs" are in VB doesn't help my opinion that VB is an inferior language. :P

    (catpcha: onomatopoeia -- come ON... if a captcha decoder script can read 5 letters written as normal text, what makes you think it can't read 12...is it necessary to make me type long words?)

    It isn't that VB is an inferior language, it is rather that inferior programmers tend to work more in VB. This does not imply that the reverse logic is true, meaning that just because you work in VB does not mean you are an inferior programmer; you just have a higher probability of working with one.

  • Jon (unregistered) in reply to KattMan

    Still, the old joke goes, "The 'B' in VB stands for 'Beginner'."

    ([Visual] Beginner's All-purpose Symbolic Instruction Code)

  • no name (unregistered) in reply to Opie
    Opie:
    Using quotes to escape themselves is not readable - that's the problem. It's pretty hard to look at a bunch of quotes stuck together and know exactly what they represent.

    However, slashes are extremely easy to count. They only start to get ridiculous around 6 or so, and really how often do you encounter that many? The most I've ever been forced to use (due to ajax and passing special strings back and forth) is 8 (\\\\), and that's a hell of a lot easier than reading """""""", especially if your text editor doesn't use a monospace font.

    They actually make those? And people use them??? Coders????

  • (cs) in reply to no name
    no name:
    Opie:
    Using quotes to escape themselves is not readable - that's the problem. It's pretty hard to look at a bunch of quotes stuck together and know exactly what they represent.

    However, slashes are extremely easy to count. They only start to get ridiculous around 6 or so, and really how often do you encounter that many? The most I've ever been forced to use (due to ajax and passing special strings back and forth) is 8 (\\\\), and that's a hell of a lot easier than reading """""""", especially if your text editor doesn't use a monospace font.

    They actually make those? And people use them??? Coders????

    Yes they still make slashes. They were going to stop production of slashes thinking that only mathematicians used them and by their calculations there should have been a surplus for decades; then us coders spoke up and started using this untapped resource in mass quantities. Since then, instead of stopping production, they have had to increase production seven fold.

    Oh wait, you were talking about mono-spaced fonts, sorry.

  • (cs) in reply to KattMan
    KattMan:
    What you do have to worry about is when you are doing syntax highlighting you need to look for " and read ahead one character to see if the next one is also a ", if it is print just one, if it isn't back up and change text color and move forward again.
    Now you see, that's a perfect example. What happens when you apply your algorithm to an empty string? And since when did syntax highlighting include replacing escape sequences anyway?
  • (cs) in reply to Faxmachinen
    Faxmachinen:
    KattMan:
    What you do have to worry about is when you are doing syntax highlighting you need to look for " and read ahead one character to see if the next one is also a ", if it is print just one, if it isn't back up and change text color and move forward again.
    Now you see, that's a perfect example. What happens when you apply your algorithm to an empty string? And since when did syntax highlighting include replacing escape sequences anyway?

    Yeah no replacements, see I'm not perfect.

    But empty strings are handled easy, because you have to actually be in the string before you can escape it.

    Hit the first quote, we are not in the string yet so start highlighting Flag it now as in string.
    Next character read in. If it is a quote and PriorQuote is true keep highlighting and set PriorQuote = !PriorQuote. If it is not a quote and PriorQuote is True stop highlighting and flag it as out of string. All other characters, set PriorQuote to false and keep highlighting.

  • Your Name (unregistered) in reply to rogueuser
    rogueuser:
    I hate single letter varibles! Everytime I have to search code for a varible named 'a' I want to scream!

    Use "vi", then /<a>/ finds just that variable, and not the "a" in assert or whatever

  • (cs) in reply to KattMan
    KattMan:
    no name:
    Opie:
    Using quotes to escape themselves is not readable - that's the problem. It's pretty hard to look at a bunch of quotes stuck together and know exactly what they represent.

    However, slashes are extremely easy to count. They only start to get ridiculous around 6 or so, and really how often do you encounter that many? The most I've ever been forced to use (due to ajax and passing special strings back and forth) is 8 (\\\\), and that's a hell of a lot easier than reading """""""", especially if your text editor doesn't use a monospace font.

    They actually make those? And people use them??? Coders????

    Yes they still make slashes. They were going to stop production of slashes thinking that only mathematicians used them and by their calculations there should have been a surplus for decades; then us coders spoke up and started using this untapped resource in mass quantities. Since then, instead of stopping production, they have had to increase production seven fold.

    Oh wait, you were talking about mono-spaced fonts, sorry.

    I nominate this as Post-of-the-Day.

  • JoshJ (unregistered) in reply to Your Name

    But it would also find "a" in the string sentence "Bob bought a car."

  • drd (unregistered) in reply to Your Name

    Even easier, (assuming by 'vi' you mean 'vim'), just move your cursor to the 'a' token, then type *. You'll get the word-boundary restrictions automatically.

Leave a comment on “Refactoring History”

Log In or post as a guest

Replying to comment #:

« Return to Article