Uses for Dynamic Languages

前端 未结 13 1976
刺人心
刺人心 2021-01-02 11:14

My primary language right now is D, and I\'m in the process of learning Python because it\'s required for a course I\'m taking. While I understand why dynamic languages wou

13条回答
  •  自闭症患者
    2021-01-02 11:19

    Example in Python:

    def lengths(sequence):
        try:
            return sum(len(item) for item in sequence)
        except TypeError:
            return "Wolf among the sheep!"
    
    >>> lengths(["a", "b", "c", (1, 2, 3)])
    6
    >>> lengths( ("1", "2", 3) )
    'Wolf among the sheep!'
    

    How long do you think this took me to write, and how many compile-run-debug cycles?

    If you think my example is trivial, I can reply by saying that dynamic languages make trivial many programming tasks.

提交回复
热议问题