Advantages of a VM
The majority of languages I have come across utilise a VM, or virtual
machine. Languages such as Java (the JVM), Python, Ruby, PHP (the HHVM),
etc.
Then there are languages such as C, C++, Haskell, etc. which compile
directly to native.
My question is, what is the advantage of using a VM (outside of
OS-independence)? Isn't using a VM just creating an extra interpretation
step, by going [source code -> bytecode -> native] instead of just [source
code -> native]?
Why use a VM when you can compile directly?
EDIT
My understanding is that Python, Ruby, et al. use something akin to a VM,
if not exactly fitting under such a definition, where scripts are compiled
to an intermediate representation (for Python, e.g. .pyc files).
EDIT 2
Yep. Looked it up. Python, Ruby and PHP all use intermediate
representations, but are simply not stored in seperate files but executed
by the VM directly. See question : Java "Virtual Machine" vs. Python
"Interpreter" parlance?
" Even though Python uses a virtual machine under the covers, from a
user's perspective, one can ignore this detail most of the time. "
No comments:
Post a Comment