- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The author was obviously spaced when he wrote this.
Oh, yeah... fist!
Admin
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.
Admin
I don't get it : does GenerateSpaces() actually do something ? I don't know VB, so maybe I'm missing something...
Admin
This is your code. This is your code on drugs.
Admin
Admin
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.
Admin
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.
Admin
I just can't believe they didn't implement this as a For-Case loop. That's the obvious correct instantiation.
Admin
Spaces... the final frontier.
umm... line.padright(n)
Admin
Everything except space100 is a variant.
Admin
As a customer your choices are:
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
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:
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
Save a bunch of money and get exactly the same thing.
Admin
Even QuickBasic had a function to make spaces...
Space$(i%)
Admin
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...
Admin
Obviously, this guy should learn the mother of all programming languages:
http://en.wikipedia.org/wiki/Whitespace_(programming_language)
Admin
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=
Admin
Admin
Admin
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.
Admin
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.
Admin
Call GenerateComments(1)
Can't believe nobody said that yet.
Admin
Admin
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!
Admin
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.
Admin
that was actually the tip of the iceberg. There are other similar global variables for most characters too.
Admin
Admin
First out loud WTF I've had from this site in a while.
All I can say is "It's about time."
Admin
There. Is that flaming enough?
Admin
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.)
Admin
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)
Admin
I bow to your restraint as evidenced by your lack of prison sentence.
Admin
MY EYES! THEY ARE BLEEDING!
Admin
Enough of your skylarkings! Mmmmkay?
Admin
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.
Admin
What we need is a language with a compile-time garbage collector!
Admin
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.
Ugh.
ETA:
Ah, it was a VB.NET property. Well at least it's scoped to an instance....
Admin
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.
Admin
You are aware that people are going to misquote you egregiously for their own sad little purposes, aren't you?
Admin
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>
Admin
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
Admin
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.
Admin
Oh, yeah:
Admin
Admin
Admin
Admin
Clearly he's a space cowboy. (You SHOULDA been ready for that!)
Admin
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.
Admin
Simple. If the dev was born before the language was invented, problem solved.
Admin
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.
Admin
B usiness A ctivity S tuck I n C rap
Admin
Throw some Perl at it:
$spaces = " " x $num_of_spaces;
31 chars, including variable names. Done.