Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Java cs C++
|
Posted: Sep 26, 2003 6:46 PM
|
|
> Freedom: See above. Developing in java leaves your future > desisions a little more open. I work in government and > our ms windows system has been rocked by virus' over the > last few months.
I think you are just talking about portability again. If portability is important, then Java is clearly superior to C++. (Borland just announced "Borland C++ Builder X" which is a multi-platform C++ development tool, but I haven't tried it out yet...)
Also, I think when deciding on C++, it is pretty important what tools/platform you choose. For example, most people on the Windows platform opt for writing MFC applications with Microsoft's Visual C++, without much thought or rationale other than the fact that it's Microsoft's compiler and tools on their operating system (so it must be the best choice, right?). Even though I've always done development mainly on the Windows platform, I've always preferred Borland's tools and only used MFC/Visual C++ when necessary (which, unfortunately is all too often -- like whenever I don't get to choose what the will be!).
> When looking for alternatives, management > was astounded that linux was immune to the onslaught.
Keep in mind that Linux isn't really immune, it is just not as ubiquitous on the desktop and so is not as big, easy and fun a target is is Windows for virus authors.
> Productivity: I like c++ but I find that things go much more > easily in java. Most c++ advocates will usually point to > best practices that will increase productivity but that > is a workaround. There's less chance of screwing up in java.
This is probably subjective and is certainly dependent on the task. For many things, especially networking-related, I think Java is much better.
For doing a GUI app, I think I could do the UI part with Borland C++ Builder on Windows in a fraction of the time that I could it in Java. Maybe that's just because I have so much more experience doing that with BCB than with Java. Additionally, there are platform-dependent GUI things that are just impossible to do with Java (short of JNI). I still love C++ Builder, but now that I've gotten my feet wet with C#, it will probably unseat C++ as my prefered Windows GUI development tool within the next couple years. For writing the "guts" behind the UI, I think both Java and C# are superior to C++.
I think it is irresponsible these days to choose to develop the main portion of your application in C++. There is just too much time lost with drudgery, house-keeping and managing complexity.
> Elegance: I just find that java is a nice improvement on > c++ (which i used before java). People like templates > alot in c++ but I have to believe that they are a work > around. Java has a more complete object hierarchy > starting with object. Primitives have wrappers. (Integer, > Character > etc.)
Hmmm... I'd say just the opposite on these things. Templates are one of the nice things about C++ and something that is scheduled to be added to Java. The only thing they "work around" is the static type system. If you don't like that, then there are some pretty nice dynamically-typed languages to choose from (Python, Ruby, ...).
Wrappers for primitives is one of Java's warts, if you ask me. It would be much nicer if primitives were objects in the first place. I think the only reason they aren't is performance. Wrappers for primitives is a work-around for the fact that they aren't objects. I think automatic boxing and unboxing is also a scheduled addition to Java, to ameliorate this annoyance to some extent.
When it comes to elegance though, C++ is the worst of these choices. Not so much the language itself, as the fact that it can be so messed up by the preprocessor. Especially if you are using a horrible heap of slop like MFC. The code is so full of ugly macros, type conversions, conditionally compiled blocks and other cruft that any elegance of the underlying C++ language is lost. I was just working with some MFC and ATL COM code this week and it is just ugly and overly complicated. Especially after you've been working with Python, Java or C#, going back and looking at that stuff is torture. I won't go into my usual rant about Hungarian Notation, which thankfully isn't encouraged in Java or C#.
> Performance: Less of a problem than in the past but > anyone who has been developing in java has had to deal with > performance issues.
This is probably usually a red herring, an excuse or a scapegoat. If your application has poor performance, it is probably not the fault of the language, the virtual machine (JVM, CLR, or interpreter), or the operating system; it is probably your code.
At the last JavaOne, I talked to the guys working on a 3D rendering tool (http://jrman.sourceforge.net/) whose performance was better than the same thing done in C++.
> Perceptions: ...
I've seen two major cases where the language/platform was used as a scapegoat for slow or buggy software, when it was really the developers and the implementation choices they made that were to blame.
The first was an enterprise Java application where the "architects" went berserk and decided that the thing needed to query every database in the entire corporation on startup. It took 10 to 20 minutes just to start the app, depending on the time of day. The users (most of whom knew little about software development and nothing about Java) constantly complained that it was because it was done with Java. I couldn't convince anyone that it was nothing to do with Java, it was just a bad implementation and you could do it just as badly in any language or platform.
The second example was a C# .NET application with performance problems and bugs. In this case, people are quick to blame any bug on the .NET platform because it is new. As if all applications they had used before .NET were bug free. They are just as quick to blame performance problems on it, because like Java, it is not running on the bare metal. The truth of the matter is that some problems arise from working on a new platform, but most of the major problems are the result of the application's implementation, not the platform or development tools. Interestingly many of the problems have come from interop, because some sub-teams decided they didn't want to do C# programming, so chose to stick with C++ and develop COM components.
I've spent far more time in my career writing C++ code then either Java or C#, but given a choice, I would use either Java or C# over C++ wherever possible (and Python over these, where possible), especially when it comes to a large complex application.
Nowadays, I only use C++ for small focused tools, or as an extension to another language: JNI for Java and for C# or Python I like to create COM Automation servers that work as very easy-to-use libraries (I haven't tracked down a simple Java library for accessing COM Automation, yet, but I bet it exists...).
COM in C++ is a complicated mess and a great breeding ground for bugs, so I don't like to do any more with it than necessary; all the application logic remains in the application and the COM library just provides a simple interface to specific tasks that can't be easily handled by the application's environment (whether it is the CLR or the Python runtime).
For now and some time to come, it is still necessary and in some cases desirable, to do specific tasks in C/C++. For example, one COM Automation library that I created for use by Python and C# (and JScript, etc.) does things like finding windows, getting key states, getting the CRC of files, getting file version information, reading BIOS settings, posting/sending messages to windows, restarting/shutting down the OS, setting system environment variables, and showing/hiding windows. Of course, this is all platform-specific stuff for Windows, but that's the platform I'm working on. (Also, the latest Python Win32 extensions now do a lot of this stuff, but didn't when I first wrote the thing).
One reason managers and "architects" choose to develop applications in C++ is because they and their team only know C++. If this is the case, the whole lot should be fired and replaced with ponies that know more than one trick! That is the wrong reason to choose a language/platform. Quit whining about "learning curves" and learn something new. Get a copy of the The Pragmatic Programmer while you're at it. Both Java and C# are easy to learn and use compared to C++ and the productivity gains will pay off quickly.
In short, my opinion is that while C/C++ is still very useful for specific tasks, I prefer to do general application development with Python, Java or C#.
|
|