What is an interpreted language?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1413 Views - Last Post: 24 March 2020 - 11:14 AM

#1 O'Niel   User is offline

  • D.I.C Addict

Reputation: 25
  • View blog
  • Posts: 584
  • Joined: 13-September 15

What is an interpreted language?

Posted 21 March 2020 - 05:38 PM

Hello

So I know the difference between an interpreted language and a compiled language. The definition is that an interpreter executes the code immediately while a compiler first needs to translate the high-level language code to machine code.

An example of an interpreted language is Python and for the latter we have for example Rust or C++.

HOWEVEEEER... While everyone is calling Python an interpreted language the Python interpreter (and more interpreted languages) actually also compiles the Python code to bytecode before executing it. Then why isn't Python considered a compiled language?


Is the difference that the bytecode from Python is executed in. a kind of VM instead of directly on the processor? But what about Java then? That's also executed on a kind of VM.

This got me confused...

Is This A Good Question/Topic? 1
  • +

Replies To: What is an interpreted language?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15743
  • View blog
  • Posts: 63,068
  • Joined: 12-June 08

Re: What is an interpreted language?

Posted 21 March 2020 - 06:18 PM

It's compiled-interpreted..

https://www.youtube....h?v=0BhSWyDEDC4


It's different from java as the dev isn't compiling their python script. That's all being handled when it ran.. .while Java requires the dev to do the compiling ahead of time to distribute.
Was This Post Helpful? 1
  • +
  • -

#3 O'Niel   User is offline

  • D.I.C Addict

Reputation: 25
  • View blog
  • Posts: 584
  • Joined: 13-September 15

Re: What is an interpreted language?

Posted 21 March 2020 - 06:33 PM

Alright thanks for the video.
However, I still have questions with this definition

 as the dev isn't compiling their python script


Take Rust for example (a compiled language). When I execute the command 'cargo run' in a Rust project, I - as a developer - do not need to compile/build the Rust code myself. The command does that automatically for me and executes the script immediately. Does that make Rust also compiler-interpreted?

Maybe the difference between interpreted and compiled is rather a vague line because in the end all code is compiled to zero and ones somehow? And we as developers just use those terms to differentiate the different types of languages because they all serve a different purpose (interpreted languages being fast to write and scripty while compiled languages are more performance-oriented).

This post has been edited by Skydiver: 21 March 2020 - 07:07 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 1
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15743
  • View blog
  • Posts: 63,068
  • Joined: 12-June 08

Re: What is an interpreted language?

Posted 21 March 2020 - 06:51 PM

I've never used Rust, but from a cursory google search points to it is compiled.
Was This Post Helpful? 1
  • +
  • -

#5 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7407
  • View blog
  • Posts: 24,986
  • Joined: 05-May 12

Re: What is an interpreted language?

Posted 21 March 2020 - 07:13 PM

Yes, Rust is compiled. It uses the LLVM compiler to generate object code which then gets compiled to native assembler into an executable. cargo run is just a shortcut for cargo build followed by running the generated executable.
Was This Post Helpful? 1
  • +
  • -

#6 justawebuser   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 83
  • Joined: 09-February 14

Re: What is an interpreted language?

Posted 22 March 2020 - 12:04 AM

interpreter executes the code immediately

No, It doesn't. It compiles and then executes it.

So what is the difference?

In Interpreted ones, the interpreter compiles and then runs the code line by line or section by section.
It's good for output based apps like websites, command-line tools, etc..


Sometimes compilation of the whole code is needed. And some times you can have something between these two.

By the way, IMHI most IT phrases need to be reconsidered and updated.

Back when I was starting to learn how to program I remember everybody called C a High-Level language But now it's considered as mid-level or even Low-level language.
Was This Post Helpful? 0
  • +
  • -

#7 Radius Nightly   User is online

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 366
  • Joined: 07-May 15

Re: What is an interpreted language?

Posted 22 March 2020 - 12:05 AM

I would put it down to something else, such as code itself.
Scripts are small codes and it can be revealed, such as bug fixes or other things, its not a threat, its light and fast, can be used for GUI, some calculations, and easier to modify it later on, so performance is not as issue, because sometimes you get better performance from engine thats running interpreted complex script, rather then compiled. There is actually no difference between this two, will engine start up, load scripts into RAM and execute or if application load itself in memory and execute itself, its the same. Also both can be virtualized and isolated.

However, some codes are not meant to be visible to the public. So, if someone make compiled code, its hard to reverse compiled code into original code and its based on guesses, since its not anymore a code that humans can understand, so its good for protection or closed code, and if developer want it to be open source, he can reveal original code, but you still cant know if compiled version hides something. Peoples also sometimes dont trust closed sources, and if you lose original code, your project is probably ended. Corporations like this things, since they dont wanna share their code to someone else who can earn profit from their work, so they want closed source.

In other hand interpreted version, or scripts are always code that humans can understand, the original code, and no matter what you do, encrypt it, put password on it, encode it, whatever you do to make it closed source, it will always be open source, since this whole original code will end up running from RAM as plain text and lines of codes, and can be dumped. Whatever you do to protect the code from some random peoples exploring it and hijacking it, like some corporations, you are simply increasing time that someone need for reverse engineering, thats always quick with this thing. Good thing is, thats open source, everyone can see the code for something fishy, its transparent, user friendly, like difference in code between Windows and Linux, in Windows you have to know from random tests and guess, while on Linux you have to read, everything can be seen and modified, and if you lose your data, whole code or even a whole project can be extracted back from your final product that ended up who knows where on the internet.

Scripts are at the beginning used for small quick, performance critical parts, for example UI, but game industries moved to Flash UI in games, and started using scripts as bug fixes, like when bug happens, script thats running on loop will fix it, because its easier then going back in a big code, and it doesnt matter if someone read the code of calculating how many floating point bullets your flamethrower in game fire per 0.01ms with 20 decimal places, no one would be interested in that code anyway, and it still left developers easier way to change things, like fire rate, capacity, damage or so. Today scripts as whole softwares are being used as interpreters getting better. Both got their benefits that you probably already know, but today i think its simply profit and corporations.

This post has been edited by Radius Nightly: 22 March 2020 - 12:12 AM

Was This Post Helpful? 1
  • +
  • -

#8 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2768
  • View blog
  • Posts: 4,429
  • Joined: 21-June 11

Re: What is an interpreted language?

Posted 22 March 2020 - 05:01 AM

View PostO, on 22 March 2020 - 01:38 AM, said:

What is an interpreted language?


"Interpreted language" and "compiled language" aren't really well-defined terms, but the term "interpreted language" is usually used to refer to languages whose most commonly used implementation is an interpreter, though of course that's a property of the ecosystem more so than the language and may very well change over time, making the term kind of sketchy.

Of course that leads us to the distinction between interpreters and compilers, which can also be somewhat sketchy, as you point out:

Quote

HOWEVEEEER... While everyone is calling Python an interpreted language the Python interpreter (and more interpreted languages) actually also compiles the Python code to bytecode before executing it. Then why isn't Python considered a compiled language?


That's a very good point. I'd say the distinction is mostly about workflow: there is no pythonc command that you explicitly invoke before invoking python (but again that's just a property of the ecosystem, there's nothing preventing someone from writing such a tool and in fact it might very well exist already - it's just not the common workflow at the moment). As you say, build tools like cargo that can invoke the compiler and run the compiled program in a single command make this less clear again, but cargo still considers compilation and execution as different phases and makes this clear in its output, whereas python performs bytecode-compilation completely transparently.

Quote

Is the difference that the bytecode from Python is executed in. a kind of VM instead of directly on the processor? But what about Java then? That's also executed on a kind of VM.


There are probably some people who might consider Java an interpreted language for that reason, but that's not how the term is commonly used these days.


Quote

Maybe the difference between interpreted and compiled is rather a vague line


Definitely.

Quote

because in the end all code is compiled to zero and ones somehow?


That's not true. You can very well write an interpreter that executes code without translating it to machine code or byte code or any other binary format. Shells works that way, as did early BASIC interpreters. Even Ruby used an AST-walking interpreter (no bytecode and certainly no machine code - just parsing) until about the mid 00s. So translation to binary formats isn't necessary, it's just commonly done for performance.

Quote

And we as developers just use those terms to differentiate the different types of languages because they all serve a different purpose (interpreted languages being fast to write and scripty while compiled languages are more performance-oriented).


That's a good way to look at it, yes.


View Postjustawebuser, on 22 March 2020 - 08:04 AM, said:

interpreter executes the code immediately

No, It doesn't. It compiles and then executes it.

So what is the difference?

In Interpreted ones, the interpreter compiles and then runs the code line by line or section by section.


That's not true. First of all, as I said above, it's perfectly possible for an interpreter to not involve any type of compilation at all. Secondly it's very uncommon for an interpreter to work line-by-line. Interpreters that involve bytecode-compilation usually translate an entire file to bytecode before executing it.

You might be talking about JIT compilation (translating bytecode to machine code at runtime) which does often work on a section-by-section basis, but 1. many interpreters do not include JIT compilers and 2. those that do usually already execute code before compiling it (invoking the JIT compiler only after a given section of code has been executed a certain amount of times and relying on normal interpretation until then).
Was This Post Helpful? 3
  • +
  • -

#9 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 1027
  • View blog
  • Posts: 3,951
  • Joined: 13-June 14

Re: What is an interpreted language?

Posted 22 March 2020 - 05:59 AM

Personally, I don't care too much about the distinction these days, so I don't even bother to characterise languages that way. FWIW, I'm doing Scala at work and Clojure for personal projects. Both of these are running on the JVM and while our Scala code is explicitly compiled, I'm using Clojure at a REPL (much like I might use Python), so make of that what you will!
Was This Post Helpful? 1
  • +
  • -

#10 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7407
  • View blog
  • Posts: 24,986
  • Joined: 05-May 12

Re: What is an interpreted language?

Posted 22 March 2020 - 07:32 AM

And there is also Javascript. Traditionally, it used to be interpreted but most modern Javascript engines like Google's V8 compiles the Javascript into machine code ... and thereby exposing the speculative execution type CPU bugs via Javascript.
Was This Post Helpful? 1
  • +
  • -

#11 justawebuser   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 83
  • Joined: 09-February 14

Re: What is an interpreted language?

Posted 22 March 2020 - 07:37 AM

it's perfectly possible for an interpreter to not involve any type of compilation at all


Yes, Perfect and unlikely though. Every simple calculation needs to be processed. So it needs to be compiled. I can't think of any contemporary app that is simple enough to not process anything at the runtime.

Secondly it's very uncommon for an interpreter to work line-by-line

So it's very uncommon for it to not involve any type of compilation.

Do you think is there any way to run this simple piece of code without compiling and yet in an efficient way?

$imax=100;$kmax=100;$outout=0;
for($i=0;$i<$imax;$i++)
   for($k=0;$k<$kmax;$k++)
      $output+=$i*$k;
echo $output;



I don't think any wise interpreter would just run this code by itself.
If I would be an interpreter I would compile the first 4 lines then maybe run the fifth line without compiling it.

By the way, the "Compilation" phrase could be used for any type of compilation like a compilation of ActionScript to Java and etc..

If I'm confusing things any correction would be appreciated.
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7407
  • View blog
  • Posts: 24,986
  • Joined: 05-May 12

Re: What is an interpreted language?

Posted 22 March 2020 - 07:47 AM

View Postjustawebuser, on 22 March 2020 - 10:37 AM, said:

Yes, Perfect and unlikely though. Every simple calculation needs to be processed. So it needs to be compiled.

Are you absolutely sure about that? If so does that mean that CS teachers will stop giving their students assignments that involve evaluating simple expressions like: "12 + 23 * ( 7 - 2 )" in their data structures and algorithms classes? Does that mean that that CS students will have to wait until they go do their compiler construction classes before they will tackle evaluating that expression so that their compiler will generate compiled code?

View Postjustawebuser, on 22 March 2020 - 10:37 AM, said:

I can't think of any contemporary app that is simple enough to not process anything at the runtime.

Here's the source code for Microsoft's Calculator app. Can you help me find where it compiles the expressions to be evaluated into machine code and then executes that machine code to get the result?
Was This Post Helpful? 2
  • +
  • -

#13 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2768
  • View blog
  • Posts: 4,429
  • Joined: 21-June 11

Re: What is an interpreted language?

Posted 22 March 2020 - 07:51 AM

View Postjustawebuser, on 22 March 2020 - 03:37 PM, said:

it's perfectly possible for an interpreter to not involve any type of compilation at all


Yes, Perfect and unlikely though. Every simple calculation needs to be processed. So it needs to be compiled. I can't think of any contemporary app that is simple enough to not process anything at the runtime.


As I said, shells work that way.


Quote

Secondly it's very uncommon for an interpreter to work line-by-line

So it's very uncommon for it to not involve any type of compilation.


First of all, you don't need any type of compilation to not work line-by-line. An AST-walking interpreter does not work line-by-line and still does not involve any compilation (by which I mean translation to any sort of binary format - be it machine code or bytecode).

Second of all, my point was that your statement that interpreters work by compiling line-by-line was wrong even for those interpreters that do involve (bytecode or JIT) compilation.

Quote

Do you think is there any way to run this simple piece of code without compiling and yet in an efficient way?


As I said, most interpreters involve at least bytecode compilation exactly because it's more efficient. But it's not like shells are impossibly slow.
Was This Post Helpful? 1
  • +
  • -

#14 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7407
  • View blog
  • Posts: 24,986
  • Joined: 05-May 12

Re: What is an interpreted language?

Posted 22 March 2020 - 08:11 AM

View Postjustawebuser, on 22 March 2020 - 10:37 AM, said:

Do you think is there any way to run this simple piece of code without compiling and yet in an efficient way?

$imax=100;$kmax=100;$outout=0;
for($i=0;$i<$imax;$i++)
   for($k=0;$k<$kmax;$k++)
      $output+=$i*$k;
echo $output;



I don't think any wise interpreter would just run this code by itself.

As I recall BASIC (yes, one of those classic interpreted languages), would just happily run something like that without needing compilation. Since it tends to run slowly, it's how some people would build in delays into their games.
10 LET IMAX = 100
20 LET KMAX = 100
30 LET OUTPUT = 0
40 FOR I = 0 TO IMAX - 1
50 FOR K = 0 TO KMAX - 1
60 OUTPUT = OUTPUT + I * K
70 NEXT K
80 NEXT I
90 PRINT OUTPUT


Was This Post Helpful? 1
  • +
  • -

#15 justawebuser   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 83
  • Joined: 09-February 14

Re: What is an interpreted language?

Posted 22 March 2020 - 08:28 AM

Quote

does that mean that CS teachers will stop giving their students assignments that involve evaluating simple expressions like: "12 + 23 * ( 7 - 2 )" in their data structures and algorithms classes? Does that mean that CS students will have to wait until they go do their compiler construction classes before they will tackle evaluating that expression so that their compiler will generate compiled code?


I'm not saying the students should understand the compiler construction. Because I don't understand it my self either.
I'm saying the interpreter they're using should do it for them.

Quote

As I recall BASIC (yes, one of those classic interpreted languages), would just happily run something like that without needing compilation. Since it tends to run slowly, it's how some people would build in delays into their games.

LET IMAX = 100
LET KMAX = 100
LET OUTPUT = 0
FOR I = 0 TO IMAX - 1
FOR K = 0 TO KMAX - 1
OUTPUT = OUTPUT + I * K
NEXT K
NEXT I
PRINT OUTPUT


Just because your program runs fast or programmer needs to use delays doesn't mean the BASIC code or interpreter itself is efficient.

And the code you put there is just the BASIC equivalent of my PHP code. It doesn't say anything about the BASIC interpreter.

This post has been edited by justawebuser: 22 March 2020 - 08:34 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2