Home > database >  Dart is compiled or interpreted language?
Dart is compiled or interpreted language?

Time:09-30

I've searched a lot on the internet about if Dart is a compiled or interpreted language, also I searched in the documentation and didn't get a clear answer about if Dart is compiled or interpreted or both, and how that works

CodePudding user response:

Yes!

The concepts of "compiled language" and "interpreted language" are not well defined.

Dart is definitely compiled in some cases. Say, when compiling to JavaScript for the web. That translates the program to a program in a different language, while preserving runtime behavior, which is the definition of compilation. (So "compilation" is well defined!)

To be pedantic, languages are not inherently compiled or interpreted. Implementations of languages may compiling or interpreting.

When running Dart on the native VM, directly from source code, it looks very much interpreted. But "interpretation" is a much mushier concept than compilation. The only thing which is fundamentally and unequivocally interpretation is executing code directly by interpreting the source code, with no intermediate representation. Nobody does that, not since BASIC. It's just too inefficient.

These days, you at least convert the source code to an abstract syntax tree. That's technically a compilation (converts a program from one representation to another, while preserving semantics). Then you might compile to a different internal representation. Maybe to byte code. Maybe even to native code. Sometimes you do all of these, doing just-in-time compilation to the next level when optimization calls for it.

The Dart VM compiles source code, through a number of steps, into native machine code. (Which is then interpreted by the CPU.)

Whether that counts as "interpretation" or not is really a philosophical question. From the outside, it matches one of the definitions of interpretation ("program goes in, runtime behavior occurs", as opposed to compilation which is "program goes in, other program comes out"). Internally, the VM is very much considering itself a compiler.

  •  Tags:  
  • dart
  • Related