Kllrnohj wrote:
The whole .Equals thing is one of the stupidest language decisions I have ever seen. They have an operator for .Equals, '==', and java should use it.
Why is it stupid? It makes perfect sense to me. The String is an object, and two objects can store the same data without taking up the same location in memory. In the past, I have used == on objects to ensure they are references to the same object, which is what it is there for. Would you prefer that == compares every field within two objects to make sure they are equal? That seems ridiculous to me: Suppose there is an object that has a minor field that causes two objects to differ, even though you expect them to be equal because the only field you care about is equal.
magicdanw wrote:
Why is it stupid? It makes perfect sense to me. The String is an object, and two objects can store the same data without taking up the same location in memory. In the past, I have used == on objects to ensure they are references to the same object, which is what it is there for. Would you prefer that == compares every field within two objects to make sure they are equal? That seems ridiculous to me: Suppose there is an object that has a minor field that causes two objects to differ, even though you expect them to be equal because the only field you care about is equal.


Lets take a String. String's only have one field that matters (that of the string itself). Since references are almost never equal, comparing references is just plain stupid - there isn't a reason to do it, especially since you aren't supposed to even know/care that it is a reference to begin with. As for your second question, that is where operator overloading comes in. It allows the class to decide what should determine if things are equal, and yes, this DOES make more sense than comparing references (a largely useless task). If you only care about one field, then only compare that field - that part is pretty simple. Generally == should compare ever piece of data that is user-settable in the class, that is the most logical use for it (it is, after all, the EQUALS operator - why should I have to call a function to test for EQUALITY when there is an EQUALS operator?)
Kllrnohj wrote:
foamy3 wrote:
Kllrnohj wrote:
In Java you would need multiple functions and/or casting/converting. In Python a simple "def addOne(num): return num + 1" would work in any case where <type> + 1 means something.


Not really. Generics in Java are cake. You just add <paramType> to the beginning of the function name when you call it. Typing out two brackets and one extra word isn't really going to slow you down...


Doesn't work (as far as I know). You would still need to cast or do something with the "+ 1" part - which is the entire point Wink And since Java doesn't let you overload operators (incredibly stupid), you couldn't even have a generic that implements an interface with + int defined. Which brings me to another point. The whole .Equals thing is one of the stupidest language decisions I have ever seen. They have an operator for .Equals, '==', and java should use it.



No, generics work just fine. Rolling Eyes I think they're called 'templates' or something in c++. I can't find my text book at the moment, but I must say I pwned my final pretty bad. They don't work with primitive data types (ie. int and char) but every primitive has a wrapper class (ie. Integer and Character). Java will automatically cast it for you into a wrapper. So instead of writing addInt(int i) and addDouble(double i), you can just write add(E i) and call it as <Integer>add(variableNameOfYourInt) or <Double>add(variableNameOfYourDouble). (The 'E' when writing the method is just a variable name used to store the data type being used.)

I agree about the operator overloading, though. I learned a little C++ in highschool and remember that not being too hard. That is definitely an epic fail for Java. But I'm pretty sure the wrapper classes automatically have '+' and '-' built in so I don't think it's a problem.
foamy3 wrote:
No, generics work just fine. Rolling Eyes I think they're called 'templates' or something in c++. I can't find my text book at the moment, but I must say I pwned my final pretty bad. They don't work with primitive data types (ie. int and char) but every primitive has a wrapper class (ie. Integer and Character). Java will automatically cast it for you into a wrapper. So instead of writing addInt(int i) and addDouble(double i), you can just write add(E i) and call it as <Integer>add(variableNameOfYourInt) or <Double>add(variableNameOfYourDouble). (The 'E' when writing the method is just a variable name used to store the data type being used.)

I agree about the operator overloading, though. I learned a little C++ in highschool and remember that not being too hard. That is definitely an epic fail for Java. But I'm pretty sure the wrapper classes automatically have '+' and '-' built in so I don't think it's a problem.


No, I mean you can't use addition or the int constant (1 in this case) with generics in the method I described. You would have to have a generic that implemented an interface where .add(int) was implemented, which ultimately is a long, roundabout way of doing what the python script does only not as well, since it won't necessarily work with built in types.

Oh, and C++ templates != Java generics. C++ templates are actually useful Razz (templates don't require the caller to do anything special - which is the way it should be)
I've never used C++ templates, so my bad for bringing them up. Smile That's just what I was told.

And I guess in the break from Cemetech I took, I forgot the #1 rule. Never argue with Kllrnohj. He knows too much. Smile

And now for the n00bly mandatory "Okay, you win, but let me slightly change the topic to not look stupid" post:

Okay, there are a few instances where that kind of thing comes up, but still, Java has solid ways of getting it done. You may be adding a few more seemingly useless things to each line, but it won't significantly effect you negatively. It's not like you have to think about how to get it done. It will still come to you second-nature once you're comfortable with the language.

EDIT:

P.S. What happened to the word count tally? That was always fun to check words/post ratios.
foamy3 wrote:
Okay, there are a few instances where that kind of thing comes up, but still, Java has solid ways of getting it done. You may be adding a few more seemingly useless things to each line, but it won't significantly effect you negatively. It's not like you have to think about how to get it done. It will still come to you second-nature once you're comfortable with the language.


But that is one of the fundamental problems with Java - you have to type too much bullshit to get things done. Almost everything is like that in Java, and its a pain in the butt. I can't stand it. I hate having to type/do more work than I have to, and the entire point of a high level language (lets face it, Java is supposed to be high level) is to PREVENT that. This is one of the major problems with Java. It is implemented like it should be high level (garbage collection, byte compiled, etc...), yet it requires code similar to that of a lower level language (but without the bonus of speed). Java's obsession with XML is also stupid, but that isn't really a language problem, just a "Java devs are morons" problem Wink

Quote:
P.S. What happened to the word count tally? That was always fun to check words/post ratios.


Its in your profile Smile (you have 62.5k words with 42.82 words/post, I have 280.9k words with 51.3 words/post, w00t)
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement