• Dave (unregistered)

    "Nic" + "e."

  • BLs (unregistered)

    Ok, the first theory is right out... 40+40+10-1 would have been much shorter. It's gotta be just a purely evil developer.

  • Kura (unregistered)

    From looking at it I'd figure it's 61ZYX...CBA3

    (Trying to type this out, I realised I do not know the alphabet backwards...)

    I'd love to know what this was actually used/meant for though.

  • grg (unregistered)

    maybe the idea was to overflow the expression evaluator stack and overwrite some other variable or the return address?

    I can think of several older compilers and interpreters that could be crashed in just this way.

  • (cs)

    WTF? Those brackets really aren't necessary

  • (cs)

    My method of measuring code quality is to ask myself if I would rather have herpes or maintain the code in question. In this case I would choose death by herpes.

  • Pink Duck (unregistered)

    My congratulations for the exquisitely named variable too :)

  • ac (unregistered)

    It might have been generated by the expansion of some plausible-looking set of macros. Why anyone would then decide to stick the preprocessed output into the code is another question, but people do do such things.

  • Dan (unregistered)

    LISP would have been better suited to this problem. change patno -= ((((((((((((((((40+1)+1)+1)+1)+1)+1)+1)+1)+1)+1)+10)+1)+('Z'-'A'))+1)+1)+1);

    to

    (+(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+ 40 1)1)1)1)1)1)1)1)1)1)1)10)1)(- Z A))1)1)1)

    now it's readable, and there's one more pair of ()!

  • (cs)

    So I guess the WTF is that Kirk's company holds a Worst Line Competition. Look -- if you have a competition, someone is going to try to win.

  • Any Mouse (unregistered)

    Possible explanations:

    1. We've all seen code that doesn't make sense when you look at the finished product. But no one would ever just sit down and write it that way. These things EVOLVE over time! It was previously just

      patno -= (((((((((((((((40+1)+1)+1)+1)+1)+1)+1)+1)+1)+1)+10)+1)+('Z'-'A'))+1)+1);

    but the last programmer was told to add one to the existing algorithm. And so on.

    1. He was testing the optimizing compiler.

    2. This is actually documentation. If you just code "patno -= 89" the next guy is going to wonder "Why 89? Where'd that come from?"

    3. Computer Science teacher gave an F to anyone who didn't explicitly declare the order of evaluation.

  • (cs) in reply to akatherder
    akatherder:
    My method of measuring code quality is to ask myself if I would rather have herpes or maintain the code in question. In this case I would choose death by herpes.

    I dunno. I watched some TV programme about a woman who died of Herpes Simplex 1 which is typically thought to be more annoying than anything else. The virus took over and shut down her liver, and it was quite a scary way to die.

    You can just do the math in your head* and then refactor the line.

    *What, you couldn't do that in your head?

  • FDF (unregistered)

    Looks like this was written by somebody who missed calculus at school or was a bit too lazy. Instead of adding ones and tens and (z-a)s himself to the number that wasn't big enough, he just let the computer do it again and again.

  • Alex (unregistered)

    Anyone else reckon it's output from the C preprocessor copy-pasted to production code?

  • Moitah (unregistered)

    i'd say the guy wanted to keep a trace of each time he had to increase the reducing value.

  • (cs) in reply to Kefer
    Kefer:
    WTF? Those brackets really aren't necessary

    If the brackets were the only thing there that you found weren't necessary, I'm glad you don't work with me.

  • (cs) in reply to Alex
    Alex:
    Anyone else reckon it's output from the C preprocessor copy-pasted to production code?
    "reckon"?
  • (cs)

    This code was written by the BDFH (Bastard Developer From Hell). And then he copyrighted it. Now, everybody has to pay if he wants to use his code.

    That's the real WTF.

  • (cs) in reply to Kefer
    Kefer:
    WTF? Those brackets really aren't necessary

    ORLY.

  • Rather Knaught (unregistered)

    It makes me SICK the way our society just automatically turns to addition first as if that was the answer to every problem. Even assuming you are restricted to ones and zeros, you can still do it more efficiently with subtraction:

    patno -= (((((((((((((((((100-1)-1)-1)-1)-1)-1)-1)-1)-1)-1)-1);

    Kids these days! Grumble!

  • Mike (unregistered)

    I can't quite believe this is pasted from preprocessor output. Even in macro language, I still can't imagine a situation that would call for all those + signs and brackets. If it was previously done with macros, it would still have looked horrible. Possibly even more horrible than this one, as it would have wrapped onto more lines...

  • (cs) in reply to snoofle
    snoofle:
    Alex:
    Anyone else reckon it's output from the C preprocessor copy-pasted to production code?
    "reckon"?
    reckon.
  • Matt (unregistered) in reply to snoofle

    What if the alphabet changes because some government decided to add new letters between A and Z ?

    This code is future-proof.

    CAPTCHA = eros

  • adiener (unregistered) in reply to Dan
    Dan:
    (+(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+ 40 1)1)1)1)1)1)1)1)1)1)1)10)1)(- Z A))1)1)1)

    now it's readable, and there's one more pair of ()!

    Unless I'm missing something, there only appears to be another pair of parentheses because you added an extra +1.

  • Franz-Leo Chomse (unregistered)

    I have written some of those myself.

    I bet each number is the width of a column in a columnar ascii report and the variable is the left margin of a subreport.

    Regards from Germany

    Franz-Leo

  • Theodore (unregistered)

    I saw once code from other party:

    x += 1+1+1+1+1+1+1+1+1+1; y += 1+1+1+1+1+1+1+1+1+1+1+1; v = 1 + 1 + 1 + 1 + 1 + 1+1+1+1+1+1+1+1+1+1;

    From what I know, their customer used an automatic test, checking that there are no "magic numbers" except from -1 to 5. So, they wrote a preprocessor...

    Also, note different spacing in 1 + 1 + 1 + 1 + 1? Seems to be enum of another type!

  • (cs) in reply to Moitah
    Moitah:
    i'd say the guy wanted to keep a trace of each time he had to increase the reducing value.

    Exactly! Who needs CVS?

    Anyway, there's nothing wrong with writing out what should be a constant in an expression to make it's semantics clear. When I want to specify 5 minutes in ms, I do this:

    final long ms = 5 * 60 * 1000;

    not this:

    final long ms = 300000;

    So from reading the expression, it's pretty obvious what the semantics of that decrement are.

  • Matt R (unregistered) in reply to Markp
    Markp:
    Moitah:
    i'd say the guy wanted to keep a trace of each time he had to increase the reducing value.

    Exactly! Who needs CVS?

    Anyway, there's nothing wrong with writing out what should be a constant in an expression to make it's semantics clear. When I want to specify 5 minutes in ms, I do this:

    final long ms = 5 * 60 * 1000;

    not this:

    final long ms = 300000;

    So from reading the expression, it's pretty obvious what the semantics of that decrement are.

    Or gasp you could use a comment! Then you can remove the assumption that the moron who will be reading/maintaining your code will see the "obvious".

    final long ms = 300000; /* 5 minutes worth of milliseconds */

  • (cs) in reply to Matt
    Matt:
    What if the alphabet changes because some government decided to add new letters between A and Z ?

    This code is future-proof.

    Unless of course the government then decided that Z looks much nicer when you put it after H. What this really needs is something to confirm the order of the alphabet, like a monster sized recursive 'if' block (if such a thing exists... and I can't think why it shouldn't).

  • Ric (unregistered) in reply to Any Mouse
    Any Mouse:
    Possible explanations:
    1. We've all seen code that doesn't make sense when you look at the finished product. But no one would ever just sit down and write it that way. These things EVOLVE over time! It was previously just

      patno -= (((((((((((((((40+1)+1)+1)+1)+1)+1)+1)+1)+1)+1)+10)+1)+('Z'-'A'))+1)+1);

    but the last programmer was told to add one to the existing algorithm. And so on.

    1. He was testing the optimizing compiler.

    2. This is actually documentation. If you just code "patno -= 89" the next guy is going to wonder "Why 89? Where'd that come from?"

    3. Computer Science teacher gave an F to anyone who didn't explicitly declare the order of evaluation.

    A similar thing exists in the world of publications: In the first edition, they put all the numbers 2 4 6 8 10 9 7 5 3 1 onto the inner cover of the book, and remove a number each edition. The dev's probably trying to allow for that.

  • (cs) in reply to akatherder
    akatherder:
    My method of measuring code quality is to ask myself if I would rather have herpes or maintain the code in question. In this case I would choose death by herpes.
    That's the start of a good idea. It should be expanded, so that you can rate code by giving it a disease-I'd-rather-have equivalent:
    • common cold
    • dysentery
    • strep throat
    • pneumonia
    • herpes
    • syphilis
    • malaria
    • dengue fever
    • AIDS
    • small pox
    • ebola
  • Gio (unregistered) in reply to Matt R

    also, you can use a more descriptive name than "ms".

    "5 * 60 * 1000" doesn't tell me that you are using milliseconds, it just tells me how you arrived at 300000.

    final long TIME_IN_MILLISECONDS = 300000;

    However, tells me everything I need to know.

  • wm.annis (unregistered) in reply to Dan
    Dan:
    LISP would have been better suited to this problem. change patno -= ((((((((((((((((40+1)+1)+1)+1)+1)+1)+1)+1)+1)+1)+10)+1)+('Z'-'A'))+1)+1)+1);

    to

    (+(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+ 40 1)1)1)1)1)1)1)1)1)1)1)10)1)(- Z A))1)1)1)

    Honestly.

    (1+ (1+ (1+ (+
                 (1+ (1+ 
                      (+
                       (1+ 
                        (1+ 
                         (1+ 
                          (1+ 
                           (1+
                            (1+ 
                             (1+ 
                              (1+ 
                               (+ 40 1))))))))))))
                 10
                 (apply #'- (mapcar #'char-int (list #\Z #\A)))))))
    
  • Dave (unregistered) in reply to Any Mouse
    Any Mouse:
    Possible explanations: If you just code "patno -= 89" the next guy is going to wonder "Why 89? Where'd that come from?"

    Right! That's why you don't use magic numbers:

    Define the constant PTANO_SUBTRACTION_FACTOR_1 and set it to octal 61. Then define the constant PATON_SUBTRACTION_FACTOR_2 and set it to hexadecimal 27. Make sure to make these global constants.

    Then in your code, you just have to do

    patno -= (PTANO_SUBTRACTION_FACTOR_1 + PATON_SUBTRACTION_FACTOR_2 + 1)\

    Much clearer and more maintainable.

  • APH (unregistered) in reply to Gio
    Gio:
    also, you can use a more descriptive name than "ms".

    "5 * 60 * 1000" doesn't tell me that you are using milliseconds, it just tells me how you arrived at 300000.

    final long TIME_IN_MILLISECONDS = 300000;

    However, tells me everything I need to know.

    Actually, I would combine all these suggestions:

    final long TIME_IN_MILLISECONDS = 5 * 60 * 1000; // 5 minutes in milliseconds

    I know myself, and I would definitely omit or add an extra zero.

  • (cs) in reply to Kefer
    Kefer:
    WTF? Those brackets really aren't necessary
    Which ones?
  • Alph (unregistered) in reply to Claxon
    Claxon:
    Unless of course the government then decided that Z looks much nicer when you put it after H. What this really needs is something to confirm the order of the alphabet, like a monster sized recursive 'if' block (if such a thing exists... and I can't think why it shouldn't).

    This already happened -- in the Greek alphabet, Z comes right before H. ("zeta" and "eta"). The Romans didn't use Z, so when they took the alphabet they replaced it with G. ("But wait", you say, "doesn't Greek have their own G ("gamma") right at the beginning?" To which I say, "Shut up unless you want me to write a 10 page essay on the history of the alphabet.") Later on, the Romans decided they wanted Z after all, so they just stuck it on at the end.

    I think the Queen (I guess; it's her English, isn't it?) should tell us all to add Þ back to our alphabet, probably at the end, in which case you will not be laughing when all this programmer has to do is change "z - a" to "Þ - a".

    ("Þis programmer", I mean. And "I Þink Þe Queen", too, I guess.)

  • (cs) in reply to Matt R
    Matt R:
    Or *gasp* you could use a comment! Then you can remove the assumption that the moron who will be reading/maintaining your code will see the "obvious".

    final long ms = 300000; /* 5 minutes worth of milliseconds */

    OR, you could do it something like this (as I've witnessed myself)

    final long ms = 5 * 60 * 1000; /* 5 minutes worth of milliseconds */

    which of course eventually got changed to

    final long ms = 2 * 60 * 1000; /* 5 minutes worth of milliseconds */

    as five minutes was too long a time for the purpose...

  • (cs) in reply to APH
    APH:
    Gio:
    also, you can use a more descriptive name than "ms".

    "5 * 60 * 1000" doesn't tell me that you are using milliseconds, it just tells me how you arrived at 300000.

    final long TIME_IN_MILLISECONDS = 300000;

    However, tells me everything I need to know.

    Actually, I would combine all these suggestions:

    final long TIME_IN_MILLISECONDS = 5 * 60 * 1000; // 5 minutes in milliseconds

    I know myself, and I would definitely omit or add an extra zero.

    I agree, plus it'll be much easier to change later if you decide it should be 6 minutes.

  • (cs) in reply to Benanov
    Benanov:
    akatherder:
    My method of measuring code quality is to ask myself if I would rather have herpes or maintain the code in question. In this case I would choose death by herpes.

    I dunno. I watched some TV programme about a woman who died of Herpes Simplex 1 which is typically thought to be more annoying than anything else. The virus took over and shut down her liver, and it was quite a scary way to die.

    You can just do the math in your head* and then refactor the line.

    *What, you couldn't do that in your head?

    What, there's math involved in this prize specimen?

    I side with the Lisp guys. There is absolutely nothing wrong with the idea behind this code at all. The only two WTFs I see are the fact that it's not idempotent (for shame!) and that silly little semicolon at the end.

  • Mark (unregistered) in reply to akatherder

    You might choose death by herpes; but do a google search for "tree man" for a look at what life with herpes looks like.

  • jk (unregistered) in reply to Alph
    Alph:
    This already happened -- in the Greek alphabet, Z comes right before H. ("zeta" and "eta"). The Romans didn't use Z, so when they took the alphabet they replaced it with G. ("But wait", you say, "doesn't Greek have their own G ("gamma") right at the beginning?" To which I say, "Shut up unless you want me to write a 10 page essay on the history of the alphabet.") Later on, the Romans decided they wanted Z after all, so they just stuck it on at the end.

    I think the Queen (I guess; it's her English, isn't it?) should tell us all to add Þ back to our alphabet, probably at the end, in which case you will not be laughing when all this programmer has to do is change "z - a" to "Þ - a".

    ("Þis programmer", I mean. And "I Þink Þe Queen", too, I guess.)

    greetings from Iceland, where the thorn has been in use for a thousand years.

    and wasn't it the ancient Irish who decided the alphabet should be in alphabetical order?

  • (cs) in reply to roe
    roe:
    Matt R:
    Or *gasp* you could use a comment! Then you can remove the assumption that the moron who will be reading/maintaining your code will see the "obvious".

    final long ms = 300000; /* 5 minutes worth of milliseconds */

    OR, you could do it something like this (as I've witnessed myself)

    final long ms = 5 * 60 * 1000; /* 5 minutes worth of milliseconds */

    which of course eventually got changed to

    final long ms = 2 * 60 * 1000; /* 5 minutes worth of milliseconds */

    as five minutes was too long a time for the purpose...

    I actually do this all the time. Well, I don't put in the stupid comments, but I frequently write stuff like:

    private static final long MARKET_CLOSE_IN_MILLISECONDS = 16 * 60 * 60 * 1000;

    I guess it's a combination of me not wanting to do all that hard math myself and the (small) benefit of documenting exactly what the number is and why it has the value that it does. shrug

  • (cs) in reply to APH
    APH:
    Actually, I would combine all these suggestions:

    final long TIME_IN_MILLISECONDS = 5 * 60 * 1000; // 5 minutes in milliseconds

    I know myself, and I would definitely omit or add an extra zero.

    Or you could go further

    final long TIME_IN_MILLISECONDS = 5 * SECONDS_IN_MINUTE * MILLISECONDS_IN_SECOND;

    You never know when someone will redefine the minute or millisecond.

  • (cs) in reply to Mark
    Mark:
    You might choose death by herpes; but do a google search for "tree man" for a look at what life with herpes looks like.
    What that guy has is not herpes, it's a strain of human papilloma virus, which normally causes warts, interacting catastrophically with a gene defect.
  • (cs)

    The true WTF : patno is not reduced by 89 but by 150. Comments are wrong.

  • Charles (unregistered)

    Maybe the author was trying to win the competition.

  • Disgruntled DBA (unregistered)

    But how would I use that to increment by 11?

    http://thedailywtf.com/Articles/If__0x2b__0x2b__Increments__0x2e__0x2e__0x2e_.aspx

  • LucianoMollea (unregistered)

    Found worse: a javascript function to validate dates that was a series of nested ifs. 23 nesting. Evidently the writer did not like the "else if" construct.

    And, oh, it was at least nicely formatted such as (syntax here may not be correct ;)

    if(...) { } else { if (...) { } else { { if(...) { } else { if(...) { } else { // logical seriesc of checks ends here if(...) { } else { // and so on }

    // and at the end... the closing paretheses } } } } } }

  • Kuli (unregistered) in reply to BLs
    BLs:
    Ok, the first theory is right out... 40+40+10-1 would have been much shorter. It's gotta be just a purely evil developer.

    Or he should have written (44>>1)+1.

    Captcha: damnum! How appropriate!

Leave a comment on “A Dubious Honor”

Log In or post as a guest

Replying to comment #:

« Return to Article