2

I first wondered why a language would store everything on the heap, when it has serious performance cost. For example, Java folks avoid creating unnecessary objects because the performance differences in using primitive types and objects are significant. but I found that languages like Python and Javascript, everything is an object and they are both interpreted and dynamically typed languages. So I wanted to know if the heap is the common ground for these languages.

trincot
  • 317,000
  • 35
  • 244
  • 286
Forethinker
  • 3,548
  • 4
  • 27
  • 48

1 Answers1

2

Yes and no. Yes, simple interpreters and bytecode compilers will store every object on the heap; CPython does that. No, there exist smart implementations of dynamic languages that can do escape analysis and convert some heap allocations to stack allocations.

Stalin does this for Scheme, PyPy does it for Python, and maybe there's a JavaScript implementation about that performs this optimization as well.

they are both interpreted and dynamically typed languages

Interpretation is not a feature of languages but of their implementations, as the Lisp community has shown decades ago. Python, in its reference implementation, is compiled to bytecode, just like Java.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • The last paragraph puzzled me at bit. What are you exactly referring to by saying "Lisp..."? – Forethinker Jun 03 '13 at 22:10
  • @Forethinker: the Lisp community has built all kinds of compilers and interpreters for their language and pioneered the idea of combining the two. In some interactive Lisp "interpreters" you can actually compile code on the fly, with full optimization. – Fred Foo Jun 04 '13 at 09:13