Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to mix languages?

What are some situations where languages should be mixed?

I'm not talking about using ASP.NET with C# and HTML or an application written in C accessing a SQL database through SQL queries. I'm talking about things like mixing C++ with Fortran or Ada with Haskell etc. for example.

[EDIT]

First of all: thank you for all your answers.

When I asked this question I had in mind that you always read "every language has its special purpose".

In general, you can get almost everything done in any language by using special libraries. But, if you are interested in learning different languages, why not take the programming language that serves your purpose best instead of a library that solves a problem your language wasn't originally designed for?

like image 515
Inno Avatar asked Jul 03 '09 21:07

Inno


People also ask

Is it normal to mix up languages?

Small bilingual children frequently mix the languages they are learning. This is completely normal. Everyone sometimes struggles to find the right word, even those who speak only one language.

Is it OK to speak 2 languages to a baby?

It's never too late – or too early – to introduce your child to a second language. The optimal time, according to experts, is from birth to 3 years old – exactly when a child is learning their first language, and their mind is still open and flexible.

Why do people mix languages when speaking?

Some people code-switch into a different language either to sound more authoritative or more approachable. This is particularly common for parents bringing up children multilingually, who might end up using specific languages for different interactions.

Why it's okay for bilingual children to mix languages?

What it could actually be doing is demonstrating high-level flexibility and interpersonal skills. Being bilingual is not simply about being able to speak two languages. Rigidly policing consistency in the one-parent-one-language approach could actually restrict bilingual children's linguistic ability and creativity.


2 Answers

For example, in video games we use different languages for different purpose :

  • Application (Game) code : have to be fast, organized and most of the time cross-platform (at least win, MacOS is to be envisaged), often on constraint-heavy platforms (consoles), so C++ (and sometimes C and asm) is used.
  • Development Tools : level design tools generates data that the game code will play with. Those kind of tool don't need to run on the target platform (but if you can it's easier to debug) so often they are made with fast-development languages such as C#, Python, etc.
  • Script system : some parts of the games will have to be tweaked by the designers, using variables or scripts. It's really easier and cheap to embed a scripting language instead of writing one so Lua or other similar scripting languages are often used.
  • Web application : sometimes a game will require to provide some data online, most often in a database accessed with SQL. The web application then is written in a language that might be C#, Ruby(R.O.R.), Python, PHP or anything else that is good for the job. As it's about the web, you then have to use HTML/Javascript too.
  • etc...

In my game I use HTML/Javascript for GUI too.

[EDIT]

To answer your edit : the language you know the best is not always the most efficient tool for the work. That's why for example I use C++ for my home-made game because I know it best (I could use a lot of other languages as the targets are Win/Mac/Linux, not consoles) but I use Python for everything related to build process, file manipulation etc. I don't know Python in depth but it's fare easier to do quick file manipulation with it than with C++. I wouldn't use C++ for web application for obvious reasons.

In the end, you use what is efficient for the job. That's what you learn by working in real world constraints, with money, time and quality in mind.

like image 80
Klaim Avatar answered Feb 19 '23 07:02

Klaim


Well, the most obvious (and the most common) situation would be when you use some high level language to make most of your program, reaping the benefits of fast development and robustness, while using some lower level language like C or even assembly to gain speed where it is important.

Also, many times it is necessary to interface with other software written in some other language. A good example here are APIs exposed by the operating system - they're usually written with C in mind (though I remember some old MacOS versions using Pascal). If you don't have a native binding for your language-compiler infrastructure, you have to write some interface code to "glue" your program with "the other side".

There are also some domain-specific languages that are tuned specifically to efficiently express some type of computation. You usually don't write your entire program in them, just some parts where it is the appropriate tool. Prolog is a good example.

Last but not least, you sometimes have heaps of old and tested code written in another language at hand, which you could benefit from using. Instead of reinventing the wheel in a new and better language, you may simply want to interface it to your new program. This is probably the most usual (if not the only) case when languages geared for similar uses are mixed together (was that C++ and Fortran you mentioned?).

Generally, different languages have different strengths and weaknesses. You should try to use the appropriate tool for the job at hand. If the benefits from expressing some parts of the program in a different language are greater than the problems this introduces, then it's best to go for it.

like image 34
stormsoul Avatar answered Feb 19 '23 05:02

stormsoul