The Artima Developer Community
Sponsored Link

Java Answers Forum
Java vs C++

10 replies on 1 page. Most recent reply: Sep 26, 2003 8:04 PM by Frank Mitchell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 10 replies on 1 page
John Channing

Posts: 17
Nickname: drc
Registered: Jun, 2003

Java vs C++ Posted: Sep 24, 2003 2:18 AM
Reply to this message Reply
Advertisement
I have my opinions on the merits of Java compared with C++, but I am interested in other people's personal experiences. I'm thinking of taking a job at a company that is essentially a C++ house, but are moving towards Java and I will need some persuasive arguments to bring people around to my thinking.
John


John Channing

Posts: 17
Nickname: drc
Registered: Jun, 2003

Re: Java vs C++ Posted: Sep 24, 2003 8:22 AM
Reply to this message Reply
Maybe I misjudged this one. Do we have any real programmers here who can share some views? Or are there just kids trying to cheat on their homework assignments? ;)
John

Daniel

Posts: 1
Nickname: heron
Registered: Sep, 2003

Re: Java vs C++ Posted: Sep 24, 2003 3:11 PM
Reply to this message Reply
Well not out of personal experience but might still be interesting:

www.rolemaker.dk/articles/evaljava/ Evaluating%20Java%20for%20Game%20Development.pdf

It's focused on game design but still worth reading.

And actually on this site:

http://www.artima.com/intv/gosling12.html

might help or not. hope it does.

out. dan

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Java vs C++ Posted: Sep 24, 2003 4:38 PM
Reply to this message Reply
What personal experiences, for example, brought you around to your thinking?

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Java vs C++ Posted: Sep 25, 2003 8:21 AM
Reply to this message Reply
And what is your "way of thinking" that you are trying to bring other people around to?

John Channing

Posts: 17
Nickname: drc
Registered: Jun, 2003

Re: Java vs C++ Posted: Sep 26, 2003 1:56 AM
Reply to this message Reply
And what is your "way of thinking" that you are trying to bring other people around to?

Matt,
In brief, that there is currently no valid reason to choose C++ over Java for any of the projects they have discussed with me.

From your bio you appear well placed to give me some sensible views, can you do that please?
John

John Channing

Posts: 17
Nickname: drc
Registered: Jun, 2003

Re: Java vs C++ Posted: Sep 26, 2003 1:58 AM
Reply to this message Reply
What personal experiences, for example, brought you around to your thinking?

Working on two large scale mission critical projects, one in C++/CORBA the other Java/J2EE.
John

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Java vs C++ Posted: Sep 26, 2003 2:41 AM
Reply to this message Reply
> And what is your "way of thinking" that you are trying
> to bring other people around to?

>
> Matt,
> In brief, that there is currently no valid reason to
> choose C++ over Java for any of the projects they have
> discussed with me.

John,

Given your conclusion above; What are the valid reasons that you would put forward to choose Java over C++?

V.

Greg

Posts: 18
Nickname: singleton
Registered: Jun, 2003

Re: Java vs C++ Posted: Sep 26, 2003 11:31 AM
Reply to this message Reply
PLUS
----------------
Portability: this is a biggie for me. And I don't find
that I need to rewrite apps significantly to run on
multiple os's unless using jni.

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. When looking for alternatives, management
was astounded that linux was immune to the onslaught.
However our work is all in VB. Case closed.

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.

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.)

MINUS
--------------------------------------------------------
Performance: Less of a problem than in the past but anyone
who has been developing in java has had to deal with
performance issues. I've seen projects abandoned because
of poor performance on handheld devices. Again it's better
now but it was an adventure running java apps on a 33mhz
dragonball processor and keeping resources below 64k. I'm
talking just a few years ago.

Perceptions: Depends on the shop. Sun screwed up with the
history of java. Lots of people equate it with "slow and
buggy" because they were introduced to it running applets
through a 24kps modem. Many people have no idea that it
can be used for anything else. It's a hard sell to big
dumb management in some shops.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Java cs C++ Posted: Sep 26, 2003 6:46 PM
Reply to this message Reply
> 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#.

Frank Mitchell

Posts: 37
Nickname: fmitchell
Registered: Jan, 2003

Re: Java cs C++ Posted: Sep 26, 2003 8:04 PM
Reply to this message Reply
> 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.

A nitpick: Java will be adding "genericity" (or parametric polymorphism), not templates.

"Genericity" specifically addresses type-safe containers, wrappers, etc. IIRC, Java will only use type information for compilation; at runtime, a List<X> is simply a List containing instances of X, plus a few strategic typecasts in code using the list.

Templates, on the other hand, are a specific technique that provides genericity. Somewhat like a C macro, each template instantiation creates a brand new class that substitutes a real type for each parameter. Thus, templates lead to machine code bloat and excessive recompilation times.

On some newsgroup somewhere (how specific of me), some C++ proponent ranted at me that templates were the "only sensible" implementation of genericity. Does anyone else want to back up that assertion? (I believe C++ templates can also substitute concrete values and function references ... which saves a little space on each instance but doesn't sound phenomenally useful.)

Flat View: This topic has 10 replies on 1 page
Topic: Pass by Reference/Value Previous Topic   Next Topic Topic: How do I convert a file to a unicode encoding??

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use