Why are dynamically typed languages slow?

前端 未结 6 716
南笙
南笙 2020-12-23 22:49

What makes it hard to speed up dynamically typed languages when compared to statically typed languages . In other words what is inherent property of statically typed languag

6条回答
  •  死守一世寂寞
    2020-12-23 23:16

    Look at this python example:

    def fact(n):
        if n==0:
            return n
        return n*fact(n-1)
    

    What is n? Is it a number? Is it a String? Is it a class you defined earlier? There is no way for the compiler to know what input it will get. You have to do a lot of checking at run-time, which means that you are doing more implicit work for simple operations.

提交回复
热议问题