- 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
Admin
Ruby:
spaces = " " * num_of_spaces
28 chars including variable names.
Admin
better:
spaces = ' ' * num_of_spaces
Still 28 characters, but uses fewer pixels.
Admin
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.
Admin
Python and Ruby do this too.
But Python's version makes the most sense since is and si (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.
Admin
Admin
Admin
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.
Admin
Too cool to use the String(n , " ") function?
Reinvent reinvent reinvent
Admin
Here at TDWTF, we're always up for fresh insight.
No Soup For You!
Admin
I guess you don't have to deal with quaternions a lot then.
Admin
Admin
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.)
Admin
Admin
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.
Admin
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()
Admin
Silly comments! SSpace is actually a string that's 50 spaces
Admin
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...
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
What you need, my man, is Base64. Preferably twice.
Also, I believe you've got the thirteenth nibble wrong. Time to upgrade to VB5.
Admin
sounds like you need a little git ;)
Admin
Admin
Edit: Also:
Admin
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.
VB is the garbage collector: you type in your code and... there you have it, the garbage!
Admin
Admin
Admin
A$=A$+Left(Spaces$, Len(A$)-60)) might be better
Admin
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:
Now you just create an instance of the dynamic type and then magically start using Spaces.Spaces725 or Spaces.Spaces489 whenever necessary.
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.
Admin
It is VB.Net. space1 is a string
Admin
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; }
Admin
Admin
Hey could you color code the spaces or something? Make them blue? I had trouble counting them, thanks!
Admin
_=' '*i
7 chars, including variable names. As a bonus, uses least ink on paper
Admin
Admin
How much do such ehm, Experienced Developers, earn on an average?
Admin
Oh God
Admin
I just loved the way space10 and Mod 10 was used for... code optimization?
Admin
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)
Admin
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.
Admin
Admin
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
Admin
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).
Admin
Admin
The trdegy is that they missed out on a space1999 global variable
Admin
It does something, but it is kind of pointless since it doesn't have any outputs or change the system state in any way.
Admin
The code looks like Visual Basic, and the logic behind the programmer also indicate Visual Basic =)
Admin
My ohhhh my. LOL My ohhhh my.