| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
The author was obviously spaced when he wrote this.
Oh, yeah... fist! |
|
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. |
|
I don't get it : does GenerateSpaces() actually do something ?
I don't know VB, so maybe I'm missing something... |
|
This is your code. This is your code on drugs.
|
You could use that, I suppose, but it would do the wrong thing if you called GenerateSpaces(-4). |
|
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. |
|
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. |
|
I just can't believe they didn't implement this as a For-Case loop. That's the obvious correct instantiation.
|
|
Spaces... the final frontier. umm... line.padright(n) |
Re: Spaced Out
2009-04-10 09:35
•
by
SpasticWeasel
(unregistered)
|
Everything except space100 is a variant. |
|
|
|
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. |
|
Even QuickBasic had a function to make spaces...
Space$(i%) |
|
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...
|
|
Obviously, this guy should learn the mother of all programming languages:
http://en.wikipedia.org/wiki/Whitespace_(programming_language) |
|
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)
|
Why I'm the master of all space, of course. I thought that would be obvious. |
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. |
|
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)
|
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. |
|
Call GenerateComments(1)
Can't believe nobody said that yet. |
Yes, it wastes a ton of memory and CPU cycles. |
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! |
|
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. |
|
that was actually the tip of the iceberg. There are other similar global variables for most characters too.
|
Wouldn't it have been easier just to revert his changes from the repository? |
|
First out loud WTF I've had from this site in a while.
All I can say is "It's about time." |
No -- TRWTF is the choice of language, as always (FLAMEFLAMEFLAMEFLAMEFLAME). There. Is that flaming enough? |
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.) |
|
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) |
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. |
Looks like BBx to me. MY EYES! THEY ARE BLEEDING! |
|
Enough of your skylarkings! Mmmmkay?
|
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. |
|
What we need is a language with a compile-time garbage collector!
|
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.... |
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. |
Oh dear. You are aware that people are going to misquote you egregiously for their own sad little purposes, aren't you? |
|
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> |
|
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)
|
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. |
|
Oh, yeah:
|
The PHP Asbestos Gloves! They do nothing! |
Soitainly! They were the inspiration for my nick. |
Chicken/egg. Which came first, the developer or the language? |
|
Clearly he's a space cowboy. (You SHOULDA been ready for that!)
|
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)
|
Simple. If the dev was born before the language was invented, problem solved. |
|
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. |
I thought it was: B usiness A ctivity S tuck I n C rap |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |