How do you program differently in dynamic languages?

前端 未结 15 1556
南笙
南笙 2021-02-01 03:37

How would someone who really knows how to take advantage of dynamic programming languages approach programming differently than someone working in a static language?

I

15条回答
  •  一个人的身影
    2021-02-01 04:12

    I like slim's answer. I do spend a crazy amount of time in Java and C++ crafting custom data structures that are just free in Python/Ruby. And crafting specialized functions to process these custom data structures. Yes, in C++, STL is really nice. Yes, Generics in Java are nice. They help create custom data structures much faster, however they still require a lot of thought and consideration.

    However, there is a more fundamental reason why dynamic languages are easier to work with. It is a deep idea which is called duck typing. Some comments above refer to duck typing, but please take time to reflect on what duck typing is. It is a fundamentally different way to view the world. A view that is incompatible with languages like Java and C++.

    Duck typing means that you waste not time in defining what a duck is. By not having to formally define your objects you save a lot of time and energy. Getting definitions right is hard. Have a look at this blog post of mine where I give examples: Formal definitions are less useful than you think

    Duck typing has proven extremely useful. The "Must Ignore" principle in XML is what has made XML so significant and useful on the web. But that's just an instance of duck typing.

    Another way to express duck typing is by the Web mantra "Be strict in what you send, generous in what you accept". That is also a very fundamental idea.

    Finally, you may want to back to a long blog post of mine where I explain duck typing and how it relates to things like AI and modelling: Duck Typing, Artificial Intelligence and Philosophy

提交回复
热议问题