• (cs)

    Are ya WTF-ed out yet? Let's hope not, otherwise you'd miss out on Duane Homick's discovery of the strftime documentation ...

    %S is replaced by the second as a decimal number [00,61].



    This is a WTF on the face of it, but there's a very good reason for seconds to includ e  61.  That would be when leap seconds happen, which they do periodically to allow clocks to  synchronize with the gradual slowing rotation of the Earth.
  • (cs)
    Alex Papadimoulis:
    could be fairly easily simplified to ";".

    isActive = (isActive == <font color="#0000ff">true</font>) ? <font color="#0000ff">true</font> : <font color="#0000ff">false</font>;


    Or ""
  • (cs)

    I laughed at most of the above, but I didn't see the problem with the strftime man page. I believe the values are valid because of leap seconds aren't they? Or am I missing something else that should be funny?

  • (cs) in reply to sinistral
    sinistral:

    Are ya WTF-ed out yet? Let's hope not, otherwise you'd miss out on Duane Homick's discovery of the strftime documentation ...

    %S is replaced by the second as a decimal number [00,61].



    This is a WTF on the face of it, but there's a very good reason for seconds to includ e  61.  That would be when leap seconds happen, which they do periodically to allow clocks to  synchronize with the gradual slowing rotation of the Earth.


    Indeed, the linked manpage says just that:
    "The range of values for %S is [00,61] rather than [00,59] to allow for the occasional leap second and even more infrequent double leap second."
  • ACoward (unregistered)

    What's the obscure synonym of 'jumble'???

  • (cs)
    Alex Papadimoulis:
      if (this == null)
      {
        throw new ArgumentNullException("this");
    }



    I've always hated those zombie classes.  They're dead but they just keep coming at ya.
  • (cs) in reply to ACoward
    Anonymous:
    What's the obscure synonym of 'jumble'???

    Farrago
  • (cs)
    Alex Papadimoulis:

    We'll start out with this simple piece of code that Jake Vinson tripped over while chasing bugs ...

    <font color="#0000ff">if</font>(3 < 4)
    {
    <font color="#0000ff">if</font>(chk.value == <font color="#ff0000">'Yes'</font>)
    fld.value = <font color="#ff0000">'No'</font>;
    <font color="#0000ff">else</font> fld.value = <font color="#ff0000">'Yes'</font>;
    }


    I've written code vaguely similar to this to trick the compiler, strictly debugging purposes.. I don't see how it applies here though.

    When I do it, it's usually because I want to return from a function early just to test something, say:

    <font size="1">int function() {
      statementOne;
     
      // <--   I just want to return a "correct" value here to see if it is the calling function that is the problem
     
      statementTwo;
     
      return realReturnValue;
    }</font>

    But if I just stick a "return 5;" in where my comment is, the compiler will complain that statementTwo can never be reached.  So I'll do this:

    <font size="1">int function() {</font>
    <font size="1">  statementOne;</font>
    <font size="1">  </font>
    <font size="1">  if (5 > 4)</font>
    <font size="1">    return 5;  // I just want to return a "correct" value here to see if it is the calling function that is the problem</font>
    <font size="1">  </font>
    <font size="1">  statementTwo;</font>
    <font size="1">  </font>
    <font size="1">  return realReturnValue;</font>
    <font size="1">}</font>

    And that is enough to trick the compiler.  But I don't see any reason for the WTF code, since it is not avoiding any compiler complaints.
  • Defender? (unregistered)
    Alex Papadimoulis:

    <FONT color=#0000ff>IF</FONT> (current_num - prev_num = current_num) <FONT color=#0000ff>THEN</FONT>

    If this is an odd way of testing "prev_num == 0", then it's a WTF.

    But without knowing the types, it's hard to say.  If, for instance, they're floats, then the expression could be true with prev_num != 0.

  • Romeo (unregistered) in reply to Maurits
    Maurits:
    sinistral:

    Are ya WTF-ed out yet? Let's hope not, otherwise you'd miss out on Duane Homick's discovery of the strftime documentation ...

    %S is replaced by the second as a decimal number [00,61].



    This is a WTF on the face of it, but there's a very good reason for seconds to includ e  61.  That would be when leap seconds happen, which they do periodically to allow clocks to  synchronize with the gradual slowing rotation of the Earth.


    Indeed, the linked manpage says just that:
    "The range of values for %S is [00,61] rather than [00,59] to allow for the occasional leap second and even more infrequent double leap second."


    Do they ever thought about a even more infrequent triple leap second?
  • Ronaldo Arribanorte (unregistered)

    Regarding the last example (dot net DrawImage method), I'm pretty sure the (this == null) check is useful when the method is invoked via reflection, and the "this" object is actually a parameter to the method invocation.  Can anyone confirm this?

  • (cs)
    Alex Papadimoulis:

    public void DrawImage(Image image, int x, int y)
    {
      if (this == null)
      {
        throw new ArgumentNullException("this");
      }
    }

    I've seen this idiom quite a bit in C++ to help cushion against null pointer problems, since 0->func(a,b,c); compiles with thiscall as _decorated_func(0,a,b,c) -- but in .Net? WTF indeed...

  • (cs) in reply to kipthegreat

    So who's got the COBOL -> 2005 translation? :)

  • (cs) in reply to Scott B.

    Scott B.:
    So who's got the COBOL -> 2005 translation? :)

    CONST FIVE = 4

    Nothing new certainly, but fun to see it in COBOL.

     

  • (cs) in reply to Ronaldo Arribanorte
    Anonymous:
    Regarding the last example (dot net DrawImage method), I'm pretty sure the (this == null) check is useful when the method is invoked via reflection, and the "this" object is actually a parameter to the method invocation.  Can anyone confirm this?


    'this' is a reserved keyword, that code would never compile:

    Test.cs(17): Identifier expected, 'this' is a keyword

  • 604 (unregistered) in reply to Scott B.

    Well, I was forced to take cobol in HS (I swear I'm only 31 not 50) so I'll take a stab at it...

    The field name is FIVE but its being set with the value of 4. 

    I guess I didn't need my cobol for that either.

    /took cobol in college even
    //Never learned any JCL so all my cobol knowledge is probably a waste
    ///thats fine by me.

  • (cs)

    How in the world could "this" ever equal null?????

    Hey Alex, when you gonna post my Coldfusion wtf?

  • Paul Tomblin (unregistered) in reply to Romeo

    They didn't consider "even more infrequent triple leap second" because the standard defines single and double leap seconds, but triple leap seconds are forbidden.

    Actually, leap seconds are all going away.  They (damn, can't remember the standards body) is going to let the time drift until it reaches some large quanta like a minute in a few centuries.

  • (cs) in reply to Ronaldo Arribanorte
    Anonymous:
    Regarding the last example (dot net DrawImage method), I'm pretty sure the (this == null) check is useful when the method is invoked via reflection, and the "this" object is actually a parameter to the method invocation.  Can anyone confirm this?


    So what you're essentially saying is, this check guards against callers trying to call this method after dynamically creating the owner object?  In the immortal words of Gene Wirchenko:

    I hope you're not serious

    Sincerely,
    Gene Wirchenko
  • Matt (unregistered)

    The strftime(3) man page on OpenBSD give more detail as to why %S goes all the way to 61.

    "%S is replaced by the second as a decimal number (00-61). The range of seconds is (00-61) instead of (00-59) to allow for the periodic occurrence of leap seconds and double leap seconds."

  • (cs) in reply to Paul Tomblin
    Anonymous:
    Actually, leap seconds are all going away.  They (damn, can't remember the standards body) is going to let the time drift until it reaches some large quanta like a minute in a few centuries.

    And $DEITY only knows what all the computer systems in the world will make of the time leaping forward a minute. (Especially any still using Unix-style timekeeping, of which there probably will be some, barring the total collapse of civilisation.)

  • (cs)

    Alex Papadimoulis:

    And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".

    isActive = (isActive == <FONT color=#0000ff>true</FONT>) ? <FONT color=#0000ff>true</FONT> : <FONT color=#0000ff>false</FONT>;

    Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?

  • (cs) in reply to Jenny Simonds
    Jenny Simonds:

    Alex Papadimoulis:

    And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".

    isActive = (isActive == <font color="#0000ff">true</font>) ? <font color="#0000ff">true</font> : <font color="#0000ff">false</font>;

    Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?



    If it was a Boolean, yes, but since its a boolean (small 'b'), no.
  • (cs)
    Alex Papadimoulis:
    <font color="#0000ff">#define private private
    </font>


    #define genius idiot

    The guy who wrote this is surely the greatest genius born to this world in a long time.

  • (cs) in reply to Matt B
    Matt B:
    Anonymous:
    Regarding the last example (dot net DrawImage method), I'm pretty sure the (this == null) check is useful when the method is invoked via reflection, and the "this" object is actually a parameter to the method invocation.  Can anyone confirm this?


    'this' is a reserved keyword, that code would never compile:

    Test.cs(17): Identifier expected, 'this' is a keyword



    That's essentially the point of the WTF in the code.  this refers to the instance of the object, and if it was null that method would never execute.

    I have no clue regarding Renaldo's comment, as my experience with Reflection in .NET is confined primarily to type checking and property information.
  • Cq (unregistered) in reply to kipthegreat

    <font size="1">int function() {</font>
    <font size="1">  statementOne;</font>
    <font size="1">  </font>
    <font size="1">  if (5 > 4)</font>
    <font size="1">    return 5;  // I just want to return a "correct" value here to see if it is the calling function that is the problem</font>
    <font size="1">  </font>
    <font size="1">  statementTwo;</font>
    <font size="1">  </font>
    <font size="1">  return realReturnValue;</font>
    <font size="1">}</font>

    ever tryed :
    if (true) return 5;

    or better:

    if (IsTrue(5 > 4)) return5;

    private bool IsTrue(int x, int y)
    {
    bool istrue;
    if (x ==y) { istrue = true }
    else { istrue = false }
    return istrue

    }

    -C
  • (cs) in reply to Mung Kee
    Mung Kee:
    Jenny Simonds:

    Alex Papadimoulis:

    And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".

    isActive = (isActive == <font color="#0000ff">true</font>) ? <font color="#0000ff">true</font> : <font color="#0000ff">false</font>;

    Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?



    If it was a Boolean, yes, but since its a boolean (small 'b'), no.


    Sorry, on second glance, this wasn't very helpful.  The value of an uninitialized boolean is false in Java and there is no no-arg constructor for the object type Boolean, so left uninitialized it would be null.
  • (cs) in reply to Maurits
    Maurits:

    Indeed, the linked manpage says just that:
    "The range of values for %S is [00,61] rather than [00,59] to allow for the occasional leap second and even more infrequent double leap second."


    And the moral to the story: RTFMB4UWTF.

  • (cs) in reply to Maurits
    Maurits:
    Alex Papadimoulis:
    could be fairly easily simplified to ";".

    isActive = (isActive == <font color="#0000ff">true</font>) ? <font color="#0000ff">true</font> : <font color="#0000ff">false</font>;


    Or ""


    Not always.

  • (cs)

    I've seen another form of the if (this == null) construct in Java.

    Foo foo = new Foo();

    if (foo == null) return;

  • (cs) in reply to kipthegreat
    kipthegreat:

    But if I just stick a "return 5;" in where my comment is, the compiler will complain that statementTwo can never be reached.


    This is because the Java compiler especially is full of WTFs like emitting errors when it should only be emitting warnings.

  • (cs) in reply to Romeo
    Anonymous:
    Do they ever thought about a even more infrequent triple leap second?


    Not in this tense.

  • (cs) in reply to dubwai
    dubwai:

    I've seen another form of the if (this == null) construct in Java.

    Foo foo = new Foo();

    if (foo == null) return;



    You've gotta be careful, sometimes those pesky constructors will actually return a null reference.
  • captain damage (unregistered) in reply to Defender?

    <font>IF</font> (current_num - prev_num = current_num) <font>THEN


    This is a method of testing that the change in numbers is
    too small to have any effect. I've seen and used that construct
    a lot in doing numeric analysis there the algorithm converges
    on some value.
    </font>

  • Jonas Grumby (unregistered) in reply to sinistral
    sinistral:
      That would be when leap seconds happen, which they do periodically to allow clocks to  synchronize with the gradual slowing rotation of the Earth.


    You're right about the leap seconds, but it's not that the earth is slowing.  It's because the length of a solar year isn't exactly the 365.24x days that the gregorian calendar allots for it.  If you have to adjust a wall clock every few months, it's because it's too fast, not because it's getting faster.
  • Ben Scheirman (unregistered) in reply to Cq

    That .NET one was pasted from Reflector, and you'll find a lot of that nonsense in the reflected code.

    Here's a pop quiz:  What's going on in this reflected code?

    public sealed abstract class Foo
    {
        //stuff
    }
  • x (unregistered) in reply to Mung Kee
    Mung Kee:
    Jenny Simonds:
    Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?
    If it was a Boolean, yes, but since its a boolean (small 'b'), no.
    Autoboxing?
  • (cs) in reply to Ytram
    Ytram:
    You've gotta be careful, sometimes those pesky constructors will actually return a null reference.


    Not in any of C#, C++ or Java, so what language are you talking about?

  • (cs) in reply to Ben Scheirman
    Anonymous:
    That .NET one was pasted from Reflector, and you'll find a lot of that nonsense in the reflected code.

    Here's a pop quiz:  What's going on in this reflected code?

    public sealed abstract class Foo
    {
        //stuff
    }


    Seems perfectly alright to me if you don't ever want your class to be instantiated or subclassed. The C# compiler won't allow a mere mortal to write this, though. It would be better to just define only a private constructor.

  • (cs) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    Ytram:
    You've gotta be careful, sometimes those pesky constructors will actually return a null reference.


    Not in any of C#, C++ or Java, so what language are you talking about?



    Go into a C# project and create a class with a constructor.  In the constructor, do the following:

    1.  Have the constructor take any value type, reference types won't work.
    2.  Within the constructor, set the parameter to null.
    3.  Add the line, "return null;" to the end of the constructor.
    4.  Realize that I am being sarcastic.

    Hopefully that should show you what I'm talking about.
  • (cs) in reply to Jonas Grumby
    Anonymous:
    You're right about the leap seconds, but it's not that the earth is slowing.  It's because the length of a solar year isn't exactly the 365.24x days that the gregorian calendar allots for it.  If you have to adjust a wall clock every few months, it's because it's too fast, not because it's getting faster.


    Not only because of the solar year length, but also to keep 00:00 at precisely the moment when the sun is opposite the 0° meridian. The earth's rotation isn't 100% uniform; it slows and speeds up due to the moon and the other planets.
  • Fj (unregistered) in reply to Ytram

    I suppose, something written here http://www.andymcm.com/dotnetfaq.htm, have produced such a confusion of ideas in the head of a programmer who wrote "if (this == null)". Actually, destructor may have been called during the method call in some circumstances, you know. 

  • (cs) in reply to Ytram
    Ytram:
    4.  Realize that I am being sarcastic.


    Steps 1 to 3 were easy, but now I'm stuck at number 4. Tough one.

  • (cs) in reply to Alexis de Torquemada

    I'm sorry, I should have clarified that you need to compile after step 3. [:P]

  • (cs) in reply to captain damage
    Anonymous:
    <FONT size=+0>IF</FONT> (current_num - prev_num = current_num) <FONT size=+0>THEN


    This is a method of testing that the change in numbers is
    too small to have any effect. I've seen and used that construct
    a lot in doing numeric analysis there the algorithm converges
    on some value.
    </FONT>

    <FONT face="Courier New" size=2>this is why mathematicians cannot program.  QED.</FONT>

  • Anonymous (unregistered) in reply to sinistral

    The strftime() documentation is still wrong. Unless you modify a struct tm's fields yourself, the seconds will never be more than 59. struct tm's are generated by the gmtime and localtime functions, which take a time_t so there it no way they can distinguish between
    2004/12/31 23:59:60 and 2005/01/01 00:00:00, since they both would have a time_t value of 1104537600.

  • (cs) in reply to Mung Kee
    Mung Kee:
    Jenny Simonds:

    Alex Papadimoulis:

    And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".

    isActive = (isActive == <font color="#0000ff">true</font>) ? <font color="#0000ff">true</font> : <font color="#0000ff">false</font>;

    Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?



    If it was a Boolean, yes, but since its a boolean (small 'b'), no.

    What if it's not a boolean?
    Couldn't it be some other type with the == operator overloaded?
    (I'm not that familiar with Java; does it even support operator overloading?)
  • (cs) in reply to Anonymous
    Anonymous:
    The strftime() documentation is still wrong. Unless you modify a struct tm's fields yourself, the seconds will never be more than 59. struct tm's are generated by the gmtime and localtime functions, which take a time_t so there it no way they can distinguish between
    2004/12/31 23:59:60 and 2005/01/01 00:00:00, since they both would have a time_t value of 1104537600.


    Usually true, not always.
    http://en.wikipedia.org/wiki/Leap_second

    The next leap second will occur at the very end of December 31 2005.
    Let me count the new year down for you...
    2005/12/31 23:59:51 TEN!
    2005/12/31 23:59:52 NINE!
    2005/12/31 23:59:53 EIGHT!
    2005/12/31 23:59:54 SEVEN!
    2005/12/31 23:59:55 SIX!
    2005/12/31 23:59:56 FIVE!
    2005/12/31 23:59:57 FOUR!
    2005/12/31 23:59:58 THREE!
    2005/12/31 23:59:59 TWO!
    2005/12/31 23:59:60 ONE!
    <font style="color: rgb(255, 0, 0);" size="4">2006/01/01 00:00:00 HAPPY NEW YEAR!</font>

    It will be interesting to see if the ball drops a second early.
  • travis (unregistered) in reply to John Smallberries
    John Smallberries:
    Mung Kee:
    Jenny Simonds:

    Alex Papadimoulis:

    And speaking of pointless code, John pulled this line of triply-redundant code from a Java production system that could be fairly easily simplified to ";".

    isActive = (isActive == <FONT color=#0000ff>true</FONT>) ? <FONT color=#0000ff>true</FONT> : <FONT color=#0000ff>false</FONT>;

    Not familiar with Java, but couldn't isActive have been set earlier to something like null, NaN, or undefined?



    If it was a Boolean, yes, but since its a boolean (small 'b'), no.

    What if it's not a boolean?
    Couldn't it be some other type with the == operator overloaded?
    (I'm not that familiar with Java; does it even support operator overloading?)

    Nope...no operator overloading in Java

  • Anonymous (unregistered) in reply to Maurits

    The time_t will have the same value, 1136073600, on both of those last two seconds. So there's no way localtime/gmtime can distinguish them, unless it does something really weird.

Leave a comment on “The Friday Farrago ”

Log In or post as a guest

Replying to comment #:

« Return to Article