Comment On A Friday Mixer

In case you haven't gotten your fill of bad code for the week, here are a few "quickies" ... [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: A Friday Mixer

2006-03-03 15:07 • by Whiskey Tango Foxtrot? Over.

Let's start out with this single line from Victor Bilyk, who's predecessor liked the long way of writing "true" ...



cbfQry.addParameter( "authenticate_required", new Boolean(true).toString() );

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"?

Re: A Friday Mixer

2006-03-03 15:10 • by chrismcb
62770 in reply to 62769
Anonymous:

Let's start out with this single line from Victor Bilyk, who's predecessor liked the long way of writing "true" ...



cbfQry.addParameter( "authenticate_required", new Boolean(true).toString() );

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

Re: A Friday Mixer

2006-03-03 15:10 • by Whiskey Tango Foxtrot? Over.
The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?


#define false 1

#define true 0
Heh.... I'm guessing evil exiting former-programmer. [:)]

Re: A Friday Mixer

2006-03-03 15:11 • by BiggBru
Alex Papadimoulis:


That's a way to do it, I suppose...


Alex Papadimoulis:


I love Oracle so much, I would marry it in San Francisco



On a separate note, should we really be allowed to modify other user's quotes? It could lead to embarassing situtations... [<:o)]


 


 

Re: A Friday Mixer

2006-03-03 15:11 • by meepster
OMGWTFBBQ first post!! Lol pudding.

Yeah. Whatever. Just stealing someone else's glory.

Re: A Friday Mixer

2006-03-03 15:11 • by Whiskey Tango Foxtrot? Over.
62774 in reply to 62770
chrismcb:
Anonymous:

Let's start out with this single line from Victor Bilyk, who's predecessor liked the long way of writing "true" ...



cbfQry.addParameter( "authenticate_required", new Boolean(true).toString() );

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



[:D] I was just reading that as you posted.

Re: A Friday Mixer

2006-03-03 15:12 • by meepster
62775 in reply to 62773
In other news, I just Totally Owned (TM) myself by receiving the 2nd post. This is America, people: winner takes all!

Re: A Friday Mixer

2006-03-03 15:13 • by .*
Alex Papadimoulis:
Since I know nothing about Linux/Unix, I showed this next snippet of korn script (from Simmoril)to a Linux guy. He thought it was worth posting and said it was one of the more inventive ways to increment a variable. Anyone care to explain why?



#!/bin/ksh



[... ommitting unimportant code...]



export SLEEP_COUNT=`expr $SLEEP_COUNT + 1`




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.

Re: A Friday Mixer

2006-03-03 15:13 • by Omnifarious
Alex Papadimoulis:

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:


export SLEEP_COUNT=$(( $SLEEP_COUNT + 1 ))

Which isn't really that much smaller or more understandable.


Re: A Friday Mixer

2006-03-03 15:15 • by Colin
Alex Papadimoulis:

Since I know nothing about Linux/Unix, I showed this next snippet of korn script (from Simmoril)to
a Linux guy. He thought it was worth posting and said it was one of the
more inventive ways to increment a variable. Anyone care to explain
why?


#!/bin/ksh 

[... ommitting unimportant code...]

export SLEEP_COUNT=`expr $SLEEP_COUNT + 1`

Re: A Friday Mixer

2006-03-03 15:16 • by DSx
private static final String MBS_PASSWORD = "f4rth9fe".toUpperCase();

I think what the real WTF is on that one, is that if you're going to hard-code a constant that always gets transformed to upper case, why not just hard-code it in upper case?

Re: A Friday Mixer

2006-03-03 15:19 • by .*
62781 in reply to 62777
Omnifarious:
Alex Papadimoulis:
Since I know nothing about Linux/Unix, I showed this next snippet of korn script (from Simmoril)to a Linux guy. He thought it was worth posting and said it was one of the more inventive ways to increment a variable. Anyone care to explain why?


#!/bin/ksh 


[... ommitting unimportant code...]

export SLEEP_COUNT=`expr $SLEEP_COUNT + 1`


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:


export SLEEP_COUNT=$(( $SLEEP_COUNT + 1 ))

Which isn't really that much smaller or more understandable.



In KSH, just use ((SLEEP_COUNT = SLEEP_COUNT + 1))

Re: A Friday Mixer

2006-03-03 15:29 • by mlathe
62786 in reply to 62781
Anonymous:
Omnifarious:
Alex Papadimoulis:
Since I know nothing about Linux/Unix, I showed this next snippet of korn script (from Simmoril)to a Linux guy. He thought it was worth posting and said it was one of the more inventive ways to increment a variable. Anyone care to explain why?


#!/bin/ksh 


[... ommitting unimportant code...]

export SLEEP_COUNT=`expr $SLEEP_COUNT + 1`

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:

export SLEEP_COUNT=$(( $SLEEP_COUNT + 1 ))

Which isn't really that much smaller or more understandable.


In KSH, just use ((SLEEP_COUNT = SLEEP_COUNT + 1))


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?

Re: A Friday Mixer

2006-03-03 15:32 • by qu1j0t3
62788 in reply to 62786
mlathe:

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?




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 ))


Re: A Friday Mixer

2006-03-03 15:34 • by Dave

> 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!


 

Re: A Friday Mixer

2006-03-03 15:34 • by Otto
62790 in reply to 62781

The increment is pretty standard in some shell scripts.


See http://www.nacse.org/demos/coping-with-unix/coping-with-unix/node161.html

Re: A Friday Mixer

2006-03-03 15:36 • by qu1j0t3
62791 in reply to 62788
Sorry, read 'Bourne', thought 'bash'. My bad. But the ksh suggestions are still valid :-)

Re: A Friday Mixer

2006-03-03 15:36 • by VGR
62792 in reply to 62786
mlathe:
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?




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.

Re: A Friday Mixer

2006-03-03 15:37 • by Drakonite


&lt;a href="#" onclick="location='http://www.sun.com'; return false;"&gt;


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.



Re: A Friday Mixer

2006-03-03 15:39 • by Slacker
...who's predecessor seemed to really have some trouble with predicate logic ... and spelling ...




Probably best not to rag on someone's spelling when you yourself haven't mastered the apostrophe yet :)

Re: A Friday Mixer

2006-03-03 15:41 • by xcor057

#define false 1
#define true 0


Because we all know FEMALE = 0 and MALE=1.  Women are always right and men are always wrong.

Re: A Friday Mixer

2006-03-03 15:42 • by Pinguis
62796 in reply to 62777
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).


Re: A Friday Mixer

2006-03-03 15:46 • by Manni
62797 in reply to 62789
Anonymous:

> 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!


 



It's not VB. It looks close to VB .Net, but it's not that because the line ends with a semicolon. Maybe C#?

Re: A Friday Mixer

2006-03-03 15:52 • by Martin
62798 in reply to 62789
Anonymous:

> 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".



 


I am guessing from the casing of the toString() method that this would probably be java. In .net, it would be ToString().

Re: A Friday Mixer

2006-03-03 15:53 • by R.Flowers


#define false 1
#define true 0



AAAHHH!!!



predecessor seemed to really have some trouble with predicate logic ... and spelling ...



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:


SELLECK some_id FRUM some_table WERE cst > 2.5


and then after the usual errors, maybe go back and correct it? Or will most editing environments auto-correct that stuff?

Re: A Friday Mixer

2006-03-03 15:53 • by sum yung guy
62800 in reply to 62797
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.

Re: A Friday Mixer

2006-03-03 15:55 • by R.Flowers
62801 in reply to 62799
R.Flowers:

 


Which brings up something I often thing about...



Yes, quite hilarious. Even worse, I carefully re-read what I type, given the comment's subject matter.

Re: A Friday Mixer

2006-03-03 16:01 • by Jon
62804 in reply to 62798
Martin:
Anonymous:

> 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".



 


I am guessing from the casing of the toString() method that this would probably be java. In .net, it would be ToString().


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.

Re: A Friday Mixer

2006-03-03 16:02 • by frzx
62805 in reply to 62796
Anonymous:
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).





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...

Re: A Friday Mixer

2006-03-03 16:04 • by J
62806 in reply to 62801
What?  It went through my spell check just fine...

Re: A Friday Mixer

2006-03-03 16:05 • by Jon
62807 in reply to 62786
mlathe:
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?


I have seen it down as follows:

nUID=`echo $nUID+1 | bc`

Re: A Friday Mixer

2006-03-03 16:05 • by mthamil
62808 in reply to 62797
Manni:
Anonymous:

> 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!


 



It's not VB. It looks close to VB .Net, but it's not that because the line ends with a semicolon. Maybe C#?



It's Java.

Re: A Friday Mixer

2006-03-03 16:16 • by RaelShark
62810 in reply to 62793
Drakonite:


&lt;a href="#" onclick="location='http://www.sun.com'; return false;"&gt;


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.



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.

Re: A Friday Mixer

2006-03-03 16:22 • by Felix

#!/bin/ksh

export SLEEP_COUNT=`expr $SLEEP_COUNT + 1`


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.

Re: A Friday Mixer

2006-03-03 16:24 • by stevekj
62812 in reply to 62801
R.Flowers:
R.Flowers:

 


Which brings up something I often thing about...



Yes, quite hilarious. Even worse, I carefully re-read what I type, given the comment's subject matter.



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.

Re: A Friday Mixer

2006-03-03 16:25 • by shatter
62813 in reply to 62804
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". :)

Re: A Friday Mixer

2006-03-03 16:30 • by beinsane
62814 in reply to 62805
Anonymous:
Anonymous:
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).





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...




$(()) 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.)

Re: A Friday Mixer

2006-03-03 16:35 • by WTF Batman
Alex Papadimoulis:


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.


Re: A Friday Mixer

2006-03-03 16:35 • by ArikTheRed
62816 in reply to 62813
shatter:
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". :)
If the programmer was really doing it to be optimized, then
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.

Re: A Friday Mixer

2006-03-03 16:40 • by WTF Batman
62817 in reply to 62793
Drakonite:


&lt;a href="#" onclick="location='http://www.sun.com'; return false;"&gt;


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.




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.

Re: A Friday Mixer

2006-03-03 16:55 • by elmegil
62819 in reply to 62805
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 :-)

Re: A Friday Mixer

2006-03-03 17:00 • by Russ
62820 in reply to 62771
Anonymous:
The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?


#define false 1

#define true 0
Heh.... I'm guessing evil exiting former-programmer. [:)]


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.

Re: A Friday Mixer

2006-03-03 17:10 • by Stevie
62821 in reply to 62817
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!?

Re: A Friday Mixer

2006-03-03 17:26 • by Cowboy Bob
62822 in reply to 62813
shatter:
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". :)




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...

Re: A Friday Mixer

2006-03-03 17:27 • by Ralph the parrot
Alex Papadimoulis:


 


Pure Evil.
This is so wonderfully evil.
It reminds me of the time I intentionally hid some code by indenting it into the horizon.

Re: A Friday Mixer

2006-03-03 17:46 • by cvi
62824 in reply to 62820
Anonymous:
Anonymous:
The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?


#define false 1
#define true 0
Heh.... I'm guessing evil exiting former-programmer. [:)]


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.

Re: A Friday Mixer

2006-03-03 18:02 • by Russ
62825 in reply to 62824
Anonymous:
Anonymous:
Anonymous:
The next two lines of code took Christophe Beugnet hours and hours to correct. Who would have guessed that a supplier would have modified a header with this?


#define false 1
#define true 0
Heh.... I'm guessing evil exiting former-programmer. [:)]


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.


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)

Re: A Friday Mixer

2006-03-03 18:03 • by ptomblin
62826 in reply to 62815
WTF Batman:

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 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.

WTF Batman:

Sadly, it probably took him longer to figure out this approach than it would have to read the correct way from the man page.

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.

Re: A Friday Mixer

2006-03-03 18:18 • by makomk
62827 in reply to 62817
WTF Batman:
Drakonite:


&lt;a href="#" onclick="location='http://www.sun.com'; return false;"&gt;


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.




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.


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).

Re: A Friday Mixer

2006-03-03 18:25 • by OneFactor
62828 in reply to 62817
WTF Batman:
Drakonite:

&lt;a href="#" onclick="location='http://www.sun.com'; return false;"&gt;


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.




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.


Very interesting theory about making sure javascript is on. Maybe this isn't a WTF after all...

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment