• (cs)

    "lastName.<font color="#0000ff">charAt</font>(0) == <font color="#0000ff">new String</font>(<font color="#ff0000">"*"</font>).<font color="#0000ff">charAt</font>(0)"
    Hey, whatever works right!

  • (cs)
    Alex Papadimoulis:
      <font color="#0000ff">int</font> getHttpPort() <font color="#0000ff">throws IllegalArgumentException</font> {
    <font color="#008000"> /// and which is the illegal argument?</font> } <font color="#a52a2a"></font>



    That one is my fav. What's funny is due to some other method that's called within this one, the compiler probably forces him to put that throw statement there since he didn't handle it within this method. That's assuming the method's body isn't just a comment (:
  • (cs)

    This is got to be in the top 5 list of worst/funniest things I have ever seen on this site, or any site for that matter.  You almost have write crap like that on purpose.

  • (cs) in reply to Sweets

    Sweets:
    "lastName.<FONT color=#0000ff>charAt</FONT>(0) == <FONT color=#0000ff>new String</FONT>(<FONT color=#ff0000>"*"</FONT>).<FONT color=#0000ff>charAt</FONT>(0)"
    Hey, whatever works right!

    Unless timeliness is important.

  • (cs) in reply to SurfaceTension
    SurfaceTension:
    [image] Alex Papadimoulis wrote:
      <FONT color=#0000ff>int</FONT> getHttpPort() <FONT color=#0000ff>throws IllegalArgumentException</FONT> {
    <FONT color=#008000> /// and which is the illegal argument?</FONT> } <FONT color=#a52a2a></FONT>



    That one is my fav. What's funny is due to some other method that's called within this one, the compiler probably forces him to put that throw statement there since he didn't handle it within this method. That's assuming the method's body isn't just a comment (:

    Java will not let you throw in superfluous 'throws'.

  • (unregistered)
    Alex Papadimoulis:

     <FONT color=#0000ff>publi</FONT>c horribleBreakingLoops() {
      <FONT color=#0000ff>try</FONT> {
       <FONT color=#0000ff>for</FONT> (<FONT color=#0000ff>int</FONT> i = 0; i < 100; i++) {
        <FONT color=#0000ff>if</FONT> (i == 98) {
         <FONT color=#008000>// Yes, java does have 'break' to exit loops</FONT>
         <FONT color=#0000ff>throw new Exception</FONT>();
        }
       }
      } <FONT color=#0000ff>catch</FONT> (<FONT color=#0000ff>Exception</FONT> e) {}
    }
     
    <FONT color=#0000ff>protected int</FONT> myHorrorIndex = <FONT color=#0000ff>new Integer</FONT>(<FONT color=#ff0000>"1"</FONT>).<FONT color=#0000ff>intValue</FONT>();

    Those two are quality [:)]

    I do have a concern that this is real production code - I mean, where's the usual horde of wrappers and interfaces that seem almost a compiler requirement for Java code? [:)]

  • (cs)

    <FONT color=#0000ff>"protected int</FONT> myHorrorIndex = <FONT color=#0000ff>new Integer</FONT>(<FONT color=#ff0000>"1"</FONT>).<FONT color=#0000ff>intValue</FONT>();"

    Why?!!

    ... No, really, why?

    Did this guy have some vendetta against his employer and coworkers when he wrote this? Does he just hate java, Is he out to prove that java is a useless language, does he know something we don't about the simple statement:

    protected int myHorrorIndex = 1;

    As in, the statement I just wrote is horribly inefficient and could cause the world to collapse in on itself.

    Was he smoking a good deal of crack when he wrote that? It just doesn't seem like inexperience, it seems more drug-induced.

  • (unregistered) in reply to SurfaceTension
    SurfaceTension:

    That one is my fav. What's funny is due to some other method that's called within this one, the compiler probably forces him to put that throw statement there since he didn't handle it within this method.


    IllegalArgumentException is a subclass of RuntimeException.  The compiler does not force you to explicitly handle RuntimeExceptions like it does for all other types of exceptions.  It's essentially an unchecked exception in a kludgy way.
  • (cs)

    <FONT style="BACKGROUND-COLOR: #efefef">Great post, excellent stuff.  Best we've had in a while.</FONT>

    I, too, am a huge fan of:

    <FONT color=#0000ff>protected int</FONT> myHorrorIndex = <FONT color=#0000ff>new Integer</FONT>(<FONT color=#ff0000>"1"</FONT>).<FONT color=#0000ff>intValue</FONT>();

    That's a classic!

  • (cs) in reply to Jeff S

    This one is my favourite for sheer demonstration that he doesn't have a clue about any of the language features.

    [code language="c#"]
    <font color="#0000ff">public boolean</font> compareObjects(<font color="#0000ff">Object</font> obj1 , <font color="#0000ff">Object</font> obj2) {
    <font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>)
    <font color="#0000ff">return true<font color="#000000">;</font>
    else
    return false</font>;
    }
    [/code]

  • (cs)

    I agree

    <FONT color=#0000ff>protected int</FONT> myHorrorIndex = <FONT color=#0000ff>new Integer</FONT>(<FONT color=#ff0000>"1"</FONT>).<FONT color=#0000ff>intValue</FONT>();

    is the best one...it takes the idea of OOP to another level...."I can't just assign the number 1 to this integer variable, I need to construct a number 1 object, using a string, and then assign it! brilliant!" [H]

  • (unregistered)

    To me, the real winner here is checkIsNull.  Prevent your code from throwing NullPointerExceptions by trying to call the equals() method of the possibly-null object, thereby throwing the NullPointerException preemptively!  If that's actually the behavior they want, they could have just left off the if.

  • (unregistered) in reply to skicow

    <FONT color=#0000ff>protected int</FONT> myHorrorIndex = <FONT color=#0000ff>new Integer</FONT>(<FONT color=#ff0000>"1"</FONT>).<FONT color=#0000ff>intValue</FONT>();

    To understand this you have to know something about how java works under the hood.  You see, in Java, everything is represented as a string at the lowest level, so if you said myHorrorIndex = 1 it would have to convert it into a string before casting it to an int.  Casting can be a very expensive operation in terms of performance, so your best bet is to start with a string and use the intValue method to return an int directly like the author of this code did.  I think I saw an article on this once but I can't find it now.

  • (cs) in reply to
    To understand this you have to know something about how java works under the hood.  You see, in Java, everything is represented as a string at the lowest level

    Yes . . . a string of ones and zeros.  [*-)]
  • (unregistered)
    <font color="#0000ff">if</font>( !a.<font color="#0000ff">equals</font>(<font color="#0000ff">null</font>) ) {
    Won't this NPE if <font face="Courier New">a</font> is null, thereby totally defeating the purpose?
  • (cs) in reply to

    :
    <FONT color=#0000ff>protected int</FONT> myHorrorIndex = <FONT color=#0000ff>new Integer</FONT>(<FONT color=#ff0000>"1"</FONT>).<FONT color=#0000ff>intValue</FONT>();

    To understand this you have to know something about how java works under the hood.  You see, in Java, everything is represented as a string at the lowest level, so if you said myHorrorIndex = 1 it would have to convert it into a string before casting it to an int.  Casting can be a very expensive operation in terms of performance, so your best bet is to start with a string and use the intValue method to return an int directly like the author of this code did.  I think I saw an article on this once but I can't find it now.

    Maybe in javascript that is true. Maybe.

    I will not tolerate any more VB programmer comments after this.

  • (cs) in reply to znaps
    znaps:

    This one is my favourite for sheer demonstration that he doesn't have a clue about any of the language features.


    <FONT face="Lucida Console, Courier" size=2>
    <FONT color=#0000ff>public boolean</FONT> compareObjects(<FONT color=#0000ff>Object</FONT> obj1 , <FONT color=#0000ff>Object</FONT> obj2) {
    <FONT color=#0000ff>if</FONT> (obj1.<FONT color=#0000ff>equals</FONT>(obj2) == <FONT color=#0000ff>true</FONT>)
    <FONT color=#0000ff>return true<FONT color=#000000>;</FONT>
    else
    return false</FONT>;
    }
    </FONT>
     

    This is my favorite just because of the absolute ignorance of basic programming concepts displayed.

    1) Right off the bat you don't even need this function because it is exactly what the equals function does.

    2) Ok, bad enough he wrote a function for it but they didn't even just return the value of the equals function. Nope, gotta write an if statement around it to check the value.

    3) Ok, bad enough he used an if statement to check which boolean value to return but the coder has to check the return value of the equals function within the condition of the if statement itself.

    I've never seen more idiotic code.

  • (unregistered)

    Say it ain't so, say it ain't so! [:'(]

  • (cs)

    <FONT size=2><FONT face="Lucida Console"><FONT color=#0000ff>if</FONT> (obj1.<FONT color=#0000ff>equals</FONT>(obj2) == <FONT color=#0000ff>true</FONT>)
    </FONT></FONT><FONT size=2><FONT face="Lucida Console"><FONT color=#0000ff>   return true<FONT color=#000000>;</FONT>
    </FONT></FONT></FONT><FONT face=Arial></FONT>

    <FONT face=Arial>Whoa... how can he be sure that <FONT face=Verdana color=#0000ff>true</FONT> is necessarily true? Shouldn't it be:</FONT>

    <FONT size=2><FONT face="Lucida Console"><FONT color=#0000ff>if</FONT> (obj1.<FONT color=#0000ff>equals</FONT>(obj2) == <FONT color=#0000ff>true</FONT>) </FONT></FONT>
    <FONT face="Lucida Console" size=2>   <FONT color=#0000ff>if</FONT> (<FONT color=#0000ff>true</FONT> == <FONT color=#0000ff>true</FONT>) </FONT>
    <FONT size=2><FONT face="Lucida Console"><FONT color=#0000ff>      return true<FONT color=#000000>;</FONT>
    </FONT></FONT></FONT>

    <FONT face=Arial>--RA</FONT>

  • (unregistered)

    It almost looks like he read these guidelines and followed them...

  • (cs)

    NYARRRRGGHHHH!!! The pain! The pain!

    Wow... I never thought I'd get real bad headaches by reading crappy source code. Thanks for showing me it's possible.

  • (cs) in reply to

    You better be joking.

    :
    <font color="#0000ff">protected int</font> myHorrorIndex = <font color="#0000ff">new Integer</font>(<font color="#ff0000">"1"</font>).<font color="#0000ff">intValue</font>();

    To understand this you have to know something about how java works under the hood.  You see, in Java, everything is represented as a string at the lowest level, so if you said myHorrorIndex = 1 it would have to convert it into a string before casting it to an int.  Casting can be a very expensive operation in terms of performance, so your best bet is to start with a string and use the intValue method to return an int directly like the author of this code did.  I think I saw an article on this once but I can't find it now.
    <script src="chrome://greasemonkey/content/scripts/1102161148673"></script><script src="chrome://greasemonkey/content/scripts/1102237157909"></script>
  • (cs) in reply to

    :
    It almost looks like he read these guidelines and followed them...

    GREAT link ! [Y]  (now THAT's a good anonymous post )

  • (cs) in reply to Rank Amateur
    Rank Amateur:

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>)
    </font></font><font size="2"><font face="Lucida Console"><font color="#0000ff">   return true<font color="#000000">;</font>
    </font></font></font><font face="Arial"></font>

    <font face="Arial">Whoa... how can he be sure that <font color="#0000ff" face="Verdana">true</font> is necessarily true? Shouldn't it be:</font>

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>) </font></font>
    <font face="Lucida Console" size="2">   <font color="#0000ff">if</font> (<font color="#0000ff">true</font> == <font color="#0000ff">true</font>) </font>
    <font size="2"><font face="Lucida Console"><font color="#0000ff">      return true<font color="#000000">;</font>
    </font></font></font>

    <font face="Arial">--RA</font>



    Rank Amateur:

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>)
    </font></font><font size="2"><font face="Lucida Console"><font color="#0000ff">   return true<font color="#000000">;</font>
    </font></font></font>

    <font face="Arial">Whoa... how can he be sure that <font color="#0000ff" face="Verdana">true</font> is necessarily true? Shouldn't it be:</font>

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>) </font></font>
    <font face="Lucida Console" size="2">   <font color="#0000ff">if</font> (<font color="#0000ff">true</font> == <font color="#0000ff">true</font>) </font>
    <font size="2"><font face="Lucida Console"><font color="#0000ff">      return true<font color="#000000">;</font>
    </font></font></font>

    <font face="Arial">--RA</font>



    Personally, I think the following would have been a lot more prudent...

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font> && obj2.<font color="#0000ff">equals</font>(obj1) == <font color="#0000ff">true</font>)</font></font>
    <font size="2"><font face="Lucida Console"><font color="#0000ff">      return true<font color="#000000">;</font>
    </font></font></font>


    ...or maybe even...

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font> && obj2.<font color="#0000ff">equals</font>(obj1) == <font color="#0000ff">true</font> && <font color="#0000ff">true</font> == <font color="#0000ff">true</font> && <font color="#0000ff">true</font> != <font color="#0000ff">false</font>)</font></font>
    <font size="2"><font face="Lucida Console"><font color="#0000ff">      return <font color="#000000"><font color="#0000ff">true</font>;</font>
    </font></font></font>


    You can never be too careful, particularly when it comes to your definition of "equivalency".
  • (cs) in reply to BACON

    Wow, and apparently you can never be too careful while using the "copy" command.

    For those wondering, I quoted that text twice as a failsafe in case one of them got corrupted in transit.  Remember, always keep a backup copy.

  • (cs)

    wow, some great stuff in there. However...

    bjmarte and drgonzo, you both get a metaphorical kick in the shin for having no sense of sarcasm. I don't understand how anyone could've missed that that comment was a joke.

  • (cs) in reply to Irrelevant
    Hm.. could this be code from a kindergarten's "Java Programming 101" assignment?
    Hope so ;)
  • (cs)

    Actually my favorite would have to be:

    <FONT color=#0000ff>
    [code language="javascript"]<FONT color=#0000ff>public long</FONT> fearOfCastingHorror() {
      <FONT color=#0000ff>return System.currentTimeMillis</FONT>() + <FONT color=#0000ff>new Double</FONT>(<FONT color=#0000ff>Math.random</FONT>()).<FONT color=#0000ff>longValue</FONT>();
      <FONT color=#008000>//instead of return System.currentTimeMillis() + (long)Math.random();</FONT>
    }[/code]

    </FONT><FONT>Forget all the stuff about casting Doubles to longs.  </FONT><FONT>You do realise that Math.random() returns a value between 0 and 1?  ie 0 <= Math.random() < 1.  </FONT>

    Given this little bit of knowledge, plus the fact that java converts to long by discarding the decimal portion, the result of (long)Math.random() will always be 0.

    In otherwords, that whole Math.random thing is a NO-OP.  They might just as well have returned the System.currentTimeMillis()

    WTF?
    evnafets

  • (cs)

    <FONT style="BACKGROUND-COLOR: #efefef">All classics ;)</FONT>

    My flatmate was reviewing and tidying code at work. He didnt have the heart to fix the various gems of:

    if(o.GetType().Equals("".GetType())) ...

    It was changed to:

    if(o.GetType().Equals("What idiot wrote this?".GetType())) ...

    Changes submitted.... :P

  • (cs) in reply to Irrelevant

    Irrelevant:
    wow, some great stuff in there. However...

    bjmarte and drgonzo, you both get a metaphorical kick in the shin for having no sense of sarcasm. I don't understand how anyone could've missed that that comment was a joke.

    Sorry, I don't think there is anything in your post to make it obvious that you were joking and I don't hang out here enough to know anything about you.  There are some pretty dumb comments sometimes.

  • (cs) in reply to Rank Amateur
    Rank Amateur:

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>)
    </font></font><font size="2"><font face="Lucida Console"><font color="#0000ff">   return true<font color="#000000">;</font>
    </font></font></font><font face="Arial"></font>

    <font face="Arial">Whoa... how can he be sure that <font color="#0000ff" face="Verdana">true</font> is necessarily true? Shouldn't it be:</font>

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>) </font></font>
    <font face="Lucida Console" size="2">   <font color="#0000ff">if</font> (<font color="#0000ff">true</font> == <font color="#0000ff">true</font>) </font>
    <font size="2"><font face="Lucida Console"><font color="#0000ff">      return true<font color="#000000">;</font>
    </font></font></font>

    <font face="Arial">--RA</font>



    No no no! It has to be

    <font size="2"><font face="Lucida Console"><font color="#0000ff">if</font> (obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>){
        return true;
    }
    else {
        return true2;
    }

    Hehehe.
    </font></font>
  • (cs)

    Wow... I'm an experianced Java guy, and I've seen some yucky code... but that is some of the worse I've seen.

    Have you set up a "wall of shame" in your office yet?

  • (cs) in reply to SurfaceTension
    SurfaceTension:
    Alex Papadimoulis:
      <font color="#0000ff">int</font> getHttpPort() <font color="#0000ff">throws IllegalArgumentException</font> {
    <font color="#008000"> /// and which is the illegal argument?</font> } <font color="#a52a2a"></font>



    That one is my fav. What's funny is due to some other method that's called within this one, the compiler probably forces him to put that throw statement there since he didn't handle it within this method. That's assuming the method's body isn't just a comment (:


    Actually <font color="#0000ff">IllegalArgumentException is a runtime exception and doesn't need to be caught... so no, the fellow just didn't have a clue.

    </font> 
  • (cs)

    Surely this is for some class ore something.
    A nice example for the students how they can fail? [:|]

  • Lorenzo Gatti (unregistered)

    I'm in the minority that prefers the more subtly stupid

    <font color="#0000ff">public stringsHorror</font>(<font color="#0000ff">String</font> lastName) {
    <font color="#0000ff">if</font> (lastName.<font color="#0000ff">charAt</font>(0) == <font color="#0000ff">new String</font>(<font color="#ff0000">""</font>).<font color="#0000ff">charAt</font>(0)
    || lastName.<font color="#0000ff">charAt</font>(0) == <font color="#0000ff">new String</font>(<font color="#ff0000">"%"</font>).<font color="#0000ff">charAt</font>(0)) {
    <font color="#008000">// here goes the code ;)
    </font> }
    }

    because it has a number of possible compactions, from normal

    char c=lastName.<font color="#0000ff">charAt</font>(0);
    if (c=='
    '||c=='%'){
    //...
    }
    to "clever"
    if ("*%".indexOf(lastName.<font color="#0000ff">charAt</font>(0))>=0){
    //...
    }

    <script src="chrome://greasemonkey/content/scripts/1102161148673"></script><script src="chrome://greasemonkey/content/scripts/1102237157909"></script>
  • Anonymous (unregistered)

    He's actually a genius. Such a genius, that he's written a genetic algorithm to write his programs.

    The next few million iterations and it'll be better. Honest.

    That, or a helper monkey.

  • (cs) in reply to bjmarte
    bjmarte:

    :
    <FONT color=#0000ff>protected int</FONT> myHorrorIndex = <FONT color=#0000ff>new Integer</FONT>(<FONT color=#ff0000>"1"</FONT>).<FONT color=#0000ff>intValue</FONT>();

    To understand this you have to know something about how java works under the hood.  You see, in Java, everything is represented as a string at the lowest level, so if you said myHorrorIndex = 1 it would have to convert it into a string before casting it to an int.  Casting can be a very expensive operation in terms of performance, so your best bet is to start with a string and use the intValue method to return an int directly like the author of this code did.  I think I saw an article on this once but I can't find it now.

    Maybe in javascript that is true. Maybe.

    I will not tolerate any more VB programmer comments after this.

    I'm not a java guy, but even if what he said IS true, he would have to recognize that the "1" in the statement above IS a string, so it would have to be parsed.  So this statement is doing the very thing that he claims it is intended to avoid.

    Troll: 75%; Poor attempt at humor: 20%; Serious: 5%

  • withheld (unregistered) in reply to znaps

    I'm afraid to have to report that some of the senior level developers at my 
    current employer would reject the compareObjects method on code review, as it
    violates the single entry/single exit principle. The "corrected" form would
    be:

    /*
    * Compares two objects and returns true if they are equal or false if they
     
    are not

    * @returns true if the two arguments are equal or false if they are not
     
    /

    <font color="#0000ff">public boolean</font> compareObjects(<font color="#0000ff"> Object</font> obj1 , <font color="#0000ff">Object</font> obj2 )
    {
    // initialize the return value
    boolean bReturnValue = false;

    // compare the two objects
    <font color="#0000ff"> if</font>( obj1.<font color="#0000ff">equals</font>(obj2) == <font color="#0000ff">true</font>)
    {
    // The test passed: set the return value to true
    bReturnValue =<font color="#0000ff"> true<font color="#000000">;
    }
    </font> else
    {
    // The test failed: set the return value to false
    return false</font>;
    }

    // return the result
    return( bReturnValue );
    }

  • (cs)
    Alex Papadimoulis:

     <FONT color=#0000ff>public boolean</FONT> compareObjects(<FONT color=#0000ff>Object</FONT> obj1 , <FONT color=#0000ff>Object</FONT> obj2) {
      <FONT color=#0000ff>if</FONT> (obj1.<FONT color=#0000ff>equals</FONT>(obj2) == <FONT color=#0000ff>true</FONT>)
       <FONT color=#0000ff>return true<FONT color=#000000>;</FONT>
      else
       return false</FONT>;
    }

    This one is my favorite.  If he had just condensed it down to "return obj1.equals(obj2);" he might have recognized the uselessness of the function.

  • Stephan Rose (unregistered)

    For those of you who doubt that this may be production code, I have sad and breaking news for you. It is!!!

    I used to have a co-worker, used to be a java programmer, and he was supposed to help me with a C# project I was working on. I promise you, this guy comitted EVERY SINGLE one of those atrocities up there, and then some!

    Here's some of my favorites...

    float value1 = 1.0f;
    double value2 = double.Parse(value1.ToString());

    --

    OneOfMyControls instance1 = new OneOfMyControls();

    instance1.Propery = someValue;

    // Later in the code 5 source files later in a totally unrelated class

    OneOfMyControls instance2 = new OneOfMyControls();

    variable = instance2.Propery;

    // Next, I get an e-mail stating the control I had written for him to use does not work, when he assigns a value to the property, the property does not get assigned. Yes, I did bang my head on the desk.

    This is just the start....

     

  • Vasil (unregistered) in reply to mugs
    mugs:
    bjmarte:

    :
    <font color="#0000ff">protected int</font> myHorrorIndex = <font color="#0000ff">new Integer</font>(<font color="#ff0000">"1"</font>).<font color="#0000ff">intValue</font>();

    To understand this you have to know something about how java works under the hood.  You see, in Java, everything is represented as a string at the lowest level, so if you said myHorrorIndex = 1 it would have to convert it into a string before casting it to an int.  Casting can be a very expensive operation in terms of performance, so your best bet is to start with a string and use the intValue method to return an int directly like the author of this code did.  I think I saw an article on this once but I can't find it now.

    Maybe in javascript that is true. Maybe.

    I will not tolerate any more VB programmer comments after this.

    I'm not a java guy, but even if what he said IS true, he would have to recognize that the "1" in the statement above IS a string, so it would have to be parsed.  So this statement is doing the very thing that he claims it is intended to avoid.

    Troll: 75%; Poor attempt at humor: 20%; Serious: 5%



    Well... I'm a Java programmer and will say that this is definetely NOT true.

    int literals are stored in the java class file constant pool and are read as ints and not as strings while loading the class file.

    So there IS a difference between:

    <font>protected int</font> myHorrorIndex = <font>new Integer</font>(<font>"1"</font>).<font>intValue</font>();
    and
    <font>protected int</font> myHorrorIndex = 1;

    One possible reasons for this ... nuisance (besides the lack of ... experience of the developer :)) :

    The guy may use some decompiled code. As most of the java developers know - constants are directly inlined in class files at compile time. So if the original code was:

    protected int myHorrorIndex = new Integer(ConstantHolder.CONSTANT_1).intValue();

    and CONSTANT_1 was a String equal to "1" then at decompile time we'll have the 'horror' line :)


    This reminds me of a common error that Java newbies make:
    Like I wrote - constants are inlined in class files at compile time. So if you change a constant holder then you MUST recompile all classes that reference the changed constant. Several years ago I had a colleague who lost several hours wondering why his changed constant does not change the application behavior - he just didn't care to recompile the whole project but only the constant holder :).


  • (cs) in reply to Jeff S

    <font color="#0000ff">protected int</font> myHorrorIndex = <font color="#0000ff">new Integer</font>(<font color="#ff0000">"1"</font>).<font color="#0000ff">intValue</font>();

    I am pretending that was actually automatically generated by some horribly disfigured tool, but on the plus side knowing that people code like this does keep my future bright.

  • Mad Hatter (unregistered) in reply to Stephan Rose
    Anonymous:
    OneOfMyControls instance1 = new OneOfMyControls();

    instance1.Propery = someValue;

    // Later in the code 5 source files later in a totally unrelated class

    OneOfMyControls instance2 = new OneOfMyControls();

    variable = instance2.Propery;

    // Next, I get an e-mail stating the control I had written for him to use does not work, when he assigns a value to the property, the property does not get assigned. Yes, I did bang my head on the desk.

    This is just the start....


    That's bad object design anyway. You should stay far away from having public fields in your classes. Who knows what code may get a reference to the object and change the field without permission.

  • th c# reader (unregistered) in reply to Mad Hatter

    It's not a public field, it's a PROPERTY. He said it's C#, not Java.

  • th c# reader (unregistered) in reply to Mad Hatter
    Anonymous:
    Anonymous:
    OneOfMyControls instance1 = new OneOfMyControls();

    instance1.Propery = someValue;

    // Later in the code 5 source files later in a totally unrelated class

    OneOfMyControls instance2 = new OneOfMyControls();

    variable = instance2.Propery;

    // Next, I get an e-mail stating the control I had written for him to use does not work, when he assigns a value to the property, the property does not get assigned. Yes, I did bang my head on the desk.

    This is just the start....


    That's bad object design anyway. You should stay far away from having public fields in your classes. Who knows what code may get a reference to the object and change the field without permission.


    It's not a public field, it's a PROPERTY. He said it's C#, not Java.

  • (cs) in reply to Mad Hatter
    Anonymous:
    Anonymous:
    OneOfMyControls instance1 = new OneOfMyControls();

    instance1.Propery = someValue;

    // Later in the code 5 source files later in a totally unrelated class

    OneOfMyControls instance2 = new OneOfMyControls();

    variable = instance2.Propery;

    // Next, I get an e-mail stating the control I had written for him to use does not work, when he assigns a value to the property, the property does not get assigned. Yes, I did bang my head on the desk.

    This is just the start....


    That's bad object design anyway. You should stay far away from having public fields in your classes. Who knows what code may get a reference to the object and change the field without permission.



    You've just done Java 101 haven't you? You've just quoted page 2! ;-)

    It's C# code, so doesn't expose the feild itself. The property's accessor and mutator (get / set) are used like:

    public string Foo {
    get {
    return foo;
    }

    set {
    foo = value;
    }
    }
  • completely irrelevant (unregistered) in reply to Irrelevant
    Irrelevant:
    wow, some great stuff in there. However...

    bjmarte and drgonzo, you both get a metaphorical kick in the shin for having no sense of sarcasm. I don't understand how anyone could've missed that that comment was a joke.


    Really.  Sounds to me like you're trying to save face after blowing your cover as a Java programmer...
  • Koumynyka (unregistered) in reply to Rick

    It is not 'superfluous' ;) It is RuntimeException and the Jaca compiler always allows to declare a runtime exception even if you don't throw it. (although that you would normally never declare that a runtime exception is thrown, except in the javadoc)

    However, the funniest thing is that the whole code really returns just an int, whithout doing any additional computations. Just the int!




  • (cs)

    What do you think of this piece of code:

    <FONT face="Courier New">...</FONT>

    <FONT face="Courier New">hashTable.put(Integer.toString(key.hashCode()), object);</FONT>

    <FONT face="Courier New">...</FONT>

  • (cs) in reply to ananke
    ananke:

    What do you think of this piece of code:

    <FONT face="Courier New">...</FONT>

    <FONT face="Courier New">hashTable.put(Integer.toString(key.hashCode()), object);</FONT>

    <FONT face="Courier New">...</FONT>

    It's stupid.

Leave a comment on “Friday Java Jumble”

Log In or post as a guest

Replying to comment #31362:

« Return to Article