Question:
Why can't compiled languages be interpreted?
mframen
2011-06-18 00:42:38 UTC
I've never really done any work with programming that required a compiler. i like working with scripted languages, but i'd like to get into programming with c++ or something like that because i can do a lot more.

Why do C++ and other programming languages need to be compiled? Why can't I script them in an interpreter and then compile them when i want to distribute them?

I guess this is two questions. Do you have to compile everytime you want to test your code along the way? Isn't that a huge hassle?
Five answers:
AnalProgrammer
2011-06-18 00:57:15 UTC
With a compiled language it is the compiler that is unique to the base operating system.

This means that the resulting program is unique to the base operating system and can probably make use of a lot of features of that operating system. This means that whilst the source code can be transported to different platforms the compiled program cannot. Of course the source that is transported to another system cannot contain OS specific code.



With an interpreted language it is the interpreter that is unique to the base operating system and so the code is more easily transported to different platforms. Because of this an interpreted language cannot make use of specific features of an operating system because they may not be available and because that would restrict the transportation of the code.



Have fun.
peteams
2011-06-18 09:04:33 UTC
Compiled languages can be interpreted, and indeed interpreted languages can be compiled.



Java is a compiled language, but it doesn't get compiled to native code it gets compiled to byte-code which is then interpreted by the host computer. Similarly Basic is designed to be an interpreted language, but using Visual Basic.NET the language is always run as compiled native code.



Interpretation and compilation are the two extremes of a line describing how a language is executed. Underneath the hood some compiled languages have characteristics of interpreted languages and some interpreted languages have characteristics of compiled languages.



JavaScript is naturally an interpreted languages. It has one of the key indicators of an interpreted language, you can very easily create a string that contains JavaScript and call an evaluate function on it to execute it. Yet some browsers are now compiling JavaScript to native code.



C# is a compiled language that runs as native code. Yet certain operations involve the creation of C# code that is then compiled as the program is running, just like you'd think an interpreter would do. [I haven't checked whether this behaviour is still present in recent editions, in early versions 'serialization' was implemented by emitting C# code, the C# compiler certainly ships with all editions of .NET to support this.]



In the old days of command line Basic, you could pause a running interpret program, change its variables, rewrite some of its code and then restart it running. That was the power that an interpreted language gave over its compiled brethren.



In a modern IDE like Visual Studio you can pause a C++ program, execute C++ statements in the immediate window, examine and change the content of variables, modify the code and the continue running it. From a developers point of view, there is little difference between compiled and interpreted; you have to look pretty deep under the hood to work out which you're using.



I've mentioned .NET several times and said its programs run as native code. However it uses an unusual model, Visual Basic.NET, C# and C++/CLI compile to an intermediate language that is then placed into the executable, this is similar to the Java model. When the program is installed or starts running, unlike Java which interprets the intermediate code, .NET compiles the intermediate language into native code. So .NET programs can appear to exhibit characteristics of both interpreted and compiled systems.



I work with large and complex C# and C++ applications on a day-to-day basis. Modern compilers can complie modified parts of code in isolation and do so very rapidly. So despite being in a large code base, I can made a small change and see its results immediately.
2011-06-18 07:50:20 UTC
It depends on the language.



Yes and no, it depends on the language. Python for example is all interpreter based, and you do not compile until you want to distribute code widely. Java on the other hand uses what is known as a Java Virtual Machine to execute code. Code is converted to bytecode and that code is executed. The 'compilation' is almost instantaneous, so it isn't a hassle. However, you can go even further and create a package, which is what you will distribute after you get the code right.



I haven't really done any work with C++, so I can't help in that respect though.
?
2011-06-18 08:05:52 UTC
compiling : make C++ source code (in text format) become native computer language (binary format). So compiled program (.exe) can run directly from operating system without depend on other program like interpreter does.



yes, we have to re-compile C++ source code after modification. Depend on program that will create, compiling process can be little bit need knowledge to how to compile.
Titus
2011-06-18 07:56:35 UTC
Yes and if you're using an IDE, not really. C++ and other non scripting language based programs need to be compiled to check for errors, and build your program correctly linked with specific libraries attributed with the OS (I/O for example). In scripting languages you're used to finding errors at runtime because there is no real compilation.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...