Jump to content
  • Advertisement
Sign in to follow this  
kirkd

Mixed language programming

This topic is 3962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I do all of my development using C++, but I have access to a nice set of features from a JAVA library. Where can I find information on mixing C++ and JAVA, or more importantly, should I mix these two. To make matters even more interesting, I had considered Python for the GUI code due to the fact that it is much easier for this purpose. Thus, Python would act as the GUI/glue, the JAVA library would provide a lot of the functionality I need, and C++ would be used for custom, compute intensive operations. I've heard of JPype which allows Python access to JAVA libraries, but I can't seem to find any information about accessing C++ code. -Kirk

Share this post


Link to post
Share on other sites
Advertisement
Java offers JNI for C and C++ integration.

In Java, there's Jython, which is Java-based implementation of Python, which also integrates Java run-time.

In C++, there's boost::python for Python integration.

Quote:
or more importantly, should I mix these two


Who will be master? C++ application, or Python, Java VMs?
Who will define API? C++, Java or Python? How will you generate the stubs?
Who will manage memory? Each of the 3 needs to manage its own. Who will hold shared objects?
How will you build all of this?

Share this post


Link to post
Share on other sites
java comes with JNI for working with C. This is typically used to interface C++ as well. Mixing languages adds a large amount of complexity that doesn't really pay off unless you are in a medium to large size team. For the solo dev it is an interesting thing to play with, but not something you want to throw in your game.

Share this post


Link to post
Share on other sites
We haint DEEF you DONT HAVE TO SHOUT.

Java will interface with C nicely through the JNI (Java will talk only C to the outside world, as far as I know).

C++ talks nicely with C.

Python talks nicely with C.

Do you see the common denominator above?

If you're going to use Java, you may as well use it for all the compute-intensive tasks instead of C++. It's Good Enough for most things. It's also at least as good as Python for GUI stuff, so again if you're going to use Java, you may as well use it for pretty much everything (except talking to hardware when JNI requires you use C).

The places where Java has the biggest problems (slow process startup, resource leaks like a Chicago mobster after Valentines day, nondeterministic GC, distribution of a huge runtime with possible license problems) will still be problems in a mixed language environment.

If you want to use Java, just use Java.

--smw

Share this post


Link to post
Share on other sites
Quote:
Original post by stonemetal
Mixing languages adds a large amount of complexity that doesn't really pay off unless you are in a medium to large size team. For the solo dev it is an interesting thing to play with, but not something you want to throw in your game.

Disagree. Adding in a scripting language is not too hard, and can make it much faster and easier to develop game logic and level-specific behaviour where a rigid and more verbose language would just slow you down. You can reap the benefits even with a single-person project.

kirkd: I think you're trying to mix too much personally. I'd pick one core language to do your actual "engine" code in (either C++ or Java), then layer a single scripting language on top (like Python or Lua). I don't really see the benefit to using both Java and C++ since the glue code required is non-trivial in this case (especially compared to how simple it is to talk to python from Java using Jython).

Share this post


Link to post
Share on other sites
Quote:

We haint DEEF you DONT HAVE TO SHOUT.


Sorry. I wasn't shouting, rather I thought the proper spelling was JAVA not Java. Fortunately it was ONLY this one word that was all CAPS.


To clarify, I have access to a library written in Java that will provide the vast majority of my functionality. I do not currently program in Java - sure, I could learn. I spend most of my time using C++ (is that shouting??) with a little Python thrown in.

I agree, mixing all 3 is a bit too much. I was hoping that there was some reasonable way to integrate what I currently know rather than take the time off to learn Java programming simply to be able to use a library. Slimming down the language content I would prefer to do my core programming in C++ and only use this Java library as needed.

Share this post


Link to post
Share on other sites
Quote:
Original post by kirkd
I agree, mixing all 3 is a bit too much. I was hoping that there was some reasonable way to integrate what I currently know rather than take the time off to learn Java programming simply to be able to use a library. Slimming down the language content I would prefer to do my core programming in C++ and only use this Java library as needed.


The "reasonable way" might depend. If you want to interface Java and C++ directly through an API, the only way to do that is through JNI, which requires that you not only know how to program in Java and C but you need to be pretty much an expert in the entire ugly side of Java dealing with installation and setup and complex interlanguage build tools. If you can wrap your Java library in a simple Java application and have your C++ app interact with it through interprocess communication, which would have a much cleaner interface with minimal need for learning Java programming. It also may not be as performant as you might desire, but then again it might still be good enough.

If you want the worst of both worlds, CORBA or SOAP or one of them there tricksters are you best enemies.

--smw

Share this post


Link to post
Share on other sites
Quote:
Original post by kirkd

I agree, mixing all 3 is a bit too much. I was hoping that there was some reasonable way to integrate what I currently know rather than take the time off to learn Java programming simply to be able to use a library. Slimming down the language content I would prefer to do my core programming in C++ and only use this Java library as needed.


How about sockets? All languages have some RPC/IPC support. And interfaces to them are language specific, which means you don't need to write ugly bridge code.

Ultimately, if the overhead isn't too much, you can to the XML route to pass data between different environments.

This is a common way of doing things in such heterogeneous environments.

Share this post


Link to post
Share on other sites
Quote:
Original post by OrangyTang

Disagree. Adding in a scripting language is not too hard, and can make it much faster and easier to develop game logic and level-specific behaviour where a rigid and more verbose language would just slow you down. You can reap the benefits even with a single-person project.


If you know what you are doing and have played with it for a while you may be correct, but until you are experienced with both languages and have played with interop enough to be able to debug across languages and have enough design chops to know how to use them together for a real benefit, it is more trouble than it is worth. hence the previous comment.

Share this post


Link to post
Share on other sites
Quote:
Original post by kirkd
Sorry. I wasn't shouting, rather I thought the proper spelling was JAVA not Java.


Open question: where does this misconception come from, anyway?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!