title: Advantages of a VM
body: <p>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. </p>
  
  <p>Then there are languages such as C, C++, Haskell, etc. which compile directly to native. </p>
  
  <p>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]?</p>
  
  <p>Why use a VM when you can compile directly?</p>
  
  <p><em>EDIT</em></p>
  
  <p>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).</p>
  
  <p><em>EDIT 2</em> </p>
  
  <p>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 : <a href="https://stackoverflow.com/questions/441824/java-virtual-machine-vs-python-interpreter-parlance">Java &quot;Virtual Machine&quot; vs. Python &quot;Interpreter&quot; parlance?</a></p>
  
  <blockquote>
    <p>" Even though Python uses a virtual machine under the covers, from a
    user's perspective, one can ignore this detail most of the time. "</p>
  </blockquote>