Comment On Spaced Out

"While going through some old code," John Preston writes, "I found this interesting set of global variables." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Spaced Out

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

Oh, yeah... fist!

Re: Spaced Out

2009-04-10 09:04 • by 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.

Re: Spaced Out

2009-04-10 09:06 • by L (unregistered)
I don't get it : does GenerateSpaces() actually do something ?
I don't know VB, so maybe I'm missing something...

Re: Spaced Out

2009-04-10 09:07 • by DOA
This is your code. This is your code on drugs.

Re: Spaced Out

2009-04-10 09:08 • by moz (unregistered)
255171 in reply to 255167
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).

Re: Spaced Out

2009-04-10 09:09 • by 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.

Re: Spaced Out

2009-04-10 09:10 • by 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.

Re: Spaced Out

2009-04-10 09:17 • by 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.

Re: Spaced Out

2009-04-10 09:24 • by Rocco (unregistered)

Spaces... the final frontier.


umm... line.padright(n)

Re: Spaced Out

2009-04-10 09:35 • by SpasticWeasel (unregistered)
255177 in reply to 255173
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.

Re: Spaced Out

2009-04-10 09:37 • by evilripper (unregistered)
hahahaha this code broke my brain! :-D

bye bye


http://www.evilripper.net

Re: Spaced Out

2009-04-10 09:52 • by 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.

Re: Spaced Out

2009-04-10 09:53 • by Max (unregistered)
Even QuickBasic had a function to make spaces...

Space$(i%)

Re: Spaced Out

2009-04-10 09:55 • by nobody (unregistered)
255181 in reply to 255179
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...

Re: Spaced Out

2009-04-10 09:56 • by randomlyVarying (unregistered)
Obviously, this guy should learn the mother of all programming languages:

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

Re: Spaced Out

2009-04-10 09:59 • by 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=

Re: Spaced Out

2009-04-10 10:02 • by Capt. Kirk (unregistered)
255184 in reply to 255181
nobody:
Cpt Kirk: who are you?

Why I'm the master of all space, of course. I thought that would be obvious.

Re: Spaced Out

2009-04-10 10:05 • by Code Dependent
255185 in reply to 255179
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.

Re: Spaced Out

2009-04-10 10:08 • by 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.

Re: Spaced Out

2009-04-10 10:12 • by Capt. Kirk (unregistered)
255188 in reply to 255185
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.

Re: Spaced Out

2009-04-10 10:17 • by derula
Call GenerateComments(1)

Can't believe nobody said that yet.

Re: Spaced Out

2009-04-10 10:21 • by smbarbour
255190 in reply to 255168
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.

Re: Spaced Out

2009-04-10 10:21 • by pink_fairy
255191 in reply to 255172
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!

Re: Spaced Out

2009-04-10 10:26 • by 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.

Re: Spaced Out

2009-04-10 10:27 • by mauhiz (unregistered)
that was actually the tip of the iceberg. There are other similar global variables for most characters too.

Re: Spaced Out

2009-04-10 10:29 • by Neil (unregistered)
255194 in reply to 255186
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?

Re: Spaced Out

2009-04-10 10:30 • by Beldar the Phantom Replier
First out loud WTF I've had from this site in a while.

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

Re: Spaced Out

2009-04-10 10:30 • by jimlangrunner
255196 in reply to 255191
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?

Re: Spaced Out

2009-04-10 10:31 • by JL (unregistered)
255197 in reply to 255168
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.)

Re: Spaced Out

2009-04-10 10:33 • by 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)


Re: Spaced Out

2009-04-10 10:35 • by jimlangrunner
255199 in reply to 255192
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.

Re: Spaced Out

2009-04-10 10:36 • by jimlangrunner
255200 in reply to 255198
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!

Re: Spaced Out

2009-04-10 10:36 • by Mr. Mackey (unregistered)
Enough of your skylarkings! Mmmmkay?

Re: Spaced Out

2009-04-10 10:45 • by pink_fairy
255202 in reply to 255196
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.

Re: Spaced Out

2009-04-10 10:48 • by Dennis (unregistered)
What we need is a language with a compile-time garbage collector!

Re: Spaced Out

2009-04-10 10:51 • by Mike H
255205 in reply to 255197
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....

Re: Spaced Out

2009-04-10 11:06 • by ih8u (unregistered)
255207 in reply to 255196
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.

Re: Spaced Out

2009-04-10 11:13 • by pink_fairy
255208 in reply to 255207
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?

Re: Spaced Out

2009-04-10 11:17 • by 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. </flame bait>

Re: Spaced Out

2009-04-10 11:19 • by 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

Re: Spaced Out

2009-04-10 11:21 • by Loren Pechtel (unregistered)
255211 in reply to 255198
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.

Re: Spaced Out

2009-04-10 11:22 • by darsal (unregistered)
255212 in reply to 255210
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

Re: Spaced Out

2009-04-10 11:26 • by pink_fairy
255213 in reply to 255209
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!

Re: Spaced Out

2009-04-10 11:30 • by Code Dependent
255214 in reply to 255202
pink_fairy:
Dysfunctional languages, that's the way to go.
Soitainly! They were the inspiration for my nick.

Re: Spaced Out

2009-04-10 11:31 • by Code Dependent
255215 in reply to 255209
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?

Re: Spaced Out

2009-04-10 11:35 • by DaveAronson
Clearly he's a space cowboy. (You SHOULDA been ready for that!)

Re: Spaced Out

2009-04-10 11:41 • by pink_fairy
255218 in reply to 255214
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.

Re: Spaced Out

2009-04-10 11:47 • by Anonymous Coward (unregistered)
255219 in reply to 255215
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.

Re: Spaced Out

2009-04-10 11:59 • by 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.

Re: Spaced Out

2009-04-10 12:09 • by Code Dependent
255223 in reply to 255220
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
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment