Spaced Out

« Return to Article
  • Code Dependent 2009-04-10 09:00
    The author was obviously spaced when he wrote this.

    Oh, yeah... fist!
  • Daid 2009-04-10 09:04
    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 2009-04-10 09:06
    I don't get it : does GenerateSpaces() actually do something ?
    I don't know VB, so maybe I'm missing something...
  • DOA 2009-04-10 09:07
    This is your code. This is your code on drugs.
  • moz 2009-04-10 09:08
    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 2009-04-10 09:09
    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 2009-04-10 09:10
    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 2009-04-10 09:17
    I just can't believe they didn't implement this as a For-Case loop. That's the obvious correct instantiation.
  • Rocco 2009-04-10 09:24

    Spaces... the final frontier.


    umm... line.padright(n)
  • SpasticWeasel 2009-04-10 09:35
    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 2009-04-10 09:37
    hahahaha this code broke my brain! :-D

    bye bye


    http://www.evilripper.net
  • Capt. Kirk 2009-04-10 09:52
    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 2009-04-10 09:53
    Even QuickBasic had a function to make spaces...

    Space$(i%)

  • nobody 2009-04-10 09:55
    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 2009-04-10 09:56
    Obviously, this guy should learn the mother of all programming languages:

    http://en.wikipedia.org/wiki/Whitespace_(programming_language)
  • DarkSprout 2009-04-10 09:59
    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 2009-04-10 10:02
    nobody:
    Cpt Kirk: who are you?

    Why I'm the master of all space, of course. I thought that would be obvious.
  • Code Dependent 2009-04-10 10:05
    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 2009-04-10 10:08
    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 2009-04-10 10:12
    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 2009-04-10 10:17
    Call GenerateComments(1)

    Can't believe nobody said that yet.
  • smbarbour 2009-04-10 10:21
    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 2009-04-10 10:21
    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 2009-04-10 10:26
    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 2009-04-10 10:27
    that was actually the tip of the iceberg. There are other similar global variables for most characters too.
  • Neil 2009-04-10 10:29
    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 2009-04-10 10:30
    First out loud WTF I've had from this site in a while.

    All I can say is "It's about time."
  • jimlangrunner 2009-04-10 10:30
    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 2009-04-10 10:31
    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 2009-04-10 10:33
    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 2009-04-10 10:35
    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 2009-04-10 10:36
    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 2009-04-10 10:36
    Enough of your skylarkings! Mmmmkay?
  • pink_fairy 2009-04-10 10:45
    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 2009-04-10 10:48
    What we need is a language with a compile-time garbage collector!
  • Mike H 2009-04-10 10:51
    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 2009-04-10 11:06
    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 2009-04-10 11:13
    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 2009-04-10 11:17
    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. </flame bait>
  • darsal 2009-04-10 11:19
    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 2009-04-10 11:21
    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 2009-04-10 11:22
    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 2009-04-10 11:26
    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. </flame bait>
    The PHP Asbestos Gloves! They do nothing!
  • Code Dependent 2009-04-10 11:30
    pink_fairy:
    Dysfunctional languages, that's the way to go.
    Soitainly! They were the inspiration for my nick.
  • Code Dependent 2009-04-10 11:31
    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 2009-04-10 11:35
    Clearly he's a space cowboy. (You SHOULDA been ready for that!)
  • pink_fairy 2009-04-10 11:41
    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 2009-04-10 11:47
    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 2009-04-10 11:59
    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 2009-04-10 12:09
    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
  • Jeremy 2009-04-10 12:27
    Throw some Perl at it:

    $spaces = " " x $num_of_spaces;

    31 chars, including variable names. Done.

  • aliquot 2009-04-10 12:35
    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).

    ITYM :
    Call GetFlame(4)
    
    Line = flame4
    Line = 'No -- TRWTF is the choice of language, as always '
    Line = Line & '(FLAMEFLAMEFLAMEFLAMEFLAME)'
    FTFY HTH !

  • derula 2009-04-10 12:39
    Jeremy:
    Throw some Perl at it:

    $spaces = " " x $num_of_spaces;

    31 chars, including variable names. Done.


    Ruby:

    spaces = " " * num_of_spaces

    28 chars including variable names.
  • Anonymous 2009-04-10 12:57
    derula:
    Jeremy:
    Throw some Perl at it:

    $spaces = " " x $num_of_spaces;

    31 chars, including variable names. Done.


    Ruby:

    spaces = " " * num_of_spaces

    28 chars including variable names.


    better:

    spaces = ' ' * num_of_spaces

    Still 28 characters, but uses fewer pixels.
  • A Gould 2009-04-10 13:07
    That's not a WTF - that's job security, right there. Code so gawd-awful that your replacement will run screaming, forcing your employer to hire you back at a substantial increase.
  • Maks Verver 2009-04-10 13:09
    Python and Ruby do this too.

    But Python's version makes the most sense since i*s and s*i (with s a string and i an integer) yield the same result, while the i*s form doesn't work in either Perl or Ruby, even though they suggest commutativity by using a symbol normally used for multiplication.
  • appalled 2009-04-10 13:27
    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.

    http://msdn.microsoft.com/en-us/library/kthanxs.aspx
  • Pepper 2009-04-10 13:29
    Dennis:
    What we need is a language with a compile-time garbage collector!

    I thought VB already collects all the garbage programming-time!
  • ell0bo 2009-04-10 13:30
    He also spent that entire week making changes to his code section. So to roll back all the changes would have broken his code, and wasted the entire week he spent on it. Now it's his little section of code, and the entire system. I only managed to contain his code, not destroy it.
  • joe 2009-04-10 13:56
    Too cool to use the String(n , " ") function?

    Reinvent reinvent reinvent
  • pink_fairy 2009-04-10 14:03
    Maks Verver:
    Python and Ruby do this too.

    But Python's version makes the most sense since i*s and s*i (with s a string and i an integer) yield the same result, while the i*s form doesn't work in either Perl or Ruby, even though they suggest commutativity by using a symbol normally used for multiplication.
    Well, that's nice to know.

    Here at TDWTF, we're always up for fresh insight.

    No Soup For You!
  • derula 2009-04-10 14:39
    Maks Verver:
    But Python's version makes the most sense since i*s and s*i (with s a string and i an integer) yield the same result, while the i*s form doesn't work in either Perl or Ruby, even though they suggest commutativity by using a symbol normally used for multiplication.


    I guess you don't have to deal with quaternions a lot then.
  • Fast Eddie 2009-04-10 15:16
    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.

    For the attempt to leverage the humor of Capt. Kirk as a means to make your own funny, I must award you the fail prize. Congratulations. Go pick up your prize at the web-site next door.
  • Maks Verver 2009-04-10 15:57
    Fair point; an even more common example might be (general) matrix multiplication.

    Still, allowing 3 * 'foo' and 'foo' * 3 to evaluate to the same result seems more sensible to me, since 3 isn't a quaternion or a matrix here, but just a simple integer. This seems more in line with the principle of least astonishment, although I'll admit this is a bit subjective.

    (The problem with Perl of course, is that the language doesn't distinguish between integers and strings but regards both as scalar values, so the interpreter only considers the positions of the arguments to decide which one is a string and which one is a number, and as a result 1x'foo' yields an empty string. Not very obvious at first glance, in my opinion.)
  • Rocco 2009-04-10 16:10
    jimlangrunner:
    Looks like BBx to me.
    MY EYES! THEY ARE BLEEDING!

    HOLY SMOKES! Yep... both MAI and Basis Intl versions. ick.
  • 01001001011101000010011101110011001000000110110101100101 2009-04-10 16:20
    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.



    This reminds me of a story:

    Two penny-pinching executives (we'll call them Bill and Ted) need to drive across the country for a conference (just go with me here...) Bill purchases a new Honda Accord for the drive. It's a nice call, but not too fancy. It cost him $28000. Ted says to Bill, "A new Honda! What a waste, you pay too much for the name, you loose money as soon as you drive it off the lot!" Ted then purchased a 12 year old used car for $2000.

    After the first 200 miles Ted needed new tires. "Part of the maintenance of a car" he said. The tires cost $400. After another 200 miles Ted's car broke down. He needed new water pump. Including the towing charge, the water pump cost $600 and Ted was now a full day behind his driving schedule. After another 600 miles Ted needed brake repairs. Cost, $350. "Part of the maintenance of a car," he said.

    This continued for many days and Ted's driving schedule slipped again and again. Finally Ted arrived at his destination, where he met up with Bill again.

    "So Bill," said Ted, "we're both here, and I only spent a fraction of the cost on my car as you did!"

    "Well, that's true," said Bill. "I estimate between the cost of the car, and the cost of gas, and the oil change I needed, I spent around $30000."

    "Ah-ha!" Said Ted, "I had to do more work on my car than you, and spent more on gas too, but at the end, I spent $25000 on the car, gas and maintenance."

    "That's great for you Ted." Said Bill.

    But what Bill did not tell Ted was that since he was late to the conference four of his customers now signed on with Bill. Also Bill's car was still in great shape and he was able to keep using it for several more years without requiring any major work.

    Ted, on the other hand, had more car trouble on his way home. He finally had to abandon the old car, and purchased another $2000 used car to get him the rest of the way home. That car also required a few trips to the mechanic on the way. "Part of the maintenance of a car," Ted said.



  • Kelly 2009-04-10 16:33
    There's something with spaces. A few weeks ago, I found this function...

    **************
    Public Function Spaces()

    Dim sSpace As String

    sSpace = " " ' 50 spaces
    'default 50 spaces

    Return sSpace
    End Function
    *******************

    And it was used like this
    Spaces() + Spaces() + Spaces()
  • Kelly 2009-04-10 16:34
    Silly comments! SSpace is actually a string that's 50 spaces
  • cod3_complete 2009-04-10 17:02

    I found this interesting set of global variables.

    Private space1, space2, space3, space4, space5, _
    space6, space7, space8, space9, space10, _
    space100 As String


    But um with the private access specifier in front of the variable declarations it's actually a set of private class variables not that this makes this craptastic code any better mind you...
  • dkf 2009-04-10 17:33
    01001001011101000010011101110011001000000110110101100101:
    This reminds me of a story:

    Two penny-pinching executives (we'll call them Bill and Ted) need to drive across the country for a conference (just go with me here...) Bill purchases a new Honda Accord for the drive. It's a nice call, but not too fancy. It cost him $28000. Ted says to Bill, "A new Honda! What a waste, you pay too much for the name, you loose money as soon as you drive it off the lot!" Ted then purchased a 12 year old used car for $2000.

    […]
    Meanwhile, a third guy called Rufus (an engineer by training, obviously) takes the time machine, errr, plane at a cost of a few hundred bucks, even allowing for the hire car at the other end. And he saved a lot of time too while those other two losers were stuck on the interstate. (Excellent!)

    The moral of this? While penny-pinching can obviously make things worse, sometimes it is best to take a step back from the immediate task and work out what the actual goal is so that you can go for the right solution.
  • Americium 2009-04-10 17:38
    Max:
    Even QuickBasic had a function to make spaces...

    Space$(i%)


    6502 Assembler has one too. Just loop through screen memory & write space characters. Memory starts at $4000 in this example.

    2000 LDY #$0A
    2002 LDA #$20
    2004 STA $4000, Y
    2006 DEY
    2008 BNE 2000

    Y-register is the loop counter, starting a 10 spaces (hex 0A), counting down. The Accumlator holds SPACE (hex 20) to be written to memory. The SPACES array starts a memory location hex 4000. The built-in SPACES(#) probably does this.

    Storing the spaces as constant arrays is wasteful in any era.
  • pink_fairy 2009-04-10 19:13
    Maks Verver:
    Fair point; an even more common example might be (general) matrix multiplication.

    Still, allowing 3 * 'foo' and 'foo' * 3 to evaluate to the same result seems more sensible to me, since 3 isn't a quaternion or a matrix here, but just a simple integer. This seems more in line with the principle of least astonishment, although I'll admit this is a bit subjective.

    (The problem with Perl of course, is that the language doesn't distinguish between integers and strings but regards both as scalar values, so the interpreter only considers the positions of the arguments to decide which one is a string and which one is a number, and as a result 1x'foo' yields an empty string. Not very obvious at first glance, in my opinion.)
    You're being a bit unfair to Perl there. It's got scalars, it's got lists (with an awful auto-flattening implementation, I grant you), and it's got hashes. I mean, what more could you want?

    Quaternions? They're, like, so Nineteenth Century.

    I'd argue that Perl does precisely what you want here -- "the principle of least astonishment." I believe Larry puts it differently ... something along the lines of "Perl always tries to guess what you actually meant."

    Now. If you're dealing with quaternions, would you rather have an empty string? Or would you rather have the abortion shown in the OP?

    Perl5: Strings are everything. And there's nothing you can't do unless you're incapable of writing a suitable regexp.

    Perl6: Superstrings -- coming to your neighborhood real soon! Superstrings spit on your quaternions! Also, check out the new Norris::Chuck module.

  • pink_fairy 2009-04-10 19:25
    Code Dependent:
    <snip/>C rap
    Hell, yes!.

    The world would be better with background music provided by C-Rap. I can't understand why those '60s guys at Dartmouth didn't get this fairly obvious point.

    But this is 2009. What we need in 2009 is Saran-Rap ... transparency is everything.
  • pink_fairy 2009-04-10 19:39
    01001001011101000010011101110011001000000110110101100101:
    <snip>Ted</snip>
    01001001011101000010011101110011001000000110110101100101, I can see you on Google Earth. We really do know where you live. And, believe me, we will use this information.

    What you need, my man, is Base64. Preferably twice.

    Also, I believe you've got the thirteenth nibble wrong. Time to upgrade to VB5.
  • mjc 2009-04-10 21:21
    sounds like you need a little git ;)
  • ratchetr 2009-04-10 22:39
    Americium:
    Max:
    Even QuickBasic had a function to make spaces...

    Space$(i%)


    6502 Assembler has one too. Just loop through screen memory & write space characters. Memory starts at $4000 in this example.

    2000 LDY #$0A
    2002 LDA #$20
    2004 STA $4000, Y
    2006 DEY
    2008 BNE 2000

    My 6502 is a bit rusty, but that looks like an infinite loop to me.
    You probably wanted:
    2008 BNE 2004


    Storing the spaces as constant arrays is wasteful in any era.

    Perhaps. But if the choice is squandering 10 bytes of garbage collectible memory, or having to debug a hang caused by an infinite loop, I'll squander the memory every time.
    An inefficient solution is infinitely faster than an infinite loop.
  • derula 2009-04-11 04:50
    Maks Verver:
    Fair point; an even more common example might be (general) matrix multiplication.

    Well I was thinking quaternions because if x and y are quaternions, x*y and y*x are both defined. This is not always (well, rarely to be exact) true for matrices.

    Maks Verver:
    Still, allowing 3 * 'foo' and 'foo' * 3 to evaluate to the same result seems more sensible to me, since 3 isn't a quaternion or a matrix here, but just a simple integer.

    While I don't know about Perl, in Ruby i*s doesn't make much sense in an object oriented point of view, seeing that * is a method of Integer here. Integer#* would then perform differently on different kinds of arguments, which seems rather odd. String#* will only have to check if the argument passed is an Integer...

    Edit: Also:
    class Integer
    
    alias old_mult *
    def *(var)
    if var.is_a? String
    var * self
    else
    old_mult(var)
    end
    end
    end
  • pbean 2009-04-11 05:29
    Python and Ruby do this too.

    But Python's version makes the most sense since i*s and s*i (with s a string and i an integer) yield the same result, while the i*s form doesn't work in either Perl or Ruby, even though they suggest commutativity by using a symbol normally used for multiplication.


    It's a method of the string class, so basically: s.multiply(i), which makes sense as you are multiplying a certain string i times. However i.multiply(s) doesn't make that much sense (in my eyes). Also, an asterisk isn't normally used 'irl' for multiplication (just in programming and computers) so the commutativity applies less than you might suggest.

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


    VB is the garbage collector: you type in your code and... there you have it, the garbage!
  • ass-laminate 2009-04-11 05:44
    mjc:
    sounds like you need a little git ;)

    But I am a little git!
  • huge 2009-04-11 05:45
    randomlyVarying:
    Obviously, this guy should learn the mother of all programming languages:

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

    Now I know why M$ Office includesa function to show all whitespace characters.. it's M$'s editor :P which would also explain the bugs featured in every software they create..
  • Mozzis 2009-04-11 11:10
    A$=A$+Left(Spaces$, Len(A$)-60))
    might be better
  • Mike H 2009-04-11 15:27
    The WTF originator didn't push the concept far enough. It was disappointing to see him give up after defining space1 through space10 and space100 and then rely on GenerateSpaces() for those odd numbers when he could have defined spaces11 through, say, spaces1000.

    That's a lot of typing though. Clearly, dynamic type generation is the way to go:


    Public Shared Function GetSpacesType() As Type

    Dim pointlessAssyName As New AssemblyName("PointlessStringLibrary")
    Dim pointlessAssyBldr As AssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(pointlessAssyName, AssemblyBuilderAccess.Run)
    Dim pointlessModBldr As ModuleBuilder = pointlessAssyBldr.DefineDynamicModule(pointlessAssyName.Name)
    Dim spacesTypeBldr As TypeBuilder = pointlessModBldr.DefineType("Spaces", TypeAttributes.Public)

    Dim spacesCtorBldr As ConstructorBuilder = spacesTypeBldr.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, Nothing)
    spacesCtorBldr.GetILGenerator().Emit(OpCodes.Ret)
    Dim staticCtorGen As ILGenerator = spacesStaticCtorBldr.GetILGenerator()

    Dim spacesStaticCtorBldr As ConstructorBuilder = spacesTypeBldr.DefineConstructor(MethodAttributes.Private Or MethodAttributes.RTSpecialName Or MethodAttributes.HideBySig Or MethodAttributes.Private Or MethodAttributes.Static, CallingConventions.Standard, Nothing)

    Dim i As Integer
    Dim fieldValue As String = ""

    For i = 0 To 1000

    fieldValue += " "

    Dim spacesFldBldr As FieldBuilder = spacesTypeBldr.DefineField("Spaces" & i.ToString(), _
    GetType(String), FieldAttributes.Public Or FieldAttributes.Static Or FieldAttributes.InitOnly)

    staticCtorGen.Emit(OpCodes.Ldstr, fieldValue)
    staticCtorGen.Emit(OpCodes.Stsfld, spacesFldBldr)

    Next

    staticCtorGen.Emit(OpCodes.Ret)
    Return spacesTypeBldr.CreateType()

    End Function


    Now you just create an instance of the dynamic type and then magically start using Spaces.Spaces725 or Spaces.Spaces489 whenever necessary.


    Public Shared Sub Main()

    Dim Spaces As Object = Activator.CreateInstance(GetSpacesType())

    Console.WriteLine("W" & Spaces.Spaces25 & "T")
    Console.WriteLine("F" & Spaces.Spaces172 & "!")

    End Sub


    Just remember to set VB.NET's "Option Strict Off" to allow for late-binding and get rid of all that pesky compile-time checking.


  • topcat 2009-04-11 17:25
    It is VB.Net. space1 is a string
  • gerard_ 2009-04-11 19:14
    Clearly it should be (in C) (all wtfs unintentional, like they should be):

    char *spaces;
    char *end;
    int maxLength;

    void initSpaces(int maxLength)
    {
    spaces = malloc(maxLength+1);
    memset(spaces, ' ', maxLength);
    spaces[maxLength] = 0;
    end = spaces + maxLength;
    }

    char *spaces(int length)
    {
    ASSERT(length <= maxLength, "Spaced Out!");
    return end - length;
    }
  • Stefan W. 2009-04-11 22:35
    COMMENT intentionally left SPACY
    
  • thatoneguy 2009-04-12 03:16
    Hey could you color code the spaces or something? Make them blue? I had trouble counting them, thanks!
  • Resistance 2009-04-12 04:35
    Anonymous:
    derula:
    Jeremy:
    Throw some Perl at it:

    $spaces = " " x $num_of_spaces;

    31 chars, including variable names. Done.


    Ruby:

    spaces = " " * num_of_spaces

    28 chars including variable names.


    better:

    spaces = ' ' * num_of_spaces

    Still 28 characters, but uses fewer pixels.

    even better:

    _=' '*i

    7 chars, including variable names. As a bonus, uses least ink on paper
  • hatterson 2009-04-12 12:27
    smbarbour:
    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.

    This is VB. Judging by it being called "old code" it is most likely VB6. I really don't think they were that concerned with wasted CPU or memory cycles.
  • courage dog 2009-04-12 20:16
    How much do such ehm, Experienced Developers, earn on an average?
  • FromCanada 2009-04-13 08:39
    Resistance:

    even better:

    _=' '*i

    7 chars, including variable names. As a bonus, uses least ink on paper


    Oh God
  • Todo: register username 2009-04-13 09:25
    I just loved the way space10 and Mod 10 was used for... code optimization?
  • dunawayc 2009-04-13 18:06
    SpasticWeasel:
    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.


    Unless it's VB.Net in which case they're all strings.

    Incidentally, the String class in .Net has the following constructor:

    Public Sub New (c As Char, count As Integer)



  • D C Ross 2009-04-14 09:59
    FromCanada:
    Resistance:

    even better:

    _=' '*i

    7 chars, including variable names. As a bonus, uses least ink on paper


    Oh God


    That's only six characters, but you're using a lot of extra pixels and I'm not sure that you'll get the correct output.
  • Pim 2009-04-14 10:32
    Americium:

    6502 Assembler has one too. Just loop through screen memory & write space characters. Memory starts at $4000 in this example.

    2000 LDY #$0A
    2002 LDA #$20
    2004 STA $4000, Y
    2006 DEY
    2008 BNE 2000

    My 6502 is a bit rusty too, but the DEY instruction would be stored at $2007, not $2006.
    Also, this stores 10 spaces in $4001 through $400A and leaves $4000 uninitialised. You should have switched the DEY and the STA $4000, Y.
  • BonziBuddy 2009-04-14 10:42
    One word : HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA
  • Al H. 2009-04-14 17:44
    Actually, space100 would be a string since it's explicitly labeled as such; the other variables would be variants (which can contain strings but are less efficient since the compiler/run-time library has to determine what kind of data it contains constantly).
  • Mark 2009-04-14 20:53
    ell0bo:
    I told him to place all constants in /company_configs/company_name.php .

    <b>All</b> constants in one file? Really?
  • TPD 2009-04-15 05:04
    The trdegy is that they missed out on a space1999 global variable
  • Great link for WTF source material buried in this article 2009-04-15 18:22
    L:
    I don't get it : does GenerateSpaces() actually do something ?
    I don't know VB, so maybe I'm missing something...


    It does something, but it is kind of pointless since it doesn't have any outputs or change the system state in any way.
  • Jazzman 2009-04-15 18:37
    The code looks like Visual Basic, and the logic behind the programmer also indicate Visual Basic =)
  • John 2009-04-16 00:17
    My ohhhh my. LOL My ohhhh my.
  • Adam 2009-04-16 00:58
    As my most favorite developer would always say - "If it seems too complicated, you're probably doing it wrong."

  • Bad Person 2009-04-16 20:38
    Please bring back capital punishment.