C++ to Java: A Lifestlye Change
- March 3rd, 2010
- Posted in Programming
- By netadptr0719
- Write comment
I have learned in the past couple weeks that I will become a Java developer. I have always had a disliking towards Java for various reasons. Since attempting to learn it though in a corporate environment I have found that it does have an awful lot to offer the business world. With that said there are a few features it lacks that I feel should really be a mainstay of any major programming language.
The biggest advantage I have found with Java is probably how easily it is ported across systems. In previous internships I worked with Visual C++ and the idea of it working on a possible Mac client were pretty much out of the question. Moving to Java though allows developers to focus less on cross compatibility and more on the true function and desired outcome of the program. While it is more flexible in cross compatibility it is also more flexible when looking at things such as internationalization. C/C++ were made ages ago and there wasn’t really much of a character encoding standard at the time. ASCII was really just about it and that really didn’t give companies any advantage when it came to foreign markets. Libraries and workarounds exist for this in C/C++ I know but since Java was made much more recently these standards are inbred into the language a little more making it a lot more accessible and easier to use. I also like the ease the transition from C/C++ to Java has been.
I have heard for some time now that people who have a background in C/C++ don’t have much of a problem transitioning to Java. I always though that this may have been people just trying to lure me over to the ‘dark side’. For the most part it has really been true, the syntax is almost identical, it is some of the logic that is throwing me off more than anything else. Even though it is causing me some trouble I must say that I am not coming at it from the other direction like a couple of my coworkers are. People who originally knew Java and are trying to move into the C++ realm are seeming to have a much harder time transitioning. A lot of it is stuff that I would consider trivial for the most part. When I stop and look at the differences in the two languages though it isn’t too shocking that someone who only knows Java is completely lost in a language like C++. The idea or using pointers or passing arguments as references is completely lost on some of these people. There have been several situations where someone has passed a class into a function, tries to change something, and it comes out completely untouched. I ask if they are passing by reference and they don’t even know what I am talking about. Something else surprising is some of the inheritance structures that these people are creating in C++. I guess I have taken for granted that C++ has multiple inheritance, something that Java ironically doesn’t have, I’ll get to that later. Some people have created classes that inherit through this giant tree of extends. This wouldn’t necessarily be bad but when you try to force something like this some of the relationships can become sketch at best.
Not having multiple inheritance may not seem like such a big deal but when you break down the foundations on which Java was built it truly seems to make pretty much no sense to me. It truly is ironic that a language built so heavily on the idea of OOP has no way to inherit multiple objects. While this may not be the death of the language it truly is something that I would expect from such a widely accepted and powerful language. Something else I find that Java is missing is a wide variety of primitive types. While Java has the basics: int, float, double, byte, char, boolean, and long, it doesn’t really have a way to expand on any of this. Java has eliminated SOME of this by creating the BigInteger() and BigDouble(). I don’t really find this to be a solution to my problem though because I am still awfully restricted. Initially looking at this list it may not seem too restricting, wait, there is more. Combining types or modifying types does not exist, that is to say I can’t made a long long, a long double, or anything of the sort. The one that really got me today was that there is no way to make a number unsigned inside of Java. This seems like a major oversight for any language that wants to gain any sort of major use and respectability. Sure I will probably not have a use for a number that goes all the way to 18,446,744,073,709,551,615 anytime soon but it still does take a huge chunk out of possible markets.
Despite the gripes about Java it truly is a pretty strong language. While its range of uses may not be as far reaching as some of the older lower level languages it really does pick up the slack in the ability to get something together and ship it out quickly among varying platforms. While efficiency may be lost there is a definite profit gain accomplished by using a language like Java over some of the other big names out there.
Another downside to no unsigned variables is that you cannot use that to implicitly restrict domain. Every time you have a value that must be greater than or equal to zero, you have to do a code check.
Other Missing Features:
Enums/Defines. Being able to rename something is quiet useful, especially when having a chain of “dot” operator commands. (IE object.subobject.itsfield.function() replaced with OSIF()).
Also, nice blog style change.
At first the lack of Enums didn’t really bother me because I didn’t use them often. What REALLY got me was the lack of defines. I used that so often to improve code readability. Not having this FORCES me to use Java’s version of enums. Yes, they have them if anyone wasn’t aware, but they are shit. They are basically a stub class with associated values…kinda. I I had something like public enum Status{GOOD, BAD} I could use those to determine if something returned GOOD if I explicitly told it to return something of type Status. There is no way to associate GOOD with say 0 and BAD with 1. It is just an arbitrary number that means practically nothing that I can not expand usability on.
Like you, I started with C/C++ and didn’t learn Java until recently. I had heard a lot of negative things about it, but it isn’t as bad as I expected. I don’t think I would choose it for any new projects, but working with it is okay, especially because of the good toolset: Eclipse is not to be underestimated.
The JVM is actually a hot place to be right now, just not with Java. You should see if work will let you use a trendier language, like Groovy: it compiles down to JVM bytecode, so it works everywhere regular Java does, but you get nice features like dynamic typing and real closures. Even if you don’t choose Groovy, there’s JRuby, Jython, Clojure, Scala, and probably more that I’m forgetting.
@Justin Voss
Java truly is good for interfaces and systems that require user interaction. This is why I did not completely bash the language. I have actually become quite surprised at how much I actually quite like it. More than anything it is the little things you would expect a language to have that are lacking. This is what makes me mad. I don’t think that it is really too much to ask for unsigned numbers or the ability to use enumerations.