LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A Newb wondering about programming in multiple languages (https://www.linuxquestions.org/questions/programming-9/a-newb-wondering-about-programming-in-multiple-languages-748548/)

kcaz 08-18-2009 05:41 PM

A Newb wondering about programming in multiple languages
 
Well I have been interested in programming for a while, and just found out about Linux and Unix. I started out with Java, but now I know I bunch: Flash, C++, C and others. I was working on a mac so I made a few flash games then started to work on iPhone games. I was board one day and I found out about Unix and I thought that would be something else to try.

So in an attempt to learn about Unix I have been reading different articles about it, and have heard of using different languages in one program. The article I was reading didn't give any examples, and it assumed the reader has programmed Unix before.

So how do you write programs in multiple languages, which languages would you use, and why would you want to do that?

Thanks for the help,
Kcaz

jiml8 08-18-2009 06:27 PM

You just write your modules in the appropriate language, compile with the gcc toolset, and link it all together. Sometimes you have to do certain things in the code or in the compile or link options to make it work but it is always do-able.

Why do it? Sometimes you want to talk to a library that is written in a certain language, and using a module written in that language to talk to it is easier. Sometimes what you want to do is convenient in one language and harder in another language. Sometimes you are taking existing code from one language and want to use it in a program that you are writing in another language, without rewriting that module. All kinds of reasons why.

I routinely mix C and C++ modules, and sometimes I even throw in some fortran.

David1357 08-18-2009 06:33 PM

Quote:

Originally Posted by kcaz (Post 3648638)
So how do you write programs in multiple languages, which languages would you use, and why would you want to do that?

You might want to start your game using Python and the pygame library. You might find that you need to speed up a portion of your game, so you might write a Python extension module in C. You might want to customize Python, so you might write a Python extension module in C++ to get access to templates and the STL.

sundialsvcs 08-18-2009 11:16 PM

Always try to program new stuff in the "highest-level" programming language available to you. For example, if you can possibly get away with doing the whole thing (say...) in Python, then you should by all means do that.

Here's why: even a single line of code in one of those languages will invoke very large amounts of well-tested low level code written by some of the smartest minds around. That code has been extensively tested, and execution-wise it is sure to be "more than fast enough for your purposes." The time that you're trying to save here is, your time.

If for some reason you found that things were "just not fast enough," then you should run a profiler on the code to determine where and why this is so. Your first response then should be, "find a better algorithm."

Certainly, programs can be written in a multitude of languages. But, especially at today's processor speeds and system capacities, the most urgent objectives are your speed and efficiency in developing a robust application.


All times are GMT -5. The time now is 09:23 PM.