- 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
Err... WTF? Why not just box the bool, why turn it into a string? And if you have to use a string, why toString() a bool, when you can just write "True"?
Admin
Err... WTF? Why not just box the bool, why turn it into a string? And if you have to use a string, why toString() a bool, when you can just write "True"?
Uhhh cause someone might have #define true to be false
Admin
Admin
<FONT face=Georgia>That's a way to do it, I suppose...</FONT>
<FONT face=Georgia>On a separate note, should we really be allowed to modify other user's quotes? It could lead to embarassing situtations... [<:o)]</FONT>
<FONT face=Georgia></FONT>
Admin
OMGWTFBBQ first post!! Lol pudding.
Yeah. Whatever. Just stealing someone else's glory.
Admin
Uhhh cause someone might have #define true to be false
[:D] I was just reading that as you posted.
Admin
In other news, I just Totally Owned (TM) myself by receiving the 2nd post. This is America, people: winner takes all!
Admin
In C-type code:
int sleep_count = 0;
...
sleep_count = evalulate_expression(int_to_string(sleep_count) + " + 1")
Not to mention that it spawns two programs just to do that.
Admin
I don't know why it's inventive. AFAIK, that's the way it has to be done in a shell script, unless it supports the
$(( ... ))
syntax, in which case you can do:Which isn't really that much smaller or more understandable.
Admin
Admin
Admin
In KSH, just use ((SLEEP_COUNT = SLEEP_COUNT + 1))
Admin
as far as i know using expr is the only way to add two numbers in bourne shell (the most portable shell). anyone have a better way?
Admin
Yes.
let A=B+C
or, in this case,
let ++SLEEP_COUNT
would do the trick.
In ksh,
(( A=$B+$C ))
works, as does
(( ++SLEEP_COUNT ))
Admin
> new Boolean(true).toString()
What programming language is this by chance? If it's VB then the result could be the localized version of truth, such as "waar" or "verdad" so don't assume it comes out "true".
http://www.codecomments.com/archive293-2005-1-376910.html
Of course, this makes it even more of a WTF because I doubt that the SQL query expects "waar".
What's it good for? Absolutely nothing!
Admin
The increment is pretty standard in some shell scripts.
See http://www.nacse.org/demos/coping-with-unix/coping-with-unix/node161.html
Admin
Sorry, read 'Bourne', thought 'bash'. My bad. But the ksh suggestions are still valid :-)
Admin
No better way in Bourne shell, as far as I know.
I figure the author just wanted to keep the script as portable as possible. When I want to write a shell script I expect may need to run on other Unix systems, I stick to basic Bourne shell syntax.
It's only a WTF if it's certain to only be used on Linux forever. And not a very big WTF.
Personally I hate Korn shell anyway. There's something to be said for the small, straightforward syntax rule set of Bourne shell.
Admin
Ugh, unfortunatly I see that crap all the time. It just goes to show, web monkeys should NOT be considered programmers...
I feel generous calling them monkeys.
Admin
Probably best not to rag on someone's spelling when you yourself haven't mastered the apostrophe yet :)
Admin
#define false 1
<FONT size=+0>#define</FONT> true 0
Because we all know FEMALE = 0 and MALE=1. Women are always right and men are always wrong.
Admin
sh -- notice its sh not bash -- does this:
echo $((1+1))
2
so the portability issues dont matter. that said, the expr version, is the one recomened by the man page. I assume this was a bash programer forced to use ksh? Remember that ksh inst free (beer of freedom).
Admin
It's not VB. It looks close to VB .Net, but it's not that because the line ends with a semicolon. Maybe C#?
Admin
I am guessing from the casing of the toString() method that this would probably be java. In .net, it would be ToString().
Admin
AAAHHH!!!
Which brings up something I often thing about: how can coders, who must master a precise syntax and set of symbols, how can they turn out to be such bad, bad spellers? I mean, do they first code:
<FONT face="Courier New">SELLECK some_id FRUM some_table WERE cst > 2.5</FONT>
and then after the usual errors, maybe go back and correct it? Or will most editing environments auto-correct that stuff?
Admin
It's got to be Java because "toString" starts with a lower case t. According to Sun it's always supposed to return "true" or "false" so you don't have to worry about locale-type stuff.
Admin
Yes, quite hilarious. Even worse, I carefully re-read what I type, given the comment's subject matter.
Admin
Yes, it is Java. And it is not outside the realm of possibility that the programmer imagined that they were supporting internationalization or wanted to be ultra-sure they were getting the string representation of the boolean true. It's a fairly minor WTF.
Admin
Ah, "I tested on one particular implementation of sh and it worked, therefore portability doesn't matter"
Nice.
FYI, Solaris 10 /bin/sh:
$ echo $((1+1))
syntax error: `(' unexpected
Some sh implementations have this feature, some (like Solaris -- bringing you tomorrow's kernel technology with the userland of 1982!) don't. And then there are systems where sh *is* bash...
Admin
What? It went through my spell check just fine...
Admin
I have seen it down as follows:
nUID=`echo $nUID+1 | bc`
Admin
It's Java.
Admin
I think it's pretty unlikely this was created by hand. More likely it was server-generated code from some backend system. If someone actually wrote this by hand, then yeah - it's much more of a WTF.
Admin
It's not really a WTF. Performing arithmetic with expr is actually standard for bourne shell, since it does not support arithmetic expansion. The way "export" is used in front of the variable is korn shell-ish; in bourne shell, this would read "SLEEP_COUNT=...; export SLEEP_COUNT". So I'd guess that this was a bourne shell programmer who'd switched to korn shell and had already learned that you can export variables in one command, but hadn't learned about arithmetic expansion yet.
In fact, I frequently write scripts in bourne shell, with expr and whatnot. It's the only shell you can rely on if you're packaging Solaris software.
Regards, Felix.
Admin
The hardest posts to get correct are the ones complaining about someone else's spelling!
I'm pretty sure there are no spelling errors in this wun.
Admin
A motivation for "new Boolean(true).toString()" might be an attempt for optimization: the toString() may be perceived as more efficient than creating a new "true" String each time. However, because Java uses String interning, the most optimal solution would be to just write "true". :)
Admin
$(()) is part of the POSIX shell standard. Sun, in their infinite wisdom, ships a perfectly POSIX-compliant shell as /usr/xpg4/bin/sh, keeping the old untouched-since-1982 Bourne shell in /bin/sh apparently for backwards compatibility.
This is all a moot point, of course, because the script says ksh, and ksh has always had this feature. (Lack of such a feature in the original Bourne shell was part of the inspiration for writing ksh in the first place.)
Admin
This is bad for a couple reasons. First, the programmer doesn't know how to increment variables in shell, which isn't such a big deal in and of itself. Every shell is different, and ksh and the other older shells are WTFs unto themselves, anyway.
Unfortunately, instead of typing 'man ksh' and looking for the section on arithmetic, he chose to spawn a subprocess to evaluate the expression and store the output of the subshell into the variable.
I'm not overly familiar with ksh myself, but it took me about 30 seconds to find how to do this from the man page:
let VAR=1
echo $VAR # prints 1
let VAR=$VAR+1
echo $VAR # prints 2
No big deal, and no overhead of spawning subprocesses for silly evaluations. Sadly, it probably took him longer to figure out this approach than it would have to read the correct way from the man page.
Admin
why not just do the static Boolean.TRUE.toString() and save yourself an object creation? Oh right, because the programmer obviously doesn't know what s/he's doing.
Admin
It also occurrs to me that this is one way to make sure javascript is turned on. I use NoScript in FireFox, and come across plenty of pages that use links like this to force you to enable JS. That, or they're just idiots.
Admin
Hey now, Solaris has ksh and bash, and you should know if you have 10 that it has GNOME too.
But let's not get into ksh vs ksh93 :-)
Admin
Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.
Admin
I'm not sure exactly why this guy/girl decided to use the onclick event to open a link, however there are some differences that may have justified the logic.
1.) Events can't be cancelled by the user, like links can (e.g. pressing ESC, or the STOP button)
2.) Developer may have wanted to "hide" the url... although I don't know why
3.) They may have done all links like this, but with some adding more JS... conditions etc.
4.) Ditto 3, if it was generated code
5.) They may have done some link tracking, that isn't apparent now... or was removed...
6.) Or, yeah, just plain old WTF!?
Admin
It wouldn't be optimisation as that would be Boolean.TRUE.toString() so you use the global static instance of true and don't create a new Boolean object. However, you're right that "true" would be even better. But then again, I shudder to think how bad a piece of software could be if optimising this kind of thing would make a difference. That or they need to upgrade their 386...
Admin
Pure Evil.
This is so wonderfully evil.
It reminds me of the time I intentionally hid some code by indenting it into the horizon.
Admin
Actually, I reckon this is from code that heavily used the strcmp family of functions - they return 0 if two strings are equal, so you end up with a lot of code like if(strcmp(str1, str2) == 0) all over the place (yes, I know you shouldn't use strcmp anyway, but bear with me). These funky defines would let you write if(strcmp(str1, str2) == true) which is slightly more readable - at the expense of making the rest of your code an impenetrable nightmare.
On the other hand, writing
if( strcmp( str1, str2 ) == false )
is a nice way to shoot yourself in your foot.
Admin
On the other hand, writing
if( strcmp( str1, str2 ) == false )
is a nice way to shoot yourself in your foot.
You're referring, I think, to the fact that srcmp might return -1, so the false test would fail. Good point. Perhaps this is where one of those famous tri-bools that show up so often could be used? Something like if(strcmp(str1, str2) == FILE_NOT_FOUND)
Admin
I don't know if you noticed the variable name? It was "SLEEP_COUNT". If you're calculating how many times you've done a sleep(1), or you're calculating how long to sleep(1) the next time, the couple of extra milliseconds that doing the calculation this way hardly matters in the long run.
Not if he did it that way because that's the way he's been doing it since real live Bourne shell sh was the only shell in the world. I don't do math in shell scripts much (because if I need to do math, the script probably should be in perl), but when I do, I do increments that same way.
Admin
I wonder if someone's written a Greasemonkey script to spot the most common forms of this and rewrite them to normal hyperlinks? Probably, I expect. (Unfortunately, being a Konqueror user I have no equivalent to Greasemonkey available).
Admin
Very interesting theory about making sure javascript is on. Maybe this isn't a WTF after all...