How to use multiple programming languages together in the same program? [closed]

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?

11

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.

3

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

1

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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật