• (cs)

    first - 0

  • Mark (unregistered)

    Two possibilities would be (obviously) that either it is causing a cast or - more likely - it was just an indication of plus or minus for the offset that is now removed - in case he needs it again.

  • staying power (unregistered)

    third! And yes, that's what I yell in bed.

  • Procedural (unregistered)

    This is actually an old trick; on some old interpreted languages (think Applesoft Basic) with floating point expression issues (spurious resolution problems that went beyond normal resolution issues), a good way to clear up the problem was to force the variable into some arithmetic expression; a = a+ 0 did the trick.

    Can't imagine that surviving a high-level optimizer nowadays, though.

  • anonymous (unregistered)

    Possibly not a (total, because the result of the min/max is unique) WTF, as -0 < 0 and this could cause non overlapping rectangles appear overlapping using standard checks.

  • OhDear (unregistered)

    I have no idea how many variables I have multiplied by one. x*=1; In various languages it has solved a multitude of hurts.

  • Mii (unregistered)

    reminds me of javascript to string conversion: ""+x :P

  • (cs)

    I always get min and max mixed up - when I want to set a minimum bound of zero for something, I do this:

    foo = Math.Min(foo, 0);

    and wonder why my "minimum bound" doesn't work and it acts like a "maximum bound" instead! :P

  • FunnyChauvinist (unregistered) in reply to staying power
    staying power:
    third! And yes, that's what I yell in bed.
    Despite actually being fifth... the first two must usually be pretty quiet about it.
  • (cs) in reply to staying power
    staying power:
    third! And yes, that's what I yell in bed.
    That's interesting! Your wife have some fun before you get home and you know it?

    I suppose all you do about it is hope you can go home earlier the next day to scream "FRIST!!11!"? Care to give me your home address?

  • Chris (unregistered) in reply to Mii
    Mii:
    reminds me of javascript to string conversion: ""+x :P

    x.toString();

    ;)

  • Jeff (unregistered)

    Looks a lot like there used to be constants in there instead of 0. Perhaps whatever reason they were adding and subtracting constants went away, so a developer swapped the constants out for zeroes.

    The permanent and more-correct fix would be to remove the line altogether, but perhaps the developer thought he'd be going right back in and changing the constants again?

    Is this code any LESS worthless? And yet somehow it seems more appropriate...

    #define X_OFFSET 0
    rect.X1 = min(rect.X1, rect.X1 - X_OFFSET);
    
  • (cs) in reply to Smash King
    Smash King:
    staying power:
    third! And yes, that's what I yell in bed.
    That's interesting! Your wife have some fun before you get home and you know it?

    I suppose all you do about it is hope you can go home earlier the next day to scream "FRIST!!11!"? Care to give me your home address?

    So when you get home, you actually know the number of men your wife has been with previously? How exactly? You count them?

  • javabrain (unregistered) in reply to Chris
    Chris:
    Mii:
    reminds me of javascript to string conversion: ""+x :P

    x.toString();

    ;)

    oh, you mean: (x==null ? "" : x.toString())

    somehow ""+x seems simpler...

  • Kevin (unregistered)

    Probably it's the easiest way to convert to INT!

  • Calm Mint (unregistered) in reply to Jeff
    Jeff:
    Looks a lot like there used to be constants in there instead of 0. Perhaps whatever reason they were adding and subtracting constants went away, so a developer swapped the constants out for zeroes.

    The permanent and more-correct fix would be to remove the line altogether, but perhaps the developer thought he'd be going right back in and changing the constants again?

    Is this code any LESS worthless? And yet somehow it seems more appropriate...

    #define X_OFFSET 0
    rect.X1 = min(rect.X1, rect.X1 - X_OFFSET);
    

    You're halfway there. You've shown the next person that X_OFFSET may occasionally change, and happens to be zero for now.

    To finish your fix, just take that special symbol and add it to the other lines, this kinda ties them together in a group to show that they're all part of the same idea:

     #define X_OFFSET 0
     #this.rect.X1 = Math.Min(this.rect.X1, this.rect.X1 - 0);
     #this.rect.X2 = Math.Max(this.rect.X2, this.rect.X2 + 0);
     #this.rect.Y1 = Math.Min(this.rect.Y1, this.rect.Y1 - 0);
     #this.rect.Y2 = Math.Max(this.rect.Y2, this.rect.Y2 + 0);
    
  • secundum (unregistered) in reply to javabrain
    javabrain:
    Chris:
    Mii:
    reminds me of javascript to string conversion: ""+x :P

    x.toString();

    ;)

    oh, you mean: (x==null ? "" : x.toString())

    somehow ""+x seems simpler...

    Would'nt that return the string "null" when x is null?

  • Zeal_ (unregistered) in reply to Jeff
    Jeff:
    #define X_OFFSET 0
    

    rect.X1 = min(rect.X1, rect.X1 - X_OFFSET);

    Anyone into a contest for saying

    rect.X1 -= X_OFFSET;
    

    in the most rundabout way?

    Bonus points for solutions the compiler can optimize back to

    rect.X1 -= X_OFFSET;
    

    :)

  • (cs) in reply to Chris
    Chris:
    Mii:
    reminds me of javascript to string conversion: ""+x :P

    x.toString();

    ;)

    Not if x is null...

  • (cs) in reply to Jeff
    Jeff:
    The permanent and more-correct fix would be to remove the line altogether
    I beg to differ. The *correct* action, regardless of whatever change you want to make to the code, is to COMMENT the damned thing so that future maintainers will understand why you're doing something so unobvious.
  • SMB (unregistered) in reply to secundum
    secundum:
    javabrain:
    Chris:
    Mii:
    reminds me of javascript to string conversion: ""+x :P

    x.toString();

    ;)

    oh, you mean: (x==null ? "" : x.toString())

    somehow ""+x seems simpler...

    Would'nt that return the string "null" when x is null?
    No, it would ont ;-)

  • Visage (unregistered) in reply to Zeal_

    What if X_OFFSET is negative?

  • Andy (unregistered)

    Perhaps there's a similar block of code immediately above or below this one where the offsets are non-zero and this code was presented in this way to make the similarities more obvious?

  • Scott (unregistered)

    Maybe I'm missing something but to me TRWTF is that a line like:

    this.rect.X1 = Math.Min(this.rect.X1, this.rect.X1 - 0);
    Is basically the same as
    this.rect.X1 = this.rect.X1;
    Which essentially does nothing.
  • (cs) in reply to Scott
    Scott:
    Maybe I'm missing something but to me TRWTF is that a line like:
    this.rect.X1 = Math.Min(this.rect.X1, this.rect.X1 - 0);
    Is basically the same as
    this.rect.X1 = this.rect.X1;
    Which essentially does nothing.

    You're missing something. That's not TRWTF, that's the TOWTF (The Original WTF).

  • FragFrog (unregistered) in reply to ounos
    ounos:
    So when you get home, you actually know the number of men your wife has been with previously? How exactly? You count them?
    Tsk, don't you know that honesty is the basis for any good relationship? Naturally she would tell him!

    All joking aside, for older PHP versions it would yield more accurate results to use $value * 1 then intval($value), for a $value big enough. Commenting something like that would be kind'a trivial tho'

  • Sigh (unregistered) in reply to SMB
    SMB:
    secundum:
    Would'nt that return the string "null" when x is null?
    No, it would ont ;-)
    Time for another le's'son on apo'strophe's. You put them before every "'s" and 'sprinkle them rando'mly wherever el'se you think they might fit. They do'nt actually mean anything, 'so it do'e''s'nt really matter e'xactly where they go.
  • (cs) in reply to Zeal_
    Zeal_:
    Jeff:
    rect.X1 = min(rect.X1, rect.X1 - X_OFFSET);
    
    rect.X1 -= X_OFFSET;
    
    This wouldn't work if X_OFFSET is negative.
  • (cs)

    Well, this looks like C# to me, and that certainly shouldn't have any effect there. At least, it has to be .NET (Math.Min, shudder), so perhaps it is VB version whatever and it has some obscure ... Nah, can't imagine.

    The other thing about this code is the consistent use of "this.". I can't imagine that being necessary, unless this code was automatically translated from some old obscure VB code where the minus and plus zero do have an effect?

    Anyway, whoever wrote that -0 < +0 should have his numeric coprocessor checked or stop working with 1-complement machines.

  • weirded verber (unregistered)
    yes, but sadly, with nothing to say. do you scream "first!" in bed too?

    all the time. Sometimes 0th

  • (cs) in reply to ounos
    ounos:
    Smash King:
    staying power:
    third! And yes, that's what I yell in bed.
    That's interesting! Your wife have some fun before you get home and you know it?

    I suppose all you do about it is hope you can go home earlier the next day to scream "FRIST!!11!"? Care to give me your home address?

    So when you get home, you actually know the number of men your wife has been with previously? How exactly? You count them?

    Of course not. He lives in a small community, so he just assumes 'all of them'.

  • sadwings (unregistered) in reply to javabrain
    javabrain:
    oh, you mean: (x==null ? "" : x.toString())

    somehow ""+x seems simpler...

    I prefer self-explanatory to simpler.

    being clever < being clear

  • Playit Safe (unregistered)

    'T'o 'b'e 's'u'r'e, 'y'o'u 's'h'o'u'l'd 'p'r'o'b'a'b'l'y 'p'u't 'a'n 'a'p'o's't'r'o'p'h'e 'b'e'f'o'r'e 'e'v'e'r'y 'l'e't't'e'r. 'T'h'a't 'w'a'y 'y'o'u''r'e 'b'o'u'n'd 't'o 'b'e 'r'i'g'h't 's'o'm'e 'o'f 't'h'e 't'i'm'e!

  • weirded verber (unregistered) in reply to halcyon1234
    halcyon1234:
    ounos:
    Smash King:
    staying power:
    third! And yes, that's what I yell in bed.
    That's interesting! Your wife have some fun before you get home and you know it?

    I suppose all you do about it is hope you can go home earlier the next day to scream "FRIST!!11!"? Care to give me your home address?

    So when you get home, you actually know the number of men your wife has been with previously? How exactly? You count them?

    if they're all hiding in the cupboard, then just count the cars on the driveway

    Of course not. He lives in a small community, so he just assumes 'all of them'.

  • Playit Safe (unregistered)

    (Ten bucks to the first Windows user who can figure out how I did that without compiling code. And no, it wasn't click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste...)

  • (cs) in reply to OhDear
    OhDear:
    I have no idea how many variables I have multiplied by one. x*=1; In various languages it has solved a multitude of hurts.

    Casting by accident solves the hurt, but it also leaves a silly looking scar.

  • Mike (unregistered)
    Scott:
    Maybe I'm missing something but to me TRWTF is that a line like: this.rect.X1 = Math.Min(this.rect.X1, this.rect.X1 - 0);
    Is basically the same as
      this.rect.X1 = this.rect.X1;
    
    Which essentially does nothing.
    

    It 'appears' to do nothing. however, we don't see the code for the property setter. Maybe the setter does more than just set a field value. Maybe it has other side effects.

    The WTF is that the property setter has (presumably) undocumented side effects that confuse the API consumers.

  • Old Coder (unregistered) in reply to SlyEcho
    SlyEcho:
    Zeal_:
    Jeff:
    rect.X1 = min(rect.X1, rect.X1 - X_OFFSET);
    
    rect.X1 -= X_OFFSET;
    
    This wouldn't work if X_OFFSET is negative.
    In that case, what you need is: rect.X1 = min(rect.X1, rect.X1 - abs(X_OFFSET));
  • infamous_blah (unregistered) in reply to sadwings
    sadwings:
    javabrain:
    oh, you mean: (x==null ? "" : x.toString())

    somehow ""+x seems simpler...

    I prefer self-explanatory to simpler.

    being clever < being clear

    String(x) has the exact same behavior as ""+x but with better readability.

  • return of the spelling nazi (unregistered) in reply to Playit Safe
    Playit Safe:
    (Ten bucks to the first Windows user who can figure out how I did that without compiling code. And no, it wasn't click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste...)

    In Python: print "".join([i + "'" for i in string])

    I was trying for a one-liner, maybe there's a better one, though.

    No compilation needed. But maybe you did some fancy shell scripting or use an advanced text editor?

  • return of the spelling nazi (unregistered) in reply to return of the spelling nazi

    Oops, you said Windows, so it's probably a cmd.exe or notepad trick. I don't know. Can I have ten dollars just for being me?

  • JoJo (unregistered) in reply to ounos
    ounos:
    Smash King:
    staying power:
    third! And yes, that's what I yell in bed.
    That's interesting! Your wife have some fun before you get home and you know it?

    I suppose all you do about it is hope you can go home earlier the next day to scream "FRIST!!11!"? Care to give me your home address?

    So when you get home, you actually know the number of men your wife has been with previously? How exactly? You count them?

    I didn't see him mention anything about men - you're making assumptions there!

  • (cs) in reply to return of the spelling nazi
    return of the spelling nazi:
    Playit Safe:
    (Ten bucks to the first Windows user who can figure out how I did that without compiling code. And no, it wasn't click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste...)

    In Python: print "".join([i + "'" for i in string])

    I was trying for a one-liner, maybe there's a better one, though.

    No compilation needed. But maybe you did some fancy shell scripting or use an advanced text editor?

    I was going to guess by typing it, since it wouldn't take long (though I'm not a Windows user so I guess I'm not eligible for the ten bucks anyway.) I am still trying to figure out why anyone would do it by clicking and pasting.

  • Mark V Shaney (unregistered)

    I wanted to write that the code probably evolved from another code dealing with some border around the rect, but such code would have been developed:

    a) with negative borders in mind b) by someone that never heard of abs()

    So, I guess it is a wtf evolved from a previous wtf...

  • Typing (unregistered) in reply to Playit Safe

    For such a short message, where it is unlikely that the need should ever arise again, I would suggest: bruteforce typing.

  • Playit Safe (unregistered) in reply to return of the spelling nazi
    return of the spelling nazi:
    Oops, you said Windows, so it's probably a cmd.exe or notepad trick. I don't know. Can I have ten dollars just for being me?
    I'm running on a virtual machine, so here's your virtual ten bucks. (And, no, I didn't say I'm using Windows.)
  • Playit Safe (unregistered) in reply to Typing
    Typing:
    For such a short message, where it is unlikely that the need should ever arise again, I would suggest: bruteforce typing.
    'A'a'h 'y'e's, 'b'r'u't'e 'f'o'r'c'e 't'y'p'i'n'g. 'A'n 'e'l'e'g'a'n't 's'o'l'u't'i'o'n 'f'o'r 't'h'o's'e 'o'n'e-'o'f'f 'r'e'q'u'e's't's 't'h'a't 'w'i'l'l 'n'e'v'e'r 'e'v'e'r 'c'o'm'e 'u'p 'a'g'a'i'n.
  • JoJo (unregistered) in reply to Playit Safe
    Playit Safe:
    (Ten bucks to the first Windows user who can figure out how I did that without compiling code. And no, it wasn't click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste...)

    use Word. Type in the original line and use Find and Replace, more options, Special and replace 'any letter' (^$) with Find What Text (^&) and ' i.e. ^&'

    replaces every letter with the same text + '

  • JoJo (unregistered) in reply to JoJo
    JoJo:
    Playit Safe:
    (Ten bucks to the first Windows user who can figure out how I did that without compiling code. And no, it wasn't click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste, click, paste...)

    use Word. Type in the original line and use Find and Replace, more options, Special and replace 'any letter' (^$) with Find What Text (^&) and ' i.e. ^&'

    replaces every letter with the same text + '

    oops! apostrophe should be before the ^& to match your example...

  • Anonymous (unregistered)

    This is one of the stupidest WTF posts ever. There have already been several reasonable explanations for why it could be done. Forgetting to leave a comment explaining something that may not even be worthy of a comment is hardly a WTF.

Leave a comment on “Math.Min(x, x - 0) = ?”

Log In or post as a guest

Replying to comment #:

« Return to Article