• (cs) in reply to fregas

    Fish...Shotgun...Barrel.  Must control urge to shoot...Coldfusion, he, he he.

  • (cs) in reply to LaurieF
    LaurieF:
    Alex Papadimoulis:
    Laurie F wrote in to share a tricky bug that took almost a week to debug. It was about twenty-five years ago, and in COBOL on a good ole' IBM 4341. It may be in a foreign language to most here, but see if you can spot it yourself ...

           <FONT color=#a52a2a>77  FIVE               PIC S9(4) COMP     VALUE 4.</FONT>

    It's obvious now, looking at the code like this, what was wrong. But (and this is all from memory) it was long (2,000+), badly written, and we didn't have the luxury of debuggers. I just love reading core dumps.

    The <FONT style="BACKGROUND-COLOR: #ffffff" face="Courier New" color=#a52a2a>77</FONT><FONT face="Times New Roman"> tricked me off into believing this must have been a huge program. How else do you get to so many levels?</FONT>

    I loved COBOL for it's <FONT face="Courier New" color=#a52a2a>REDEFINES</FONT>. That is the single feature that makes me want to use it sometimes. If I could have that in VB, I'ld be so happy!

  • (cs) in reply to mdecarle
    mdecarle:

    I loved COBOL for it's <font color="#a52a2a" face="Courier New">REDEFINES</font>. That is the single feature that makes me want to use it sometimes. If I could have that in VB, I'ld be so happy!



    A union in C is mostly the same, isn't it? No reason to use Cobol then.
  • zootm (unregistered) in reply to Alexis de Torquemada

    As much as people like to blame the compiler when they've written dodgy code, I think you'll find the errors help people not write nonsense.

  • zootm (unregistered) in reply to zootm

    (in reference to someone who chimed in that the Java compiler is giving errors where it "should" be giving warnings)

  • anon (unregistered)
    Alex Papadimoulis:

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

    But then again, from the same manpage:

    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.

    Reading's hard, isn't it?

  • grimskunk (unregistered) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    Anonymous:
    I love reading the WTF replies from people who have no idea what they are talking about.


    You love reading your own posts?

    Anonymous:

    In C++, the "isActive" example is perfectly valid (but verbose) because even a "bool" has more values than just true and false.


    Actually, that's complete and utter bollocks.Thanks for trying, anyway.



    As one example...
    <font>In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int.

    Fron windef.h:
    typedef int                 BOOL;
    #ifndef FALSE
    #define FALSE               0
    #endif

    #ifndef TRUE
    #define TRUE                1
    #endif

    isActive isn't of type BOOL of course, cuz "true" wouldn't be a valid keyword.. unless it was typedef'd too.</font>
  • (cs) in reply to grimskunk

    grimskunk: "As one example... In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int.

    Fron windef.h: typedef int BOOL; #ifndef FALSE #define FALSE 0 #endif

    #ifndef TRUE #define TRUE 1 #endif

    isActive isn't of type BOOL of course, cuz "true" wouldn't be a valid keyword.. unless it was typedef'd too."

    No, that equates BOOL with int. C++ is case sensitive, and BOOL (from a pre-standard C++) and bool are not the same thing. Microsoft's BOOL type was one of a number of fudges, none of which completely worked, that forced the addition of bool to the language.

  • Anon Ymus (unregistered) in reply to anon
    Anonymous:
    Alex Papadimoulis:

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

    But then again, from the same manpage:

    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.

    Reading's hard, isn't it?

    Try reading previous posts before making remarks 'bout reading.

     

  • (cs) in reply to kipthegreat
    kipthegreat:
    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.


    I've left junk like that (not this basic, but similar) lying around before. Say, you're testing for a real condition 5 > X, and you write a bunch of conditional code, and then your boss changes something so that the whole conditional no longer applies, but only one branch of it. So then you change it to something stupid, like if(4>5){} or if(5>4){}, so that when the big guy changes his mind AGAIN, you can just shift it back...But then he never does, and it goes off to plague someone years down the line. Bad form, of course, but I'll own up to it.

    I don't see why anyone would do that in this case...All he really wants is "if(true){}"



  • Dave (unregistered) in reply to Maurits
    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.

    Only if you live in GMT.  The countdown for "the ball" dropped in New York (in EST) will be normal; according to http://en.wikipedia.org/wiki/Leap_second the leap second will be at 2005-12-31 18:59:60 EST.
  • (cs) in reply to grimskunk
    Anonymous:

    Anonymous:

    In C++, the "isActive" example is perfectly valid (but verbose) because even a "bool" has more values than just true and false.


    As one example...
    <font>In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int.

    Fron windef.h:
    typedef int                 BOOL;
    #ifndef FALSE
    #define FALSE               0
    #endif

    #ifndef TRUE
    #define TRUE                1
    #endif

    isActive isn't of type BOOL of course, cuz "true" wouldn't be a valid keyword.. unless it was typedef'd too.</font>


    Good point, though malicious readers might object that "BOOL" isn't "bool" and "windef.h" isn't standard C++.

  • (cs) in reply to zootm
    Anonymous:
    As much as people like to blame the compiler when they've written dodgy code, I think you'll find the errors help people not write nonsense.


    So you don't read compiler warnings, then? I'll tell you what: That's your problem, not mine. The one thing I remember about the Java compiler is that it often pretended to be smarter than me, and turned out to be dumber every single time. In your case, of course, the result may be different.

    Java is like forcing grown men to wear diapers.

  • (cs) in reply to Alexis de Torquemada
    Alexis de Torquemada:
    Anonymous:
    As much as people like to blame the compiler when they've written dodgy code, I think you'll find the errors help people not write nonsense.


    So you don't read compiler warnings, then? I'll tell you what: That's your problem, not mine. The one thing I remember about the Java compiler is that it often pretended to be smarter than me, and turned out to be dumber every single time. In your case, of course, the result may be different.

    Java is like forcing grown men to wear diapers.



    Quit your conjecture-based b*tching.  Take Java's messages for what they're worth and move on.  I guess when you get $hit in the way of intuitive error messages with C++, I can see why you'd hate verbosity.
  • (cs) in reply to josh
    Anonymous:
    Apoch:

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



    Technically that's too late to do this in C++.  You're dereferencing a NULL pointer to call the function, so it's undefined behavior.  Certainly, if it's a virtual function (that the compiler can't resolve), you're screwed.  (also, multiple inheritance could cause a more subtil problem)  Otherwise, most implementations do define the behavior to be "call the member function with this == 0."  Still, it's a sign of less than wonderful code.

    Try it out for yourself. Define a class with a non-static, non-virtual member function that doesn't touch any member data of the class itself - maybe just sets a global or something for testing purposes. Call the function from a null pointer (0->func();) and trace the call in a debugger. The function will enter and execute with an implicit this parameter of 0, as required by the thiscall calling convention.

    You only get into trouble if A) you call a virtual function on a null pointer or B) the function called touches the object's members in any way (oo err). At a machine code level, a call to 0->func() doesn't technically "dereference" the null pointer until the object itself is touched. This includes calling other member functions that touch members, reading or writing member variables, and calling any virtual function of the object. Basically, where x is a pointer to an object, and func is a nonstatic member function, x->func() is equivalent to func(x) in the thiscall convention. If x is never actually used in func, there's no problem. The chances of useful code not ever touching x, however, are miniscule.

    So it's extremely rare that actual code will survive a call to 0->func(), but it is possible - I've seen a couple of really nasty bugs come of it. Yes, it's usually a bad sign if your member function implementations really have to check for a null this, but in some cases it is perfectly valid (such as the GetSafeHWND MFC call mentioned earlier, and certain design patterns that rely on unusual construction methods).

  • (cs) in reply to Alexis de Torquemada

    Alexis de Torquemada:
    So you don't read compiler warnings, then? I'll tell you what: That's your problem, not mine. The one thing I remember about the Java compiler is that it often pretended to be smarter than me, and turned out to be dumber every single time. In your case, of course, the result may be different.

    Java is like forcing grown men to wear diapers.

    <FONT face="Courier New" size=2>all striking tributes to diaper fetishism aside, the java compiler is smarter than you.  people who make statements about 'dumb compilers' after 1998 are either still programming a lode runner port to FORTRAN 77 or have no idea what they're talking about.</FONT>

  • (cs) in reply to emurphy

    emurphy:
    Is this a troll?

    <FONT face="Courier New" size=2>no, that is a not a troll.  in fact, it's everything a troll can't be, and more.</FONT>

  • (cs) in reply to x
    Anonymous:
    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?


    Nope, you have to construct the object type.
  • (cs) in reply to emptyset
    emptyset:
    <font face="Courier New" size="2">it's everything a troll can't be, and more.</font>


     * Maurits draws Venn diagram

    So... it is a troll?
  • (cs)
    Alex Papadimoulis:

    <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>;
    }


    Why am I not seeing a IsTrue call in this!? I mean how else could 3 < 4 be false unless we randomly choose true or false to filter out the  bias.
  • (cs) in reply to Maurits

    Maurits:
    emptyset:
    <FONT face="Courier New" size=2>it's everything a troll can't be, and more.</FONT>


     * Maurits draws Venn diagram

    So... it is a troll?

    <FONT face="Courier New" size=2>'more' is a set disjoint from the things a troll can't be.  the difference of the universal set and the set of things a troll can't be is the set of things a troll can be.  the intersection of 'more' and the set of things a troll can be is empty.  the comment that was previous to the one i quoted fell in the union of the sets "things a troll can't be" and "more".</FONT>

    <FONT face="Courier New" size=2>so when you draw your venn diagram with a red crayola marker, and partition your universe box into "troll" and "not troll", take that marker and draw a circle on your forehead.  label it "more".  then spin your head around and vomit blood.</FONT>

  • (cs) in reply to emptyset
    emptyset:

    Maurits:
    emptyset:
    <FONT face="Courier New" size=2>it's everything a troll can't be, and more.</FONT>


     * Maurits draws Venn diagram

    So... it is a troll?

    <FONT face="Courier New" size=2>'more' is a set disjoint from the things a troll can't be.  the difference of the universal set and the set of things a troll can't be is the set of things a troll can be.  the intersection of 'more' and the set of things a troll can be is empty.  the comment that was previous to the one i quoted fell in the union of the sets "things a troll can't be" and "more".</FONT>

    <FONT face="Courier New" size=2>so when you draw your venn diagram with a red crayola marker, and partition your universe box into "troll" and "not troll", take that marker and draw a circle on your forehead.  label it "more".  then spin your head around and vomit blood.</FONT>

    Umm...
    Let A = everything a troll can be
    Let B = everything a troll can Not be = complement A
    Let C = everything a troll can Not be and MORE
    By definition, C contains an element which does not belong to B (the MORE), thus contains an element which belongs to A. Look ma! a Troll.

  • (cs) in reply to OneFactor
    OneFactor:
    emptyset:

    Maurits:
    emptyset:
    <font face="Courier New" size="2">it's everything a troll can't be, and more.</font>


     * Maurits draws Venn diagram

    So... it is a troll?

    <font face="Courier New" size="2">'more' is a set disjoint from the things a troll can't be.  the difference of the universal set and the set of things a troll can't be is the set of things a troll can be.  the intersection of 'more' and the set of things a troll can be is empty.  the comment that was previous to the one i quoted fell in the union of the sets "things a troll can't be" and "more".</font>

    <font face="Courier New" size="2">so when you draw your venn diagram with a red crayola marker, and partition your universe box into "troll" and "not troll", take that marker and draw a circle on your forehead.  label it "more".  then spin your head around and vomit blood.</font>

    Umm...
    Let A = everything a troll can be
    Let B = everything a troll can Not be = complement A
    Let C = everything a troll can Not be and MORE
    By definition, C contains an element which does not belong to B (the MORE), thus contains an element which belongs to A. Look ma! a Troll.



    Couldn't it just be everything that is not related in any way shape or form to being a troll?
  • (cs) in reply to Mike R

    Mike R:
    Couldn't it just be everything that is not related in any way shape or form to being a troll?

    <FONT face="Courier New" size=2>the powerful technique of invoking sets that do not exist in the implied universal set is lost on the masses.</FONT>

  • (cs) in reply to sinistral
    <FONT color=#1000a0>Public</FONT> <FONT color=#1000a0>Sub</FONT> DrawImage(<FONT color=#1000a0>ByVal</FONT> image<FONT color=#1000a0> As </FONT><FONT color=#006018>Image</FONT>, <FONT color=#1000a0>ByVal</FONT> x<FONT color=#1000a0> As </FONT><FONT color=#006018>Integer</FONT>, <FONT color=#1000a0>ByVal</FONT> y<FONT color=#1000a0> As </FONT><FONT color=#006018>Integer</FONT>)
          <FONT color=#1000a0>If</FONT> (<FONT color=#1000a0>Me</FONT> <FONT color=#1000a0>Is</FONT> <FONT color=#800000>Nothing</FONT>) <FONT color=#1000a0>Then</FONT>
                <FONT color=#1000a0>Throw</FONT> <FONT color=#1000a0>New</FONT> <FONT color=#006018>ArgumentNullException</FONT>(<FONT color=#800000>"this"</FONT>)
          <FONT color=#1000a0>End If</FONT>
          <FONT color=#1000a0>If</FONT> (<FONT color=#006018>image</FONT> <FONT color=#1000a0>Is</FONT> <FONT color=#800000>Nothing</FONT>) <FONT color=#1000a0>Then</FONT>
                <FONT color=#1000a0>Throw</FONT> <FONT color=#1000a0>New</FONT> <FONT color=#006018>ArgumentNullException</FONT>(<FONT color=#800000>"image"</FONT>)
          <FONT color=#1000a0>End If</FONT>
          <FONT color=#1000a0>Dim</FONT> num1<FONT color=#1000a0> As </FONT><FONT color=#006018>Integer</FONT> = <FONT color=#006018>SafeNativeMethods</FONT>.<FONT color=#006018>GdipDrawImageI</FONT>(<FONT color=#1000a0>New</FONT> <FONT color=#006018>HandleRef</FONT>(<FONT color=#1000a0>Me</FONT>, <FONT color=#1000a0>Me</FONT>.<FONT color=#006018>nativeGraphics</FONT>), <FONT color=#1000a0>New</FONT> <FONT color=#006018>HandleRef</FONT>(<FONT color=#006018>image</FONT>, <FONT color=#006018>image</FONT>.<FONT color=#006018>nativeImage</FONT>), <FONT color=#006018>x</FONT>, <FONT color=#006018>y</FONT>)
          <FONT color=#1000a0>Me</FONT>.<FONT color=#006018>CheckErrorStatus</FONT>(<FONT color=#006018>num1</FONT>)
    <FONT color=#1000a0>End Sub</FONT>
    
    waahahahhaha!!! gotta love MS!
    If Me Is Nothing! some people over there got some problems with reality?
  • (cs) in reply to RiX0R
    RiX0R:
    davidmwilliams:

    In the Foo example above, what if the constructor had an exception or if the system did not have enough memory to create a new object?

    Then the code path would be aborted and resumed at the nearest exception handler. So the check would never be run anyway.

    What if the exception handler checked the value of foo?

    Isn't this something that all programmers are meant to know? That a computer has only a finite amount of storage?

    Hasn't anyone else here paid their dues to C's malloc function, and the need to check for NULL afterwards?

  • (cs) in reply to emptyset
    emptyset:

    Alexis de Torquemada:
    So you don't read compiler warnings, then? I'll tell you what: That's your problem, not mine. The one thing I remember about the Java compiler is that it often pretended to be smarter than me, and turned out to be dumber every single time. In your case, of course, the result may be different.

    Java is like forcing grown men to wear diapers.

    <FONT face="Courier New" size=2>all striking tributes to diaper fetishism aside, the java compiler is smarter than you.  people who make statements about 'dumb compilers' after 1998 are either still programming a lode runner port to FORTRAN 77 or have no idea what they're talking about.</FONT>

    How about if I learnt to programme with Python; can I think Java has a dumb compiler then?

    Dumb as in statically typed, of course. It doesn't seem to produce overly much
    of a performance increase, so I can only presume it's there because an assumption was made at some level that programmers need static typing.
    As for the "You can't overload operators because..." thing...

    I mean, Jython gets on fine with the JVM without static typing.

    But, I kid, of course, I just think Java itself is a little dumb at times. ;p
    But then, I'm spoilt, and I had a horrid time learning Java and dealing with unhelpful error messages. Took me ages to figure out why static methods can't call non-static methods... or something like that.

  • phx (unregistered) in reply to Ronaldo Arribanorte

    A non-static method in .Net MSIL is just an ordinary method that takes in a "this" pointer as argument 0 under the hood.

    You can invoke a method by reflection or interop and pass in a null this pointer and cause null reference exceptions when a field is accessed.

  • (cs) in reply to Mike R
    Mike R:
    OneFactor:
    emptyset:

    Maurits:
    emptyset:
    <FONT face="Courier New" size=2>it's everything a troll can't be, and more.</FONT>


     * Maurits draws Venn diagram

    So... it is a troll?

    <FONT face="Courier New" size=2>'more' is a set disjoint from the things a troll can't be.  the difference of the universal set and the set of things a troll can't be is the set of things a troll can be.  the intersection of 'more' and the set of things a troll can be is empty.  the comment that was previous to the one i quoted fell in the union of the sets "things a troll can't be" and "more".</FONT>

    <FONT face="Courier New" size=2>so when you draw your venn diagram with a red crayola marker, and partition your universe box into "troll" and "not troll", take that marker and draw a circle on your forehead.  label it "more".  then spin your head around and vomit blood.</FONT>

    Umm...
    Let A = everything a troll can be
    Let B = everything a troll can Not be = complement A
    Let C = everything a troll can Not be and MORE
    By definition, C contains an element which does not belong to B (the MORE), thus contains an element which belongs to A. Look ma! a Troll.



    Couldn't it just be everything that is not related in any way shape or form to being a troll?

    Hypothesis: couldn't it just be that MORE is the empty set?

  • (cs) in reply to ammoQ
    ammoQ:
    mdecarle:

    I loved COBOL for it's <FONT face="Courier New" color=#a52a2a>REDEFINES</FONT>. That is the single feature that makes me want to use it sometimes. If I could have that in VB, I'ld be so happy!



    A union in C is mostly the same, isn't it? No reason to use Cobol then.
    You get a variable, that is a combination of variables. But you can redefine it, so that it becomes another set of variables. Plus, you can read a line from a text file into the complete variable.

    It's the numerical variables that breaks that.

  • (cs) in reply to Cyresse

    Cyresse:
    How about if I learnt to programme with Python; can I think Java has a dumb compiler then?

    <FONT face="Courier New" size=2>no.  but if you've taken a stab at writing a compiler, then i suppose you could find and understand some valid critiques of the java compiler.  this doesn't appear to be the case here.</FONT>

    Cyresse:
    Dumb as in statically typed, of course. It doesn't seem to produce overly much of a performance increase, so I can only presume it's there because an assumption was made at some level that programmers need static typing.

    <FONT face="Courier New" size=2>well, if you're using java to write in the object-oriented style, it makes more sense to have static types.  if you look at something like ML, it can be a pain in the ass to get the types working together.  what you realize after a while is that if you fix the type errors, the program is pretty much correct - your algorithms might be wrong though.  then ML sets you free.</FONT>

    Cyresse:
    I mean, Jython gets on fine with the JVM without static typing.

    <FONT face="Courier New" size=2>there's a lot going on there you may not be aware of.</FONT>

    Cyresse:
    But, I kid, of course, I just think Java itself is a little dumb at times. ;p
    But then, I'm spoilt, and I had a horrid time learning Java and dealing with unhelpful error messages. Took me ages to figure out why static methods can't call non-static methods... or something like that.

    <FONT face="Courier New" size=2>yeah, i agree.  going from a dynamic to a statically typed language can be hell, if you're learning.  </FONT>

  • (cs) in reply to Enric Naval

    Enric Naval:
    Hypothesis: couldn't it just be that MORE is the empty set?

    <FONT face="Courier New" size=2>hypothesis: stop watching william shatner.</FONT>

  • (cs) in reply to Cyresse
    Cyresse:
    Took me ages to figure out why static methods can't call non-static methods... or something like that.


    At the time, did you know the difference in purpose between a Class and an Object/Instance?  That difference provides your answer.  Static methods are, in a sense, members of the Class and non-static methods are members of the Object/Instance.
  • (cs) in reply to Enric Naval
    Enric Naval:

    Hypothesis: couldn't it just be that MORE is the empty set?

    Hmm... yes, especially if the set of everything a troll can be is the empty set. I suppose MORE could simply mean it was disjoint from the previous set and not that it actually contained elements. Ma, can I have more soup? Sure here you are. But Ma, the soup bowl is empty. Ah, but as long as the contents of the soup bowl are disjoint from the soup you previously had, it qualifies as more.

    I don't like that. I think more means "it is not a subset of" which means that it cannot be empty as the empty set is a subset of every set.

  • (cs) in reply to Mung Kee

    Mung Kee:
    Cyresse:
    Took me ages to figure out why static methods can't call non-static methods... or something like that.


    At the time, did you know the difference in purpose between a Class and an Object/Instance?  That difference provides your answer.  Static methods are, in a sense, members of the Class and non-static methods are members of the Object/Instance.

    Reminds me of my struggles with Java when I was just learning. I think the trouble was I was instantiating my object from within the public static void main of that same class and getting confused. If I had used two classes, one with a public static void main and the other to define the object I was creating it would have been less confusing. Ah - fond memories of the newbie days, like when I stuck junit.jar into jre/lib/ext and wondered why I could no longer run my unit tests....

  • Amazing! (unregistered) in reply to Mung Kee
    Mung Kee:
    Cyresse:
    Took me ages to figure out why static methods can't call non-static methods... or something like that.


    At the time, did you know the difference in purpose between a Class and an Object/Instance?  That difference provides your answer.  Static methods are, in a sense, members of the Class and non-static methods are members of the Object/Instance.


    Wow, a helpful and concise response!  Grab the recordbooks!
  • Hasani (unregistered) in reply to Fj
    Anonymous:

    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. 

     

    Sorry buddy, but only the garbage collector calls Finalizers and it is only called when there are no references to the object.

  • (cs) in reply to emptyset

    I'll bet you didn't know that the Java compiler (Sun J2SE 1.5, I think that is what it's called) lets you access a private static final variable in one class from a completely different one without any warnings or errors at all. Calling it "dumb" is too kind.

  • (cs) in reply to RajaMukherji
    RajaMukherji:
    I'll bet you didn't know that the Java compiler (Sun J2SE 1.5, I think that is what it's called) lets you access a private static final variable in one class from a completely different one without any warnings or errors at all. Calling it "dumb" is too kind.


    Were you replying to someone?  Where did you hear about this?  I'd be quite surprised.
  • (cs)

    Here is a special, mainly paranoic rationale for

    isActive=(isActive==true)?true:false;

    Imagine it is C++:

    <FONT color=#0000ff>class</FONT> Active
    {
    <FONT color=#0000ff>public</FONT>:
    Conditional <FONT color=#0000ff>operator</FONT>==(bool v) <FONT color=#0000ff>const</FONT>;
    Active& <FONT color=#0000ff>operator</FONT>=(ConvertibleFromBool v);
    // and some extra stuff...




    };
    Active isActive;

    where

    Conditional is a type that can be treated as boolean in conditional expressions:

    • bool itself (Not here, because we could reduce to isActive = (isActive == true); )
    • any numeric type (int, char, double etc.)
    • any enumeration
    • any pointer, pointer to function, pointer to member
    • finally, any class with defined operator bool() const

    ConvertibleFromBool is a type that can be constructed on bool values:

    • bool itself (Why not?! We could fight "performance warning: explicit conversion from XXX to bool" where XXX is numeric or pointer type)
    • any numeric type (false -> 0, true -> 1)
    • finally, any class with defined constructor(bool)

    And there should be no implicit conversion available from Conditional to ConvertibleFromBool.

    WTF, you ask? Yes, above is just TF. But more let's see tri-state logic class, boost::tribool...

    Yes, yes, there's a conversion from bool to tristate, so we can reduce to isActive = (isActive==true);

    But there might be some context: for instance,

    isActive  = (isActive  == true   ) ? true  : false;
    isArchive = (isArchive == false ) ? true : anotherArchive;
    isAbove = (isAbove == isBelow) ? false : true;

    looks more clear than reduced nonuniform expressions.

  • (cs) in reply to Mung Kee

    Mung Kee:
    Cyresse:
    Took me ages to figure out why static methods can't call non-static methods... or something like that.


    At the time, did you know the difference in purpose between a Class and an Object/Instance?  That difference provides your answer.  Static methods are, in a sense, members of the Class and non-static methods are members of the Object/Instance.

    I think the issue was attempting to programme in Java like I did in Python.
    I was using main() like __init__().

    Or was I using it like if __name__ == "__main__" ? Either way, I'd forgotten to take my Python hat off.

    At the time I was relatively acquainted with the basics of OO, but not Java's variant of it, so I knew the difference between something at class level, and something at instance level, but I'm buggered if Java didn't scare me off OO for about 3 months.

    I'd just like to thank everyone who replied for not flaming me in doing so, btw, most refreshing. I've been kicking around with the idea of playing around with Java again for awhile... what sort of project does Java suit? 

  • (cs) in reply to Cyresse
    Cyresse:

    Mung Kee:
    Cyresse:
    Took me ages to figure out why static methods can't call non-static methods... or something like that.


    At the time, did you know the difference in purpose between a Class and an Object/Instance?  That difference provides your answer.  Static methods are, in a sense, members of the Class and non-static methods are members of the Object/Instance.

    I think the issue was attempting to programme in Java like I did in Python.
    I was using main() like __init__().

    Or was I using it like if __name__ == "__main__" ? Either way, I'd forgotten to take my Python hat off.

    At the time I was relatively acquainted with the basics of OO, but not Java's variant of it, so I knew the difference between something at class level, and something at instance level, but I'm buggered if Java didn't scare me off OO for about 3 months.

    I'd just like to thank everyone who replied for not flaming me in doing so, btw, most refreshing. I've been kicking around with the idea of playing around with Java again for awhile... what sort of project does Java suit? 



    Without a doubt, small to large web applications.  If you're going to develop a fat client with it, it's Swing components and event model are going to force you to write code you're not proud of.  I would hope that .NET is better in this arena.
  • Jivemonkey (unregistered) in reply to Matt B

    actually it does compile.

  • seebs (unregistered)

    strftime was specified by people who had not been able to get an absolute assurance that leap seconds could not be doubled up.

  • Dionysius Exiguus (unregistered) in reply to Romeo
    Anonymous:
    Maurits:

    "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?


    The last time a triple leap second occurred was on February 29 during the third full moon of the month on a Friday the 13th (which fell on Halloween that year), and this is not likely to occur again any time soon.  I remember it well; I was travelling by ship at the time and the ship had just crossed the international date line from west to east (in reverse), and a female passenger who was pregnant with twins had just given birth to the younger of her two children, and was about to give birth to his older brother....

  • SeeVeeEss (unregistered) in reply to Satanicpuppy
    Satanicpuppy:
    Say ... you write a bunch of conditional code, and then your boss changes something so that the whole conditional no longer applies.... So then you change it to something ... like if(4>5){}... so that when the big guy changes his mind AGAIN, you can just shift it back...


    Yeah.  Wouldn't it be great if there was some kind of container, a repository, if you will, that would hold old versions of your code, and let you control it, so that you could pull that code back when you needed it again, instead of just commenting it out or writing a silly condition like that?

    Well, we can dream, I guess.
  • (cs) in reply to Dionysius Exiguus
    Anonymous:
    Anonymous:
    Maurits:

    "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?


    The last time a triple leap second occurred was on February 29 during the third full moon of the month on a Friday the 13th (which fell on Halloween that year), and this is not likely to occur again any time soon.  I remember it well; I was travelling by ship at the time and the ship had just crossed the international date line from west to east (in reverse), and a female passenger who was pregnant with twins had just given birth to the younger of her two children, and was about to give birth to his older brother....



    That was not particularly witty or humorous.
  • Kevin (unregistered) in reply to Ytram

    Actually a constructor can return null. For instance in C++ when you call "new Class();" you are actually making two calls, one to the constructor and the other to the "new" operator. If you disassemble the call you see that new actually calls malloc to allocate the memory required for the new instance of the class (read instance data members). And if for some reason you don't have enough memory left in your heap malloc will return null, which means the call to "new Class();" will also return null.

    Granted if you don't have enough memory left to allocate an object you probably have bigger problems like a memory leak. IMHO it's not only reasonable to check memory allocations for success in C++, it should be done as good programming practice to exit gracefully instead of crashing when you dereference a null pointer to a class and end up with "this == null" which can happen in a C++ environment, although it means you should have either initialized your variable, or checked your memory allocation.

    In C#/Java I'd imagine that if you are out of heap memory and the gc can't free up more it will also return null, otherwise it would be giving you a bad pointer to memory you don't own. I do believe those languages will throw exceptions if you dereference null so this cannot equal null. In C# reflection it definately throws an exception if you try and call a member method of a null class instance.

  • (cs) in reply to Kevin
    Anonymous:
    Actually a constructor can return null. For instance in C++ ....

    In C#/Java I'd imagine that if you are out of heap memory and the gc can't free up more it will also return null....


    In fact, in Java it will throw an OutOfMemoryError, and I assume C# does something similar, so you would not reach the code that checked for null.
  • (cs) in reply to Anonymous
    Anonymous:
    Maurits:
    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.


    Leap seconds are observed at 11:59:60 UTC, so it wouldn't be the ball in New York that we have to worry about, but the...uh...whatever they have in London.


    Generally everything is timed off the chimes of Big Ben.  Not that the drunken fun with fireworks in Trafalgar Square is often timed to the second, anyway...

Leave a comment on “The Friday Farrago ”

Log In or post as a guest

Replying to comment #:

« Return to Article