Dearest /prog/,
This is an actual snippet of production code from a jsp application used by the US health-care system, which I have the misfortune to be developing on. This is not a joke.
public String rnd(double e, double d, int numDigits)
{
String t;
int tempDouble;
double f;
//e=16.47;
//d=47.023;
//out.print(e + " + " + d);
f= e / d;
//out.print("<br>" + f);
Let's have a little game. We'll list all the things we can see that are wrong with it. off the top of my head, I see 4.
1. Perhaps it's just me, but one letter variable names are terrible.
2. No useful commenting
3. It really should be a static method.
4. It's a stupid way of doing a simple task.
Also worthy of note is it seems to behave a little oddly when using large values for numDigits. I gave it vales of 2.222, 4.444444 and 20, and it came out with 2.14748365E-120
Excuse me, fine gentlemen and EXPERT PROGRAMMERS, but can anyone tell me just exactly what this function is supposed to do, I got lost in the ENORMOUS AMOUNTS OF FUCKING STUPIDITY. Thanks.
Takes two numbers, divides the first by the second, and then produces a string containing the result to the number of decimal places specified in numDigits.
Then please share them. A few more I've noticed are:
5. 'tempDouble' is a really stupid name for an int.
6. It's buggy for big values of numDigits.
7. 'rnd' is a rather meaningless function name.
>>16 7. 'rnd' is a rather meaningless function name.
I agree. It should be
public String lptstrRound_double_double_int(double fdFloat1, double fdFloat2, DWORD numDigits);
Name:
Anonymous2009-08-14 13:45
>>16 Takes two numbers, divides the first by the second, and then produces a string containing the result to the number of decimal places specified in numDigits.
Oh, so the rnd is supposed to stand for round? I actually thought it was an attempt at a PRNG.
Then please share them. A few more I've noticed are:
How about the fact that it's violently unaware of String.format?
/*** strRound_fd_fd_dw (double, double, DWORD)
*
* Returns a string as a result of dividing
* the 1st argument by the 2nd, and rounding
* to a number of digits as specified by the
* 3rd argument.
*
*/
public String strRound_fd_fd_dw(double fdFloat1, double fdFloat2, DWORD dwDigits)
{
String str_t;
int i_temp;
double fd_f;
>How about the fact that it's violently unaware of String.format?
I would throw that under point 4, as one of the better ways of doing the given task.
Name:
Anonymous2009-08-14 14:32
>>21
By that token, everything fits in that category.
Name:
Anonymous2009-08-14 14:39
I can't even make out what the code does. ;_;
Name:
Anonymous2009-08-14 15:08
5. 'tempDouble' is a really stupid name for an int.
What's really hilarious is that whoever wrote this puts inst at the end of instance names, so that you know that this is an instance of an object. In JAVA.
Name:
Anonymous2009-08-14 15:18
wats the real wtf XD??
Name:
Anonymous2009-08-14 15:34
>>25
TRWTF is that a bunch of VB programmers think they can recognize bad code.
I hate Alex Parapadarapa so much.
>>30
Don't have such prejudices. Hate everyone, equally.
Name:
Anonymous2009-08-14 22:26
>>30
Probably Spolsky. The TDWTF guys have zero influence outside of their little website, and don't seem intent on acquiring it. Atwood is only dangerous because of Spolsky, and Spolsky is dangerous all by himself.