I've been programming for a while, I've written some rudimentary programs, and I want to keep learning. I've reached that point where you just don't know what to learn next, and I'd like to ask a question for my own curiosity.
The question, in a nutshell, is if you can combine multiple programming languages into 1 result? For example, can this code be possible?
<html>
cout << "Hello world!";
</html>
or
import java.util.Scanner;
cout << "Insert a number from 1 to 10";
Scanner n = new Scanner(System.in);
System.out.println("The value you entered was" +n.newLine());
This feels like a silly question but I can't possible know if it's possible or not, so that's why I'm asking it. In this question I notice he is using Python code in html code, if my above example is not possible, what did he do?
Best Answer
You first example is sort of possible. Usually such things happen in PHP (and other related web-programming languages) like this:
Some important points to note about this example:
Your second example looks like some sort of mash-up of C++ and Java. It's possible to have compiled modules written in different languages talk to each other, but to combine Java and C++ in the same source file would be extremely confusing and difficult: how would the compiler know which statements are Java and which are C++?
I suppose in theory you could write a special compiler/pre-processor with "language" indicators such as:
But I'm honestly not sure you'd gain anything useful by doing this.
Also, how would this hybrid language environment handle language features which are incompatible between the two?