aspose file tools*
The moose likes C / C++ and the fly likes Why C++ when Java! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Why C++ when Java!" Watch "Why C++ when Java!" New topic
Author

Why C++ when Java!

Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

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.


===Vyas Sanzgiri===
My Blog
Craig Taylor
Ranch Hand

Joined: Jul 17, 2008
Posts: 64
Generally, any of the questions of the form, "Why program in X when Y does Z" can be answered by any of the following:

a) It's what the individuals are used to.
b) The language, for the task given, may be just as suitable for the purpose.
c) Too lazy to be aware of anything else.

Now, given that - C++ (and I'm speaking from Unix C++ / not .Net as I haven't looked at it) does have some advantages over Java in a couple of areas:

- Bit Handling
- Interfacing with lower-level protocols
- Device and OS drivers / management
- Embedded work

In short, the answer is the same reason as your answer to the question - Why do you like flavor of tea you like?
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Craig - interesting perspective!

I develop in Unix C++ and Java and we have successfully implemented Bit Handling, Interfacing with lower-level protocols, device and OS drivers/management. There are so many libraries available in Java to interface. I do not deal with embedded work so I cannot comment.

But I want to specifically know why does one use C++ 2008 (.NET)

In short, I doubt A and C but B needs research. The answer is not as simple as your tea example - I make tea at home cause it costs less :-)
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Vyas Sanzgiri wrote:In short, I doubt A and C but B needs research. The answer is not as simple as your tea example - I make tea at home cause it costs less :-)


You doubt that some people use a language because it is the only one they know? And it can be as simple as the tea example. It costs less for me to use Java than C++ because I know java better and it is more suited to what I primarily do, which is web development. Folks use managed C++ (C++ in the .NET environment) for a lot of reasons.

To me, your questions are bordering on insulting. I perceive a bit judgment in them.

[I edited one part of my post because I didn't realize this was probably targeted towards the book promo.]


GenRocket - Experts at Building Test Data
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

I am sorry I never meant insult and insult to whom? I am talking to the general public. Sorry again Gregg, Craig and ranchers

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.

I am just trying to understand why one would use Unix C++ or C++ 2008 (which I just learnt about last week!)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18836
    
  40


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.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18836
    
  40

Vyas Sanzgiri wrote:
I am just trying to understand why one would use Unix C++ or C++ 2008 (which I just learnt about last week!)


Well, 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.

Henry
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Henry Wong wrote:

Well, 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.

Henry


Absolutely true as one of the reasons
Prentiss Knowlton
Author
Greenhorn

Joined: Dec 18, 2009
Posts: 7
Greetings, Vyas --

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

Cheers,
Pren

Vyas Sanzgiri wrote: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.


Prentiss Knowlton

People don't care how much you know until they know how much you care -- Cavett Robert
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Very interested. I have to try it out.
Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
...it is interesting but, depending on the company you are working in and the architectural
decisions that have been taken, it might need some arm twisting before you can indeed
try out C++ and then use for real development.

I've worked for companies that were open for suggestions and others that were more
conservative, both have their advantages.


"Eppur si muove!"
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Gian, I am looking beyond management decisions, resistance to change, "I know c++language" kind of statements. I am more towards what is the technical reason behind C++ still being used as the author and a few other ppl have commented before.

In our company we are finding it very difficult to support C++ since we do not get good quality C++ programmers. Our message bus and core infrastructure is still in C++ ! - very stable and reliable
Pradip Bhattacharya
Greenhorn

Joined: Dec 05, 2008
Posts: 23
Hi Vyas,
Actually choice of 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
(this is all that came to my mind while writing this reply)

I work in a mobile gaming company where we develop mobile games for numerous platforms. To be honest I simply love Java and C++. My choice of language depends upon the targeted mobile phone. But whenever I need to test out an algorithm or need to make some prototype, I use Java. For server side programming I again use Java because I love Servlets/JSP. It takes care of most the headaches.
Still there are some parts of the code which needs to be written in C,C++ when every single CPU cycle and every single byte becomes important .

Pradip.B
Oriol Boan
Greenhorn

Joined: May 30, 2009
Posts: 15

Hello,

Pradip Bhattacharya wrote:Hi Vyas,
Actually choice of 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
(this is all that came to my mind while writing this reply)


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.

And answering the thread question, Why C++ when Java!, 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 behaviour and then respond that C++ may be used when Java doesn't fit well enough to our purposes, and viceversa. For instance, C++ best fits in programming embedded devices, but Java in web development.


www.orboan.com
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Hmm...interesting topic. I think it all depends on nature of the Project and decisions made by Enterprise architects because a lot of factors involved including compatibility to existing systems, company culture on introducing new language etc.. One key point is money being spent on new project. I know it is easier to find good and cost effective Java programmer than C++ guy. So, maintenance would be much cheaper if you go by a popular and widely used language, which is Java

But again it all depends on nature of the project and we can't have a rule of thumb


SCJP 1.5, SCEA, ICED (287,484,486)
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Most of the commercial Java Runtime Environments (JRE) are written in C++.

So, when you think you are using only Java, you are also using C++ in most cases
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

ok. I am marking this topic as resolved since I got the essence of the argument.

Thanks for all your expert contribution.
Sha Jar
Greenhorn

Joined: Mar 02, 2010
Posts: 23
Vyas Sanzgiri wrote: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.


I'm not going back to C++. I prefer C++ over Java. I learned C then Java and then C++. In my view C++ is superior to Java.

I like the portability of Java. That's the only reason to use it really. But as soon as you need to do something just a little out of the ordinary Java becomes a hassle. For example forget using OpenGL with Java. And try to easily use other non-mainstream technologies with Java such as CUDA. It's a pain in the ass.

Besides all the problems with using Java in extraordinary situations, C++ actually is a much better language. And to boot, C++ is not proprietory.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18836
    
  40

In my current job, I use both C/C++ and Java (actually, use C++ a bit more than Java at the moment, but it changes week to week). And seriously, don't really prefer one over the other. Maybe it is because I am very comfortable with both. Maybe it is because I care less about the language, the API, or framework, and more about the task at hand.


Anyway... I could see the last post fueling a bit of a religious debate -- it definitely "pushed" it a bit more than other posts. Please be careful. This topic is interesting. Or it can get to the point where it will be deleted.

Henry
Sha Jar
Greenhorn

Joined: Mar 02, 2010
Posts: 23
Henry Wong wrote:Anyway... I could see the last post fueling a bit of a religious debate -- it definitely "pushed" it a bit more than other posts. Please be careful. This topic is interesting. Or it can get to the point where it will be deleted.


It's my post you mean right.

Well I thought the OP asked for personal experience so I gave mine.

I'm not trying to impose my view on anybody else though. Everybody thinks and does what they want.
Pradip Bhattacharya
Greenhorn

Joined: Dec 05, 2008
Posts: 23
I am not trying to hijack the thread. Just want to give my opinion on what Natasha wrote
Natasha Jar wrote:For example forget using OpenGL with Java.

Its just a matter of writing appropriate java bindings. I have used JOGL and Android Java OpenglES interface, they are pretty good. And currently I am not aware of any CUDA binding. But it should be relatively easy once you know CUDA.
I think its inappropriate to draw comparisons between two languages based on the availability of OpenGL/CUDA support.






 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why C++ when Java!