• Code Dependent (cs)

    The author was obviously spaced when he wrote this.

    Oh, yeah... fist!

  • Daid (cs)

    Simple because "space()" was not fancy enough: http://msdn.microsoft.com/en-us/library/k6ethaxs.aspx

    Returns a string consisting of the specified number of spaces.

  • L (unregistered)

    I don't get it : does GenerateSpaces() actually do something ? I don't know VB, so maybe I'm missing something...

  • DOA (cs)

    This is your code. This is your code on drugs.

  • moz (unregistered) in reply to Daid
    Daid:
    Simple because "space()" was not fancy enough: http://msdn.microsoft.com/en-us/library/k6ethaxs.aspx

    Returns a string consisting of the specified number of spaces.

    You could use that, I suppose, but it would do the wrong thing if you called GenerateSpaces(-4).

  • Code Dependent (cs)

    Even though the author was able to improve on Spaces(#), why call a subroutine to fill the spaces variables? Why not declare them as const, or store them in a resource file?

    Hmm... maybe he wanted to leave the option for future changes such as spaces1 having 37 spaces in it.

  • Zapp Brannigan (unregistered)
    Private space1, space2, space3, space4, space5, _
            space6, space7, space8, space9, space10, _
            space100 As String
    

    If this is vb what data type is space1? It's not string.

    Something doesn't smell right, this code has to be someones idea of a joke.

  • For-Case Man (unregistered)

    I just can't believe they didn't implement this as a For-Case loop. That's the obvious correct instantiation.

  • Rocco (unregistered)

    Spaces... the final frontier.

    umm... line.padright(n)

  • SpasticWeasel (unregistered) in reply to Zapp Brannigan
    Zapp Brannigan:
    Private space1, space2, space3, space4, space5, _ space6, space7, space8, space9, space10, _ space100 As String

    If this is vb what data type is space1? It's not string.

    Something doesn't smell right, this code has to be someones idea of a joke.

    Everything except space100 is a variant.

  • evilripper (unregistered)

    hahahaha this code broke my brain! :-D

    bye bye

    http://www.evilripper.net

  • Capt. Kirk (unregistered)

    As a customer your choices are:

    1. Hire an experienced competent developer who understands the library functions, knows how to write properly structured code with appropriate variable scope and data types, or

    2. Hire someone who will produce what appears to be exactly the same output.

    As a customer who doesn't happen to be a developer himself, the above two options translate as:

    1. Hire an expensive expensive expensive who expensive the expensive expensive, knows how to write expensive expensive code with expensive expensive expensive and expensive expensive, or

    2. Save a bunch of money and get exactly the same thing.

  • Max (unregistered)

    Even QuickBasic had a function to make spaces...

    Space$(i%)

  • nobody (unregistered) in reply to Capt. Kirk

    Cpt Kirk: who are you? Why don't you put this in a blog and post a link to it so we can all share it? Seriously, the sarcasm & wit may have made my day, but the point is actually very insightful...

  • randomlyVarying (unregistered)

    Obviously, this guy should learn the mother of all programming languages:

    http://en.wikipedia.org/wiki/Whitespace_(programming_language)

  • DarkSprout (unregistered)

    a simple: ... = String$(4,32)

    I do love the code, it is fun; but if you are going to do it by appending to strings - then you should be using the faster method of using an API or two, such as RtlMoveMemory and CopyMemory.

    Ho Hum, =|)arkSprout=

  • Capt. Kirk (unregistered) in reply to nobody
    nobody:
    Cpt Kirk: who are you?
    Why I'm the master of all space, of course. I thought that would be obvious.
  • Code Dependent (cs) in reply to Capt. Kirk
    Capt. Kirk:
    As a customer your choices are:
    1. Hire an experienced competent developer who understands the library functions, knows how to write properly structured code with appropriate variable scope and data types, or

    2. Hire someone who will produce what appears to be exactly the same output.

    As a customer who doesn't happen to be a developer himself, the above two options translate as:

    1. Hire an expensive expensive expensive who expensive the expensive expensive, knows how to write expensive expensive code with expensive expensive expensive and expensive expensive, or

    2. Save a bunch of money and get exactly the same thing.

    3. Save a bunch of money and get what looks like exactly the same thing, and spend the next five years constantly hiring cheap consultants to come in and appear to fix what's wrong.

  • ell0bo (unregistered)

    I just had to deal with this myself. A new project we're working on, we brought in a new guy. He's older, been around the block, so I didn't think I had to watch him closely. I actually thought that since I'm 26, he's 50... maybe I can learn something from him right?

    I had about a month to get him into understanding the framework we were going to be using, and how methodology I wanted to go by. I told him to place all constants in /company_configs/company_name.php . I showed him how I used constants in the config.php to tell me what type of server the framework was running on, if that instance of PHP was for live or test, that kind of thing. I went on vacation to visit, and by the time I came back, the company config had things like define('/', SLASH). Not only did he add that definition, he then went through all of the framework's code and changed all slashes to SLASH. I wished he had stopped at SLASH, but there was DOT, QUOTE, DBLQUOTE, and PDF ('.pdf').

    Luckily he only checked in the changes in the day before I returned. No one could figure out why we had files name of companySLASHcheckDOTPDF showing up places.

    Not only did he do all of that, he never added the company_config file so the constants got defined. Sigh... I fixed most of it in a day or two, but some of that code still exists in the wild out there.

  • Capt. Kirk (unregistered) in reply to Code Dependent
    Code Dependent:
    Capt. Kirk:
    As a customer your choices are:
    1. Hire an experienced competent developer who understands the library functions, knows how to write properly structured code with appropriate variable scope and data types, or

    2. Hire someone who will produce what appears to be exactly the same output.

    As a customer who doesn't happen to be a developer himself, the above two options translate as:

    1. Hire an expensive expensive expensive who expensive the expensive expensive, knows how to write expensive expensive code with expensive expensive expensive and expensive expensive, or

    2. Save a bunch of money and get exactly the same thing.

    3. Save a bunch of money and get what looks like exactly the same thing, and spend the next five years constantly hiring cheap consultants to come in and appear to fix what's wrong.
    True, but a lot of businesses would rather spend a million dollars spread over five years than 10 thousand dollars today, because:

    A. In all likelihood, tomorrow will never come (for this product or business line).

    B. If tomorrow does pan out, to the point where we need to keep this baby limping along, we'll have the million dollars.

    C. Customer can't see the difference between good code and garbage anyhow.

  • derula (cs)

    Call GenerateComments(1)

    Can't believe nobody said that yet.

  • smbarbour (cs) in reply to L
    L:
    I don't get it : does GenerateSpaces() actually do something ? I don't know VB, so maybe I'm missing something...
    Yes, it wastes a ton of memory and CPU cycles.
  • pink_fairy (cs) in reply to Code Dependent
    Code Dependent:
    Even though the author was able to improve on Spaces(#), why call a subroutine to fill the spaces variables? Why not declare them as const, or store them in a resource file?

    Hmm... maybe he wanted to leave the option for future changes such as spaces1 having 37 spaces in it.

    Const and resource files aren't really enterprisey enough, are they? This solution would be excellent, if only it allowed for memoization. I mean, who wants to generate the same length of whitespace more than once?

    Oh wait, VB.Net presumably does this for you.

    But I bet it doesn't create a heapsort-based list of pointer/length pairs into the longest string. Yes, that would be the way to go. (You need the pointers to make sure that access to memory is evenly distributed; vital for proper performance.)

    Well now. I thought VB was supposed to be garbage-collected, but clearly it isn't. This garbage doesn't so much need "mark and sweep" as "mark, take out back behind the chicken shack, and shoot in the back of the head."

    No -- TRWTF is the choice of language, as always (insert flame here).

    This solution would clearly be superior if coded in Whitespace. Yay! It's available on .NET!

  • John Preston (unregistered)

    For those of you who are wondering, it's VB.Net code. And dimming them all those space# variables in commas like that makes them all strings.

    Also the NumSpaces you see there is a property which was used to append hold the "return value" of GenerateSpaces. For more Java/C minded people Sub means it's a void function, so there was something similar to a global variable holding what could have been the return value.

    None of the variables or methods are still there. They were replaced by Space(#)s and, as I recall a PadLeft and PadRight or two.

  • mauhiz (unregistered)

    that was actually the tip of the iceberg. There are other similar global variables for most characters too.

  • Neil (unregistered) in reply to ell0bo
    ell0bo:
    I just had to deal with this myself. A new project we're working on, we brought in a new guy. He's older, been around the block, so I didn't think I had to watch him closely. I actually thought that since I'm 26, he's 50... maybe I can learn something from him right?

    I had about a month to get him into understanding the framework we were going to be using, and how methodology I wanted to go by. I told him to place all constants in /company_configs/company_name.php . I showed him how I used constants in the config.php to tell me what type of server the framework was running on, if that instance of PHP was for live or test, that kind of thing. I went on vacation to visit, and by the time I came back, the company config had things like define('/', SLASH). Not only did he add that definition, he then went through all of the framework's code and changed all slashes to SLASH. I wished he had stopped at SLASH, but there was DOT, QUOTE, DBLQUOTE, and PDF ('.pdf').

    Luckily he only checked in the changes in the day before I returned. No one could figure out why we had files name of companySLASHcheckDOTPDF showing up places.

    Not only did he do all of that, he never added the company_config file so the constants got defined. Sigh... I fixed most of it in a day or two, but some of that code still exists in the wild out there.

    Wouldn't it have been easier just to revert his changes from the repository?

  • Beldar the Phantom Replier (cs)

    First out loud WTF I've had from this site in a while.

    All I can say is "It's about time."

  • jimlangrunner (cs) in reply to pink_fairy
    pink_fairy:
    snip. No -- TRWTF is the choice of language, as always (insert flame here). snip.
    No -- TRWTF is the choice of language, as always (FLAMEFLAMEFLAMEFLAMEFLAME).

    There. Is that flaming enough?

  • JL (unregistered) in reply to L
    L:
    I don't get it : does GenerateSpaces() actually do something ? I don't know VB, so maybe I'm missing something...
    It might, if NumSpaces is a global variable -- which depends on compiler settings, VB version, and whether NumSpaces is declared elsewhere. If it is a global, GenerateSpaces() could be better written as a function returning a value rather than a subroutine side-affecting a variable. If it isn't a global, then GenerateSpaces() does nothing at all, and could be replaced with an empty subroutine body (or removed outright).

    But in the code example at the bottom of the article, no, GenerateSpaces() isn't doing anything to affect the value of the Line variable. (And even if it were, the value of Line is overwritten two statements later. Really, really pointless code.)

  • Rocco (unregistered)

    The beauty of this is that the guy wrote the rediculous function, called it, then hardcoded the spaces anyway.

    Years ago I worked in a BASIC language that did not have a padding function. Common practice was to define Spaces$ as a few hundred spaces, then we would append it to other string variables follwed by cropping to correct length. Inelegant, but functional. ex: A$=left(a$+spaces$,60)

  • jimlangrunner (cs) in reply to John Preston
    John Preston:
    For those of you who are wondering, it's VB.Net code. And dimming them all those space# variables in commas like that makes them all strings.

    Also the NumSpaces you see there is a property which was used to append hold the "return value" of GenerateSpaces. For more Java/C minded people Sub means it's a void function, so there was something similar to a global variable holding what could have been the return value.

    None of the variables or methods are still there. They were replaced by Space(#)s and, as I recall a PadLeft and PadRight or two.

    You know, I almost argued about whether it's VB.Net or VB6. It could just as easily fit into VB6, in which case the original (all but last variant) would hold true. That's why, in VB.Net, I always explicitly declare all variables. But then I looked. You're the OP, and if anyone would know, you would.

    I bow to your restraint as evidenced by your lack of prison sentence.

  • jimlangrunner (cs) in reply to Rocco
    Rocco:
    The beauty of this is that the guy wrote the rediculous function, called it, then hardcoded the spaces anyway.

    Years ago I worked in a BASIC language that did not have a padding function. Common practice was to define Spaces$ as a few hundred spaces, then we would append it to other string variables follwed by cropping to correct length. Inelegant, but functional. ex: A$=left(a$+spaces$,60)

    Looks like BBx to me.

    MY EYES! THEY ARE BLEEDING!

  • Mr. Mackey (unregistered)

    Enough of your skylarkings! Mmmmkay?

  • pink_fairy (cs) in reply to jimlangrunner
    jimlangrunner:
    pink_fairy:
    snip. No -- TRWTF is the choice of language, as always (insert flame here). snip.
    No -- TRWTF is the choice of language, as always (FLAMEFLAMEFLAMEFLAMEFLAME).

    There. Is that flaming enough?

    Well, I thought it was funnier with the reference to Whitespace, but heck, you're right. Let's get back down to the mat, here.

    Only a Deranged Fool would use VB.Net for a task this important. Clearly the only Sane Choice is ... no, I'm not going to calm down. Get your hands off me! I don't care how many side effects that filthy solution has; I'm not going to use a functional alternative.

    Dysfunctional languages, that's the way to go.

  • Dennis (unregistered)

    What we need is a language with a compile-time garbage collector!

  • Mike H (cs) in reply to JL
    JL:
    L:
    I don't get it : does GenerateSpaces() actually do something ? I don't know VB, so maybe I'm missing something...
    It might, if NumSpaces is a global variable -- which depends on compiler settings, VB version, and whether NumSpaces is declared elsewhere. If it is a global, GenerateSpaces() could be better written as a function returning a value rather than a subroutine side-affecting a variable. If it isn't a global, then GenerateSpaces() does nothing at all, and could be replaced with an empty subroutine body (or removed outright).

    But in the code example at the bottom of the article, no, GenerateSpaces() isn't doing anything to affect the value of the Line variable. (And even if it were, the value of Line is overwritten two statements later. Really, really pointless code.)

    I was wondering about what that method did too, but I think you're right. NumSpaces (a great name for a string variable BTW) isn't declared locally in GenerateSpaces() so it must be a global.

    The code to use it probably looks like this.

    Call GenerateSpaces(19)
    Line = "W" & NumSpaces
    Call GenerateSpaces(1)
    Line = "T" & NumSpaces
    Call GenerateSpaces(11)
    Line = "F" & NumSpaces
    

    Ugh.

    ETA:

    John Preston:
    Also the NumSpaces you see there is a property which was used to append hold the "return value" of GenerateSpaces.

    Ah, it was a VB.NET property. Well at least it's scoped to an instance....

  • ih8u (unregistered) in reply to jimlangrunner
    jimlangrunner:
    pink_fairy:
    snip. No -- TRWTF is the choice of language, as always (insert flame here). snip.
    No -- TRWTF is the choice of language, as always (FLAMEFLAMEFLAMEFLAMEFLAME).

    There. Is that flaming enough?

    One thing to consider is that without VB, idiots would learn another language. At least with VB's creepy looking source, you can tell at a glance that the code is slow and buggy at best or causes severe head trauma at worst -- and you don't actually have to read it.

    VB is a necessary evil. Just never hire or work with a VB-only programmer.

  • pink_fairy (cs) in reply to ih8u
    ih8u:
    One thing to consider is that without VB, idiots would learn another language. At least with VB's creepy looking source, you can tell at a glance that the code is slow and buggy at best or causes severe head trauma at worst -- and you don't actually have to read it.

    VB is a necessary evil. Just never hire or work with a VB<snip/> programmer.

    Oh dear.

    You are aware that people are going to misquote you egregiously for their own sad little purposes, aren't you?

  • Anonymous Coward (unregistered)

    I'm waiting for the never-ending fight to begin: It's not the language; it's the developer VERSUS It's the language

    Granted, it's the developer more than the language. However, the culture of some languages like VBA are more likely to breed this kind of stupidity. Can we all agree on that?

    <flame bait="">Oh, and before we get too kumbaya, PHP developers rock. All others FTL. &lt;/flame bait&gt;<p> </flame>

  • darsal (unregistered)

    Far more effective:

    Private Sub fillSpaces() space0 = " " ;2^0=1 space space1 = " " ;2^1=2 spaces space2 = " " ;2^2=4 spaces space3 = " " ;2^3=8 spaces space4 = " " ;2^4=16 spaces space5 = " " ;2^5=32 spaces (...) End Sub

  • Loren Pechtel (unregistered) in reply to Rocco
    Rocco:
    The beauty of this is that the guy wrote the rediculous function, called it, then hardcoded the spaces anyway.

    Years ago I worked in a BASIC language that did not have a padding function. Common practice was to define Spaces$ as a few hundred spaces, then we would append it to other string variables follwed by cropping to correct length. Inelegant, but functional. ex: A$=left(a$+spaces$,60)

    Yeah, there are legit reasons to define a block of spaces. This insane function certainly isn't it, though!

    I've done it before for padding and I've done it to provide a quick way to clear a character array.

  • darsal (unregistered) in reply to darsal

    Oh, yeah:

    Private Sub fillSpaces()
      space0 = " "                                ;2^0=1 space
      space1 = "  "                               ;2^1=2 spaces
      space2 = "    "                             ;2^2=4 spaces
      space3 = "        "                         ;2^3=8 spaces
      space4 = "                "                 ;2^4=16 spaces
      space5 = "                                " ;2^5=32 spaces
    (...)
    End Sub
    
  • pink_fairy (cs) in reply to Anonymous Coward
    Anonymous Coward:
    I'm waiting for the never-ending fight to begin: It's not the language; it's the developer VERSUS It's the language

    Granted, it's the developer more than the language. However, the culture of some languages like VBA are more likely to breed this kind of stupidity. Can we all agree on that?

    <flame bait="">Oh, and before we get too kumbaya, PHP developers rock. All others FTL. &lt;/flame bait&gt;</flame>

    The PHP Asbestos Gloves! They do nothing!

  • Code Dependent (cs) in reply to pink_fairy
    pink_fairy:
    Dysfunctional languages, that's the way to go.
    Soitainly! They were the inspiration for my nick.
  • Code Dependent (cs) in reply to Anonymous Coward
    Anonymous Coward:
    I'm waiting for the never-ending fight to begin: It's not the language; it's the developer VERSUS It's the language
    Chicken/egg. Which came first, the developer or the language?
  • DaveAronson (cs)

    Clearly he's a space cowboy. (You SHOULDA been ready for that!)

  • pink_fairy (cs) in reply to Code Dependent
    Code Dependent:
    pink_fairy:
    Dysfunctional languages, that's the way to go.
    Soitainly! They were the inspiration for my nick.
    Well, that makes sense.

    Who wouldn't buy Visual Basicine? I'm still waiting for Audio Plastic.NET, but, y'know, our little community has never quite managed to get Accessibilty right for those poor souls crippled by overdosing on Windolene.

    I'm still gonna stand by Whitespace.NET. It's as pure as the water your gramma use ta irrigate yer nethers with. Only three meaningful characters: that's the ticket.

    Turing would claim that you only need two characters, but then he was a pouf, and a fellow of King's College, Cambridge, as well. There's only so much deviation that a Godfearing Software Engineer can take.

  • Anonymous Coward (unregistered) in reply to Code Dependent
    Code Dependent:
    Anonymous Coward:
    I'm waiting for the never-ending fight to begin: It's not the language; it's the developer VERSUS It's the language
    Chicken/egg. Which came first, the developer or the language?

    Simple. If the dev was born before the language was invented, problem solved.

  • boingle (unregistered)

    Come on folks! It's written in Visual BASIC

    B EGINNERS A ll purpose S ymbolic I nstruction C ode

    This is a language created for beginners, did you really expect anything other than stupid code.

  • Code Dependent (cs) in reply to boingle
    boingle:
    B EGINNERS A ll purpose S ymbolic I nstruction C ode
    I thought it was:

    B usiness A ctivity S tuck I n C rap

Leave a comment on “Spaced Out”

Log In or post as a guest

Replying to comment #:

« Return to Article