7

I'm now learning Perl. What are the pros and cons of the interpreted languages?

nbro
  • 15,395
  • 32
  • 113
  • 196
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

9 Answers9

17

Blatant copy from wikipedia so I'll make this community wiki.

Advantages of interpreted languages

Interpreted languages give programs certain extra flexibility over compiled languages. Features that are easier to implement in interpreters than in compilers include (but are not limited to):

  • platform independence (Java's byte code, for example)
  • reflection and reflective usage of the evaluator (e.g. a first-order eval function)
  • dynamic typing
  • ease of debugging (it is easier to get source code information in interpreted languages)
  • small program size (since interpreted languages have flexibility to choose instruction code)
  • dynamic scoping
  • automatic memory management

Disadvantages of interpreted languages

An execution by an interpreter is usually much less efficient than regular program execution. It happens because either every instruction should pass an interpretation at runtime or as in newer implementations, the code has to be compiled to an intermediate representation before every execution. The virtual machine is a partial solution to the performance issue as the defined intermediate-language is much closer to machine language and thus easier to be translated at run-time. Another disadvantage is the need for an interpreter on the local machine to make the execution possible.

nbro
  • 15,395
  • 32
  • 113
  • 196
Nifle
  • 11,745
  • 10
  • 75
  • 100
6

Pros:

  • Rapid prototyping (no write, compile, execute cycle)
  • Cross-platform (assuming interpreters exist for each platform)

Cons:

  • Performance (won't be as fast as compiled languages)
tscho
  • 211
  • 2
  • 7
2

Biggest drawback? Most would say execution speed, but isn't always necessarily true. Most modern interpreted languages these days convert the files to be interpreted into an intermediate state upon building, which when executed is turned into machine code just as any other language. With clever caching being mostly prevalent within these language VMs these days, it shouldn't be too much of an issue. This is certainly not to say that performance is not an issue with interpreted languages, just that it is often not as bad as most would suggest.

Keep in mind that even with the performance problems though, it is often easier to achieve the same tasks as a compiled language in less and more efficient code, making the performance loss during compilation negligible over the execution time of a program.

Personally for me, the biggest drawback is the need for the interpreter to always be present before execution can occur. This quite often reduces portability, especially because interpreted languages aren't always cross platform.

Nathan Kleyn
  • 5,103
  • 3
  • 32
  • 49
  • 1
    "which when executed is turned into bytecode just as any other language" Natively compiled and executed code (typical of languages like C and C++ (non .NET)) does not involve bytecode. – Pulseczar Jun 07 '16 at 16:12
  • @Pulseczar Sorry, you're quite right, that's a mistake which I've edited - I meant "machine code". The "intermediate state" I referred is what is often bytecode. – Nathan Kleyn Jun 08 '16 at 11:25
  • "Personally for me, the biggest drawback is the need for the interpreter to always be present before execution can occur." What does this mean? Please guide. – Supriya Bhide Jun 15 '22 at 13:39
  • @SupriyaBhide Ah sorry — basically I mean that it would be required to have installed the interpreter (eg. Node, Ruby, Python) before you can run the code for an interpreted language. In comparison, a compiled language does not require this — you can run a Rust/C/C++ program without installing the language itself. This can be a security risk, and adds bloat to your runtime environment. – Nathan Kleyn Jun 17 '22 at 10:53
1

Con:

  • The biggest drawback is probably execution speed

Pro:

  • The biggest upside is probably turn-around time i.e. code-test iteration loop
jldupont
  • 93,734
  • 56
  • 203
  • 318
1

To put for the obvious and broad point, compiled languages tend to have higher performance than interpreted ones, since compiling precludes the need for a runtime interpreter.

Compiled languages are more suitable for commercial desktop software, since the source code is not shipped along with it.

Interpreted languages tend to be a bit quicker to learn, insofar as they allow you to quickly edit/run/repeat without waiting on a compiler. In my experience they also tend to be higher-level, which makes them easier as well.

Adam Bard
  • 1,693
  • 1
  • 11
  • 17
0

Wikipedia has a page on the advantages and disadvantages. Any significantly advanced interpreted language can be actual compiled into a native binary thus blurring the lines between the pro's and cons of an interpreted language.

PERL is one of those languages which blurs the lines. Whilst its famous for being a powerful scripting language, you could compile it to be native.

Andrew Keith
  • 7,515
  • 1
  • 25
  • 41
0

The "slowness" of Dynamic Languages such as PERL may not be an issue any longer. Here is an excellent presentation on the latest trends in the Dynamic Language area:

http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html

srini.venigalla
  • 5,137
  • 1
  • 18
  • 29
0

As java is interpreted language

Pros:

  • Compatibility: Java virtual machine approves this concept "Write once, run everywhere."
  • Security: The program running in JVM so if any failure happens this not affects on operating systems files.
  • Memory management.

Cons:

  • Java virtual machine has many implementations, for example when writing a program that uses Java 8 features this program must run on JVM with 8 version not less.
Mohamed Ali
  • 103
  • 2
  • 7
  • Your first statement might need rephrasing. Java is a compiled language, but the byte code generated by java compiler is interpreted by JVM. – Vijay Purush Jan 28 '23 at 11:18
0

The significant benefit of an interpreted language is that it does not have to be compiled for each hardware target separately.

The disadvantage is that it makes the code execution slower.

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53