- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
"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!
Admin
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 (:
Admin
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.
Admin
Unless timeliness is important.
Admin
Java will not let you throw in superfluous 'throws'.
Admin
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? [:)]
Admin
<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.
Admin
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.
Admin
<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!
Admin
This one is my favourite for sheer demonstration that he doesn't have a clue about any of the language features.
Admin
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]
Admin
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.
Admin
<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.
Admin
Yes . . . a string of ones and zeros. [*-)]
Admin
Admin
Maybe in javascript that is true. Maybe.
I will not tolerate any more VB programmer comments after this.
Admin
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.
Admin
Say it ain't so, say it ain't so! [:'(]
Admin
<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>
Admin
It almost looks like he read these guidelines and followed them...
Admin
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.
Admin
You better be joking.
<script src="chrome://greasemonkey/content/scripts/1102161148673"></script><script src="chrome://greasemonkey/content/scripts/1102237157909"></script>Admin
GREAT link ! [Y] (now THAT's a good anonymous post )
Admin
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".
Admin
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.
Admin
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.
Admin
Admin
Actually my favorite would have to be:
<FONT color=#0000ff></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
Admin
<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
Admin
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.
Admin
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>
Admin
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?
Admin
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>
Admin
Surely this is for some class ore something.
A nice example for the students how they can fail? [:|]
Admin
I'm in the minority that prefers the more subtly stupid
to "clever"<script src="chrome://greasemonkey/content/scripts/1102161148673"></script><script src="chrome://greasemonkey/content/scripts/1102237157909"></script>
Admin
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.
Admin
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%
Admin
Admin
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.
Admin
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....
Admin
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 :).
Admin
<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.
Admin
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.
Admin
It's not a public field, it's a PROPERTY. He said it's C#, not Java.
Admin
It's not a public field, it's a PROPERTY. He said it's C#, not Java.
Admin
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:
Admin
Really. Sounds to me like you're trying to save face after blowing your cover as a Java programmer...
Admin
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!
Admin
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>
Admin
It's stupid.