ariya / ama

Ask me anything!
29 stars 1 forks source link

Is JavaScript a compiled or interpreted language? #31

Closed dnkolegov closed 6 years ago

dnkolegov commented 8 years ago

Here it is considered that JavaScript is a compiled language. Unfortunately the author does not explain this statement reasonably and does not describe details. It will be interested to know your point of view (more detailed and technical) on this question.

sukrosono commented 7 years ago

AFAIK it's interpreted language, here not listed or not yet listed. The term is somewhat vague. In principle, any language can be implemented with a compiler or with an interpreter. Yeah i want to hear his POV :smile:

dnkolegov commented 7 years ago

In principle, any language can be implemented with a compiler or with an interpreter.

In theory it is true, but what do we mean when we use term programming language? I think that a programming language is not only a vocabulary and set of grammatical rules. It should also include some mechanisms and attributes/properties.

Examples:

  1. Typing (weak, strong) is enforced by compiler (interpreter), but not a grammar.
  2. When we say C we mean speed. We can create interpreted version of C, but it will be another "language".
agauniyal commented 7 years ago

@dnkolegov Major implementations of javascript are compiled. About your points -

  1. There aren't weak/strong types because there is no proper definition for them. Though there are static and dynamic type systems and I've only seen people troubling themselves with weak/strong types because they wouldn't agree on a universal terminology.

  2. Languages themselves aren't compiled or interpreted, their implementations are. C++ is widely used as compiled language with gcc, clang, msvc, intel as popular compiler vendors. However, there are actively developed and used interpreters for C++ as well including the famous Cling developed by CERN org. This does not make C++ an entirely new language, though some performance is sacrificed for shiny features.

Also, a well-written, efficient algorithm written in js will always outperform a poorly designed one in C/C++ so it's not the language, but how many instructions you ultimately give to your microprocessor and how much time does it idles which makes some program faster or slower. Have a nice day 😄