Tuesday 3 July 2012

Equals or ==?

So Android is pretty ubiquitous now. New tablets/phones coming out with the version 4 upgrades and awesomeness. I personally love my Android phone. No, it's not expensive, but I love it!

However, this is where I get to moan. I have never really touched Java before Android came out. Some people swear by it, I swear at it! It's not that Java is an aweful language, in fact there are some really nice features. However, from a C# point of view it is somewhat like learning Polish after learning Russian.

You see the slavic languages are very similar. The have a similar verb conjugation and many similar verbs, and then you get to the important bit, the verb that is the difference between like and love and it lets you down and changes. (Russian love transliterated is "lubit" in Polish lubic is to like).

The same thing happened with Java. I'm feeling confidant in the fact that I can write code without looking up syntax just because it's SO similar to C#. So much so that when i evaluated two variables with a

     if(var1 == var2) { // Do Something... }

statement, saw in debugging that they had the same value I expected that the // Do Something... code would run. WRONG! Turns out that the == in Java is COMPLETELY different to C#!

"EEEJIT!" you say. "Java is a better and older language than C#"

"No need to be rude!" Say I "C/C++ is an even older an more widely known langauge than even Java"

So how do we get around this evilness? Why does this happen?

Java-Samples states : "the equals( ) method compares the characters inside a String object. The == operator compares two object references to see whether they refer to the same instance"

So the equals() method was what I needed. Tbh I had not been so dissapointed by a language inconsistancy since the lack of switch in python. I look forward to comments and suggestions (clean ones please) about what I'm missing in Java that makes it better than either C# and/or Python. 

No comments:

Post a Comment