Sign in to follow this  
moeen k

is it possible to program one app with different languages?

Recommended Posts

hi.

in one program for a good structure to work for different platforms its good to have a undependant layer of platfrom like algorithms and ... and may its good to do it with c++. but on different platforms maybe you want to use a special api that is only written for python or.... is it technically possible to do that as we know windows libraries is written with dll and other platforms like android is jar.

 

if its not possible, pro developers what do they do in these times.

thank you for helping

Share this post


Link to post
Share on other sites


Yes it's possible and common to use multiple languages.

 

 can you explain a little more. just an example how really it works?

 

for exmple how a python code uses output of a c# function. should it be a compiled library code or it can be simply done?

Share this post


Link to post
Share on other sites

 


Yes it's possible and common to use multiple languages.

 

 can you explain a little more. just an example how really it works?

 

for exmple how a python code uses output of a c# function. should it be a compiled library code or it can be simply done?

 

 

I find myself doing this all the time; hell, I am doing it as we speak.  For example,  I have an old piece of software that needed to target Android, PC, and iOS.  Since I created the app on Android, the program was in Java.  When I ported it to PC, I decided to stick with Java.  When I ported it to iOS, I had to recode the app using Objective-C.  The Android and PC version of the app shared almost the same code base, with the exception of a select few platform specific parts.  The iOS version used the same ideals as the other two platforms, but was a completely new code base.

 

EDIT:  I just looked over your last post again, and I believe you are confusing the use of multiple languages.  What you are referring to "FFI."  The language has to support calling functions from other languages; for example, C# offers the ability to call native functions from managed code.  For example, with C# calling C++, the C++ code has to be coded in a specific way and compiled using CLR.  You then hook the DLL in C# and bind your routines.

 

Here is some more information.

https://msdn.microsoft.com/en-us/library/ms235282.aspx

Edited by ByteTroll

Share this post


Link to post
Share on other sites

hi.

in one program for a good structure to work for different platforms its good to have a undependant layer of platfrom like algorithms and ... and may its good to do it with c++. but on different platforms maybe you want to use a special api that is only written for python or.... is it technically possible to do that as we know windows libraries is written with dll and other platforms like android is jar.

 

if its not possible, pro developers what do they do in these times.

thank you for helping

Short answer is "yes". Check out cocos2d-x for example. It is open-source and is mostly written in C++, but uses other languages (Objective-C for iOS, Java for Android) for platform specific stuff.

 

Longer answer: iOS has Objective-C++ and it can mix Objective-C and C++ code pretty easy. Android uses Java and Java has JNI to work with C/C++.

Share this post


Link to post
Share on other sites

Well first, you of course need the 'core' language with the crossplatform code to run on all the platforms (c++ in your example).

 

Then, you might have more cross platform code written in another language. Communication with these depends on the language and the "FFI" mechanism it implements as explained (usually calling C-like simple functions is supported, possibly with special requirements/constraints to make sure it works properly).

 

Then, there might be platform dependent libraries written in another language OR the same core language. With C++, you would write the code for each such platform dependent library, and then at compile time choose which piece of code you want to compile using preprocessor directives (if its windows, use this block of code, if its mac, use this next one and so on). This would be done such that whatever platform dependent library you choose, the interface is the same, so the cross platform code can use it the same way (eg you might have a function that does something, and the implementation of it changes depending on platform. So the interface doesnt change)

 

Though just because the interface for such a cross platform functionality implemented differently for each platform doesnt change, its behavior might. Eg if it was some kind of rendering class, on one platform it would report that it supports some maximum size of texture, and another platform the maximum size might be different. But thats a part of the interface so its ok.

Share this post


Link to post
Share on other sites

Of course, directly calling a function in a program (or library) in another language is not the only way to communicate with it. You can very well make any two programs communicate via network or IPC, this is how DB queries and remote procedure calls generally work. That's also an example of programming an "app" with different languages: write the backend in one language, the client in another language, yet they can still communicate. This is probably not what you meant (you probably mean within the same process, e.g. Lua and C/C++) but thought I'd point it out.

Share this post


Link to post
Share on other sites

I am not sure why you ask this question, but yes: Python loads modules written in C/C++ and the same for PHP where modules are written in C.

Many languages has that ability, mostly using C as a bridge.

If that your question?

If it isn't, then ask differently.

 

<edit>

DLLs and jar?

That is two different things.

A 'jar' file is simply just an archive, like a zip file, only simpler. It does carry a manifest and some other Java jazz, and then some compiled (binary) files (.class) which can be loaded by a running Java program.

A DLL is a compiled, shared library, specifically designed to run/execute/load on the Windows platform. On Linux that would be a .so file.

Edited by jacmoe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this