I have always heared that compile time languages (Java, C++ etc) are statically typed and interpreted languages (PHP, Python etc) are dynamically typed, But the question is why they are, Why not a compile time language can be dynamically type and vice versa?
Asked
Active
Viewed 70 times
0
-
1There are dynamic-typed languages that compile code. https://stackoverflow.com/questions/2555063/is-there-a-compiled-programming-language-with-dynamic-maybe-even-weak-typing – ernest_k Dec 19 '18 at 20:36
-
[Julia](https://julialang.org/), for example. – user2357112 Dec 19 '18 at 20:38
-
In other words, your premise is untrue. – martineau Dec 19 '18 at 21:02
-
Possible duplicate of [Is there a compiled\* programming language with dynamic, maybe even weak typing?](https://stackoverflow.com/questions/2555063/is-there-a-compiled-programming-language-with-dynamic-maybe-even-weak-typing) – Oleksii Filonenko Dec 19 '18 at 23:52
2 Answers
1
It's not really true. Java bytecodes can be interpreted, indeed they were only interpreted up until around JDK 1.1.5ish. JavaScript is often compiled.
However, an interpreter for a dynamic language is really easy to write. Perhaps try it. Statically typed languages are a bit more difficult, so you may as well compile it anyway. On the other hand, to reasonably compile a dynamic language takes some effort.

Tom Hawtin - tackline
- 145,806
- 30
- 211
- 305
1
This depends strictly on the language e.g. Java has mixed mode where the code that runs less often is only interpreted. Code compilation can be expensive so if the compiled code is not executed many times after the compilation the effort spent compiling will not be worth it.

Karol Dowbecki
- 43,645
- 9
- 78
- 111