Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

fucking fuck

Name: Anonymous 2009-08-13 11:57

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);
   
    //out.print("<br>f=" + f);
    tempDouble=(int)((f)* Math.pow(10,numDigits+1));
    //out.print("<br>tempDouble=" + tempDouble);
    f=(double)tempDouble;
    f=f/10;
    f=Math.round(f);
    //out.print("<br>f=" + f);
    //out.print("<br>" +tempDouble + " " + f/Math.pow(10,numDigits));

    t=Double.toString(f/Math.pow(10,numDigits));
    if (t.substring(t.indexOf('.'),t.length()).length() < numDigits+1)
        t=t+'0';
    //out.print("<br>" + t);
    if (t.compareTo("0.00")==0)
        t="0.0";
    return t;
}

Name: Anonymous 2009-08-13 12:10

i dont care - i just masturbated.

Name: Anonymous 2009-08-13 12:11

fail. GTFO

Name: Anonymous 2009-08-13 12:11

>>1
Is there an actual reason for turning this double into a string, or is this just a completely ingenious way of rounding to a single digit?

Name: Anonymous 2009-08-13 12:19

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);
  
    //out.print("<br>f=" + f);
    tempDouble=(int)((f)* Math.pow(10,numDigits+1));
    //out.print("<br>tempDouble=" + tempDouble);
    f=(double)tempDouble;
    f=f/10;
    f=Math.round(f);
    //out.print("<br>f=" + f);
    //out.print("<br>" +tempDouble + " " + f/Math.pow(10,numDigits));

    t=Double.toString(f/Math.pow(10,numDigits));
    if (t.substring(t.indexOf('.'),t.length()).length() < numDigits+1)
        t=t+'0';
    //out.print("<br>" + t);
    if (t.compareTo("0.00")==0)
        t="0.0";
    return "GRUNNUR";
}

Fixed.

Name: Anonymous 2009-08-13 12:22

>>5
I lol'd. However, your post is ruining the entire page, and I'm going to make it go away now.

Name: Anonymous 2009-08-13 12:22

>>5
I don't really feel like saging this thread since it's at the top anyway

Name: Anonymous 2009-08-13 12:23

>>1
Rewrite it in Clojure. Then they'll be sorry.

Name: Anonymous 2009-08-13 12:24

>>7 Delicious desert theme...

Name: Anonymous 2009-08-13 12:24

>>8
I'll rewrite your mom in OCaml, and give her a hump

>>5
I can still see you on the front page :(

Name: Anonymous 2009-08-14 10:08

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

Name: Anonymous 2009-08-14 10:21

>>11
If those are the worst things you can find about that code, you shouldn't be programming either.

Name: Anonymous 2009-08-14 10:37

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.

Name: Anonymous 2009-08-14 10:38

Kinda reminds me of the code I write myself. Ah, bliss.

Name: Anonymous 2009-08-14 13:16

    '-._                  ___.....___
        `.__           ,-'        ,-.`-,            HAVE YOU READ
            `''-------'          ( p )  `._       YOUR C++ TODAY ?
                                  `-'      (
                                            \
                                  .         \
                                   \---..,--,
       ................._           --...--,
                         `-.._         _.-'
                              `'-----''

Name: Anonymous 2009-08-14 13:36

>>13

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.


>>12

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.

Name: Anonymous 2009-08-14 13:39

>>15
EXPERT LANGUAGE MISIDENTIFIER

Name: Anonymous 2009-08-14 13:40

>>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: Anonymous 2009-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?

Name: Enterprise Quality !Anus3nMVO2 2009-08-14 13:55

/*** 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;

    // Excellent self-documenting code
    fd_f = fdFloat1 / fdFloat2;

    i_temp = (int)((fd_f)* Math.pow(10,dwDigits+1));

    fd_f = Math.Round((double)(i_temp / 10));

    str_t = Double.toString(fd_f / Math.pow(10,dwDigits));
    if (str_t.substring(str_t.indexOf('.'),str_t.length()).length() < dwDigits+1)
        t=t+'0';


    if (t.compareTo("0.00")==0)
        t="0.0";

    return t;
}


Much better.

Name: Anonymous 2009-08-14 14:25

>>19

>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: Anonymous 2009-08-14 14:32

>>21
By that token, everything fits in that category.

Name: Anonymous 2009-08-14 14:39

I can't even make out what the code does. ;_;

Name: Anonymous 2009-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: Anonymous 2009-08-14 15:18

wats the real wtf XD??

Name: Anonymous 2009-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.

Name: Anonymous 2009-08-14 15:40

>>26
Parappa the Rapper?!

Name: Anonymous 2009-08-14 15:45

>>27
What >>26 meant was actually Alex Papillonmousse.

Name: Anonymous 2009-08-14 17:02

>>28
What >>26 meant was actually Alec Palpitatethemoose

Name: Anonymous 2009-08-14 18:20

>>26
Along those lines, who should I hate more? Alex / Spolsky / Attwood? I'm torn.

Name: Anonymous 2009-08-14 19:13

>>30
Don't have such prejudices. Hate everyone, equally.

Name: Anonymous 2009-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.

Name: Anonymous 2009-08-14 23:02

>>32
I have liked many of Spolsky's articles.

Name: Anonymous 2009-08-14 23:02

>>33
They have pills for that now.

Name: Anonymous 2009-08-14 23:07

>>34
Anyone who promotes DSL is fine in my book. I could do without the narcissism, though.

Name: Anonymous 2009-08-14 23:51

>>35
Care to explain the appeal of DSLs? Frankly I find it extremely cumbersome having to learn a DSL just to do a couple of trivial tasks.

Name: Anonymous 2009-08-14 23:53

>>36
DSL
trivial
Found your problem.

Name: Anonymous 2009-08-15 0:21

your
Found you're problem.

Name: Anonymous 2009-08-15 0:55

>>38
What about I am problem?

Name: Anonymous 2009-08-15 6:12

>>32
That made sense, oddly enough. Thanks for the analysis.

Name: Anonymous 2013-01-19 23:18

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List