How do you program differently in dynamic languages?

前端 未结 15 1831
南笙
南笙 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 03:53

    Dynamic Languages can change the object at run time, you can add methods, properties...

    One good example of Dynamic Languages magic is this Groovy code snippet which call a method on a webservice in just two lines of code:

    def proxy = new SoapClient("http://localhost:6980/MathServiceInterface?wsdl");
    def result = proxy.add(1.0, 2.0);
    

    This is another Groovy snippet that extract data from XML:

    def contacts = new XmlParser().parseText("Bahaa Zaid");
    def myName = contacts.name[0].text();
    

    You cannot do this in Static Languages. Dynamic Language can change the objects to reflect the actual runtime condition.

提交回复
热议问题