Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Such a simple question, but I have not found a reasonable answer to this.

I currently program in Python, an interpreted language. I always hear of people using multiple languages in the same program? Then I hear them using scripting languages; Can someone on here please in plain english explain to me the difference between what I know as programming languages and scripts, and how on Earth do people use multiple languages together. That just does not make any sense.

How can someone use Javascript, PHP, and ASP together. Or program a game in C/C++ and use python as scripts? It just doesn't make sense to me, they are different languages for a reason, i assume, so how do they play a role with one another?

share|improve this question

closed as too broad by gnat, Jörg W Mittag, Doval, MichaelT, Dan Pichelman Dec 24 '14 at 16:11

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. If this question can be reworded to fit the rules in the help center, please edit the question.

1  
You answered yourself: "They are different languages for a reason". Some projects are big enough and have to tackle down many problems, each problem has a language where the solution comes easier/cleaner. –  Mephy Dec 23 '14 at 2:35
    
It's all bits at the bottom... –  Telastyn Dec 23 '14 at 2:37
    
Just doesn't make sense. For instance I am busy programming a MUD style game in Python. Why would I use another language? What is the purpose of it? Preference? Bragging rights to say my program is written in 4 languages? Doesn't make sense. Even if you want too, how do you do it? Its not like I can write in Python code and say, "Here look at this C style code.. do your thing..." doesn't work that way. –  user3712563 Dec 23 '14 at 2:42
    
@user3712563 - how many programming languages have you actually used at length? I would think it was obvious with use that they have different strengths. –  Telastyn Dec 23 '14 at 2:45
    
I have used C++ and Python, a little bit of AutoLISP for my AutoCAD work. No I honestly can't find any strengths or weaknesses for either.. They all do the exact same job, one might be just more txt than the other. –  user3712563 Dec 23 '14 at 2:47

3 Answers 3

Interoperability is usually achieved by transferring data

Generally, you can think each language being it's own separate program. This is not always the case though...

Some examples:

  1. Sending sql queries to a database
  2. using json_encode() in php to encode a data structure into it's string representation, which then can be decoded by java script.
  3. Exposing an api which can be called by an embedded interpreter. This api can be exposed by memory addresses (think lua tied in with c++). Another example is Jython, python that can be ran on the JVM.

Some reasons you want to do this:

  1. Some problems are easier to solve in other languages
  2. You can extend a binary program without having to re-compile it
  3. Tying in existing solutions so you don't have to write stuff from scratch.
share|improve this answer

Bill Door gave some good examples where the "main program" is written in C or C++, and a scripting language is included for customization, But there is also a common, but different scenario, where the "main program", written in some "scripting language" (whatever people have in mind when they use that word) is extended by modules written in C or C++. For example, in Python, a typical use case would be to implement an extension or module in C, because of the better performance one can typically achieve this way. That's why the core parts of Python modules like NumPy or SciPy are mostly written in C, or PyGame, or the Python Imaging Library (PIL).

share|improve this answer
    
And it's actually the most common definition of what "scripting" is - a lightweight glue which binds together various smaller modules or standalone programs. –  SK-logic Dec 23 '14 at 21:48

In many cases, when you see multiple languages used together, you will find that one is a compiled language and the other is a scripting language.

The compiled language is typically C/C++, but can be many other languages (Haskell, Erlang, Java, etc). The compiled language provides the base application. The base provides an interface to the underlying operating system as well as the foundation for the work to be done by the application. The application will often provide lower level functionality that makes it easier to develop using the scripting interface.

The scripting language is most often used to provide customization for the application. The customization can be part of the application provided by the vendor for their own convenience or the scripting interface can provide customization for the end user.

Many times, the script interface will provide almost a Domain Specific Language by providing useful functions and high level interface specific for the application, making it more easily customized.

A couple of well known examples. Emacs is written in C and customized using Emacs Lisp. TextMate is a compiled application customized using Ruby. Atom is a new text editor that is written in JavaScript to run on Node. Atom is more indirect. The application is (nearly?) all JavaScript while Node.js uses V8 which is written in C++. World of Warcraft has a scripting interface that uses Lua.

As a personal example, I worked on a brand-able installer where the base code was Objective-C/C++ in order to access UI elements on MacOS with customization using AppleScript. The AppleScript interface was used only by us in order to brand the application for each customer.

As others have said, use the right language for the right application.

share|improve this answer
    
Maybe I'm being too pedantic here, but instead of "scripting language" I'd write "interpreted language". Compiled languages are complied to a binary that is interpreted (either directly by the processor, as is usually the case for C and C++, or by a runtime, as usually happens with Java or C#). Interpreted languages are not complied, but are run by an interpreter that parses and runs the program without producing a binary form. –  Charlie Kilian Dec 23 '14 at 6:17
2  
There is no such thing as a compiled language or an interpreted language. Compilation and interpretation are traits of the compiler or interpreter (duh!) not the language. Languages aren't compiled or interpreted. They just are. Every language can be implemented with a compiler and every language can be implemented with an interpreter. Most languages have both compiled and interpreted implementations. Most modern high-performance implementations are both interpreted and compiled. There are interpreters for C and C++, there are compilers for JavaScript and Lisp. –  Jörg W Mittag Dec 23 '14 at 18:56
    
@JörgWMittag: you are correct, but do you really think this clarifies anything for the OP? I guess I will change the question title to reflect more what the OP really asks in the question body (which actually does not match the title). –  Doc Brown Dec 23 '14 at 21:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.