Why C++ when Java!

I am capturing a part of discussion we had on JavaRanch about C++ especially C++ 2008 which is bundled with .NET Studio 2008 (upgrade 2010 version is available now)

My question to the community and author of book Murach’s C++ 2008 was:-

Why would you want to go back to C++ when there are other free and equally powerful languages like Java? I work with machines and manufacturing and still I can take the performance hit of Java and make it work.
Why do people still code in C++ and esp C++ in .NET which is a commercial license? There are so many tools/plugins/IDEs/components available in other languages to get up and started with.

Some of the replies were :-

  1. It’s what the individuals are used to.
  2. Language is suitable for the purpose.
  3. Too lazy
  4. Bit Handling
  5. Interfacing with lower-level protocols
  6. Device and OS drivers / management
  7. Embedded work

Now I develop in Unix C++ and Java and we have successfully implemented Bit Handling, Interfacing with lower-level protocols, device and OS drivers/management.

We are updating our repository from C++ to Java since we have better ways to handle and enhance code. We have successfully achieved the tasks listed above as well.
Also, we get more and more developers well-versed with Java as compared to their C++ skills I would love not to waste time updating our legacy code but I do not see any C++ training sessions or skills distributed around us. So maintenance is a big issue.

Henry Wong’s use case :
A few years ago, I had to make a call to .NET from java. With JNI, it was possible to get from Java to C/C++, but that isn’t enough. Unmanaged C/C++ can’t use .NET services in most cases. The only thing that it can do is call static methods.
So, I had two options…
1. Make another wrapper to get to Managed C++ — meaning Java to C/C++ to managed C++.
2. Make another wrapper to get to C# — meaning Java to C/C++ to C#.
In the end, I chose the first case. Why? My reasoning was that unmanaged C++ and managed C++ can be in the same file. There was no need to have a separate file to compile. A stronger (and probably better) reason was probably that three languages at the same time (although I do that often today) tend to get really confusing.

One big reason is not everyone has the luxury of choosing between either Java and C++. For many, it is not a choice. For many, it could even be both. You have to code based on the underlying libraries, frameworks, managerial decisions. etc.
Good programmers must work within the restrictions of the project. And in my opinion, someone that quits or refuse to join a project, because it isn’t pure java, is someone that I don’t want on a project. The last thing that I need is someone whose understanding of other languages is whether it is legacy or not.

This came from the author Pren:
One unique factor offered by C++ 2008 is its backward compatibility to native (unmanaged) C++ and legacy C. This offers the programmer the ability of using proven and tested code written more than 30 years ago. The world’s first Hello World program illustrated in the 1978 first edition of The C Programming Language (called Hello, Earth on page 527) still runs without change, as does the same program in The C++ Programming Language (called Hello, Mars on page 529).

Language is influenced by factors like:
1. Language that all your team members are comfortable with.
2. Existing technology that the company is using.
3. Easy for developing prototypes
4. Mandatory language for the targeted platform

Don’t forget the maintenance issues, although it can be seen as related with the existing technology that the company is using. You know, the main cost of every software development project resides in its maintenance, so besides the documentation, a well ordered and structured programming, etc., the availability of good programmers in a specific programming language far beyond the end of the project “development”, it should also be a key for choosing the right language. Some examples regarding the difficulty in the availability of C++ programmers has been mentioned here. And concerning the easy for developing prototypes you also mentioned, yes, this could be a reason if your project and or development methodology is mainly based on prototyping.

Humans are lazy by nature and if their needs can be accomplished by one language, don’t expect they learn another (there are always exceptions), thus the answer should bypass this natural human behavior and then respond that C++ may be used when Java doesn’t fit well enough to our purposes, and vice versa. For instance, C++ best fits in programming embedded devices, but Java in web development.

Advertisements

One thought on “Why C++ when Java!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s