• Dr. Atkins (unregistered) in reply to Playit Safe

    I'd do a find/Replace with a regex such as s/./$&'/g (in perl) or Find: . Replace: \0' in Visual Studio.

  • infamous_blah (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...)
    I wouldn't consider myself a Windows user, but they do have python and other scripting languages. Pardon my bash single-quote escaping:

    $ python -c 'orig = "To be sure, you should probably put an apostrophe before every letter. That way you'''re bound to be right some of the time!";print "".join([ "'''" + x if ord(x) in range(65,90) or ord(x) in range(97,122) else x for x in orig ])' '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!

  • Playit Safe (unregistered)

    Nice tries. I gotta go now. If anyone cares, it was:

    sed "s/([a-zA-Z])/'\1/g"

  • (cs)

    In addition to type casts, null conversions and the remnants of some offset strategy, there are a couple of other uses for such logic:

    1. To break an assignment check.
    2. Perhaps the Math.Min function has been overridden with another function definition.
    3. The slow down a loop intentionally. (Not a good way)

    But I would vote for null handling. I can't tell how many times I have added 0 or "" to a database field value to scrub off the nullness.

  • HIC Russell (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...)
    sed
  • (cs) in reply to Playit Safe

    Well, it was interesting seeing all the possible solutions, but I'm still intrigued as to why anyone would click and paste to do it, when typing would be much faster. Did you forget to mention an additional assumption, such as, 'I have no keyboard' or, 'My current keyboard layout does not have the apostrophe in a convenient location'?

  • JoJo (unregistered) in reply to Playit Safe
    Playit Safe:
    Nice tries. I gotta go now. If anyone cares, it was:

    sed "s/([a-zA-Z])/'\1/g"

    \

    So, it was actually quicker using Word on a Windows machine ;-)

  • (cs) in reply to Playit Safe
    Playit Safe:
    '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!
    Thats just ridiculous. Never ever ever use an apostrophe and you will be right a much greater percentage of the time than if you put one before every letter.

    (For the humor-impaired: I know I left a necessary apostrophe out of that first sentence. Lighten up a bit, okay?)

  • JoJo (unregistered) in reply to RogerC
    RogerC:
    Playit Safe:
    '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!
    Thats just ridiculous. Never ever ever use an apostrophe and you will be right a much greater percentage of the time than if you put one before every letter.

    (For the humor-impaired: I know I left a necessary apostrophe out of that first sentence. Lighten up a bit, okay?)

    And it's also incorrect as putting an apostrophe before every letter doesn't solve all cases as Socrates' cat will tell you ;-)

  • Frank (unregistered) in reply to Playit Safe

    Apostrophe's are often a warning to the reader that an 's' is a about to appear.

  • Nick (unregistered)

    I've actually done this for a reason (ofc, I commented the code, unlike the above). In ColdFusion, a dynamically-typed language, I was having trouble with using some variables containing numbers in both an integer & string context (data was string coming out of the db and in the display, but needed to be an integer for an interim calculation). Using variable + 0 cast it into an integer when I needed it to be.

  • (cs)

    This reminds me of Commodore V2 BASIC. For some reason, it computed "." quicker than "0", so you had a lot of "A=." going on.

    If you think some of the DailyWTF code is obfuscated, try 5 KB VIC programs that looked like this:

    10 ?"*** MY AWESOME PROGRAM ***":DIMAB$(20):A=.:B=1:C=10:FORL=1TO20:READAB$(L):NEXT
    

    Up to 88 characters per BASIC line, no spaces required, and there were "tokenized" versions of almost every command (besides "?" for print, you could use <first letter><shift-second letter> for other commands).

  • Dennis (unregistered) in reply to Frank

    Apostrophe's are often a warning to the reader that an 'butt' is a about to appear. Clbuttic!

  • Dennis (unregistered) in reply to operagost
    operagost:
    This reminds me of Commodore V2 BASIC.

    Now that's the real WTF!

  • yah (unregistered) in reply to Frank
    Frank:
    Apo'strophe's are often a warning to the reader that an ''s' i's a about to appear.

    FTFY

  • (cs) in reply to GooberMcNutly
    1. As said before, this looks very much like C#, and it doesn't break an assignment check. Heck, even if it could do that, what check is this supposed to break? x = x?

    2. Overriding Math.Min is a WTF in itself.

    3. Slow down a loop? Are you kidding? The + 0 or - 0 is going to be discarded by the optimizer and the call to Math.Min will take the better part of a microsecond. Four of those to slow down a loop? Depending on CPU speed?

    Null handling either, since the only null objects are this or this.rect. If either is null, an exception will be thrown. I know people add 0 or "" in databases or awk or whatever, but this just isn't the case here.

  • The Coffey Maker (unregistered)

    My dick itches.

  • iToad (unregistered) 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.

    It does nothing only for sufficiently small values of zero.

  • Ken (unregistered)

    Don't laugh. I've had all sorts of nonsense like this work, and in fact help. Superstitious/shotgun debugging helps sometimes...

    Example from my code yesterday (in windows driver source):

    KdPrint(("argm->p[3]: %I64x\n", argm->p[3])); ULONGLONG returnval = (argm->p[3] >> 5) & 0xFFFFFLL;

    The above code results in errors from MSVS: 1>c:\WINDDK\3790.1830\src\test.c(54) : error C2143: syntax error : missing ';' before 'ULONGLONG' 1>c:\WINDDK\3790.1830\src\test.c(58) : error C2065: 'returnval' : undeclared identifier

    i.e. there is a missing semicolon before ULONGLONG, which obviously means at the end of the KdPrint line.

    REMOVING the semicolon at the end of the KdPrint line results in it compiling properly: KdPrint(("argm->p[3]: %I64x\n", argm->p[3])) ULONGLONG returnval = (argm->p[3] >> 5) & 0xFFFFFLL;

    If I swap the lines, it compiles WITH the semicolon. Note that the double parentheses on KdPrint are required as stated by msdn - either their compiler sucks at dealing with preprocessor macros or whoever wrote the macro in the first place was smoking something. In either case, if VS complains about a "missing" semicolon after a line containing a macro, and it's not missing, try removing it.

  • Worf (unregistered) in reply to Playit Safe
    Playit Safe:
    Nice tries. I gotta go now. If anyone cares, it was:

    sed "s/([a-zA-Z])/'\1/g"

    Since when did Windows come with sed? (Remember, the poster said "Windows" in his original challenge!)

  • Worf (unregistered) in reply to Playit Safe
    Playit Safe:
    Nice tries. I gotta go now. If anyone cares, it was:

    sed "s/([a-zA-Z])/'\1/g"

    Since when did Windows come with sed? (Remember, the poster said "Windows" in his original challenge!)

  • RiF (unregistered) in reply to Worf
    Worf:
    Playit Safe:
    Nice tries. I gotta go now. If anyone cares, it was:

    sed "s/([a-zA-Z])/'\1/g"

    Since when did Windows come with sed? (Remember, the poster said "Windows" in his original challenge!)

    Read it again (and note the username):

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

    Reading is fundamental.

  • Really Great Cod3r (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);
    

    I am a senior software desiger at a MAJOR corporation, and I require ALL my employees to code this way. It makes it easy to set up an offset later if we need to. The zeros are placeholders for the offset that will someday go there.

    Besides, it took mathematicians thousands of years to invent the number zero, which exists for precisely this function: to serve as a placeholder.

    TRWTF is that eveyone doesn't do this!

  • Tgr (unregistered)

    Must have been written on a hyperreal architecture. The programmer is trying to clear out infinitesimal quantities.

  • Eevee (unregistered) in reply to JoJo
    JoJo:
    And it's also incorrect as putting an apostrophe _before_ every letter doesn't solve all cases as Socrates' cat will tell you ;-)
    That should be "Socrates's". Only plurals ending in an 's' get a bare apostrophe at the end.
  • Russ (unregistered) in reply to dpm

    I hate people who comment out code. Its called source control, just delete it.

  • Duke of New York (unregistered)

    This is not a true WTF unless the program stopped working when Robert removed the code.

  • bucket (unregistered) in reply to Playit Safe
    Playit Safe:
    '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!

    However if you dont use them at all, youre percentage of times being right is higher than you use the for every letter.

  • Abby Normal (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?

    Their bedroom was developed with Microsoft(TM) Front Page(TM) an uses the obligatory Extra-Marital Hit-It Counter (TM) which reads: "You're wife's vagina has been visited by X - 0 partners."

  • (cs) in reply to RogerC
    RogerC:
    Playit Safe:
    '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!
    Thats just ridiculous. Never ever ever use an apostrophe and you will be right a much greater percentage of the time than if you put one before every letter.
    You left a necessary apostrophe out of that first sentence.
  • (cs) 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...)
    I'm not a Windows user, but I imagine pressing the apostrophe key before typing each letter in your message would do the trick.
  • MM (unregistered) in reply to Old Coder
    Old Coder:
    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));
    No. That would wipe out the negative. If it were negative, it would presumably be because it's supposed to be negative. That's where the min function would have been needed in the first place - where the offset is a variable that might sometimes be positive and sometimes be negative but is supposed to be subtracted only when it's positive. (When it's negative, the value of rect.X1 should be left alone.)
    rect.X1 = min(rect.X1, rect.X1 - X_OFFSET);
    is equivalent to
    if (X_OFFSET > 0)
       rect.X1 -= X_OFFSET;
  • Harrow (unregistered) in reply to The Coffey Maker
    The Coffey Maker:
    My dick itches.
    That's because you've been icking ditches.
  • Jonas (unregistered) in reply to Playit Safe

    Don't forget to put a few after letters too! That way you won't get caught on things like "Jonas'" and other such constructs.

  • Tyrathect (unregistered) in reply to Zeal_

    #define OFFSET_TO_REMOVE 5

    #define OFFSET_FUNC(x) (85 + x3 - xx*4)

    #define REMOVE_OFFSET(x,y) x-=y

    ...

    REMOVE_OFFSET(rect.X1, OFFSET_TO_REMOVE)

  • Tom JP (unregistered) in reply to return of the spelling nazi
    return of the spelling nazi:
    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?

    Here's the better one:

    print "'".join(string)
    
  • SeaDrive (unregistered) in reply to anonymous

    I worked on a Data General minicomputer on which integer subtraction of equals returned a negative zero. If testing for zero, it was best to take absolute value of the result. Adding zero would probably also work.

  • Zapakh (unregistered) in reply to Worf
    Worf:
    Playit Safe:
    Nice tries. I gotta go now. If anyone cares, it was:

    sed "s/([a-zA-Z])/'\1/g"

    Since when did Windows come with sed? (Remember, the poster said "Windows" in his original challenge!)

    Though I had the same question, I have two possible responses:

    1. The poster required respondents to be Windows users, but did not claim to be a Windows user.

    2. http://gnuwin32.sourceforge.net/packages/sed.htm

  • noname (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...)

    You typed an apostrophe between each letter?

  • g0ats3 (unregistered)

    i have to poo

  • (cs) in reply to Sigh
    Sigh:
    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.
    Doesn't matter? I think you'll find it matters quite a lot when one goes before "OR%201=1;%20DROP%20TABLE;--"!
  • Guest Dev (unregistered) in reply to Playit Safe

    My.Reply = Math.Min('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! + '0); My.Reply = Math.Min('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! + 1'); My.Reply = Math.Max('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! + '0); My.Reply = Math.Max('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! - '0);

  • Kalinka (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...)

    home, apostrophe, cursor right, apostrophe, cursor right, cursor right, apostrophe, cursor right, apostrophe, cursor right, cursor right, apostrophe, cursor right, apostrophe, cursor right, apostrophe, cursor right, apostrophe, cursor right, cursor right, cursor right, apostrophe, cursor right, apostrophe, cursor right, apostrophe, cursor right, cursor right...

    Reminds me Tetris walkthrough

  • noname (unregistered) in reply to Eevee
    Eevee:
    JoJo:
    And it's also incorrect as putting an apostrophe _before_ every letter doesn't solve all cases as Socrates' cat will tell you ;-)
    That should be "Socrates's". Only plurals ending in an 's' get a bare apostrophe at the end.

    Well, it's alway's nice to warn reader's about an upcoming 's. They can be 'scary 'sometime's.

  • (cs) in reply to Eevee
    Eevee:
    JoJo:
    And it's also incorrect as putting an apostrophe _before_ every letter doesn't solve all cases as Socrates' cat will tell you ;-)
    That should be "Socrates's". Only plurals ending in an 's' get a bare apostrophe at the end.
    Actually, it's "Schrödinger's cat".

    No, wait... that cat died. Or did it? Oh well, nevermind.

  • (cs) in reply to Really Great Cod3r
    Really Great Cod3r:
    ...the number zero...exists for precisely this function: to serve as a placeholder.

    TRWTF is that eveyone doesn't do this!

    Don't you mean "eve0yone"?
  • The Fake WTF (unregistered) in reply to Playit Safe
    Playit Safe:
    '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!

    That would have been so much more ironic if you had used "you are" instead of the contraction....

  • (cs) in reply to MM
    MM:
    Old Coder:
    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));
    No. That would wipe out the negative. If it were negative, it would presumably be because it's supposed to be negative. That's where the min function would have been needed in the first place - where the offset is a variable that might sometimes be positive and sometimes be negative but is supposed to be subtracted only when it's positive. (When it's negative, the value of rect.X1 should be left alone.)
    rect.X1 = min(rect.X1, rect.X1 - X_OFFSET);
    is equivalent to
    if (X_OFFSET > 0)
       rect.X1 -= X_OFFSET;
    public class OverflowFail {
    	private static void printAssertion(long expected, long got, String label) {
    		System.out.println("expected " + label + " (" + expected + ")" + (got == expected ? " and got the correct value" : ", but got a different value (" + got + ")"));		
    	}
    	public static void main(String[] args) {
    		long x = Long.MIN_VALUE;
    		long y = 1;
    		long result = Math.min(x, x - y);
    		if (y > 0)
    			printAssertion(x - y, result, "x - y");
    		else
    			printAssertion(x, result, "x");
    	}
    }
    
  • John (unregistered)

    Seems more likely that at some point they tried adding/subtracting various values other than zeo, found that those weren't handling all of the issues, tried some other stuff elsewhere in the code that did fix the issues, but now found that they were off by the non-zero amounts, so changed all of those amounts to zero, and just never went back and removed these lines of code. But... whatever.

  • DWTF is a bunch of made up shit. (unregistered) in reply to Playit Safe

    A capture-replace expression on the alphabet character class. sed would do the trick but you're certainly not constrained to a 1 line shell script as any editor worth its salt has this functionality.

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

Log In or post as a guest

Replying to comment #:

« Return to Article