How do you program differently in dynamic languages?

前端 未结 15 1500
南笙
南笙 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:02

    In dynamic languages, I'm more experimental. It's easier to change things on the fly, so I can explore solutions faster.

    If I know what I want to do, and generally how to do it, I like C++. If I don't know how to do what I want to do, and likely am not entirely sure about what I want to do, I much prefer Lisp.

    0 讨论(0)
  • 2021-02-01 04:02

    John, just based on your update edit of 1/5/09, you might find AMOP an interesting read, and more on the line you're thinking of. It's pretty lisp-centric, but after all many of the good dynamic ideas started there. So if you can enjoy (or get past) that aspect, the authors do discuss the dynamic aspects needed and used to do something like this. It's pretty powerful stuff.

    0 讨论(0)
  • 2021-02-01 04:03

    Fast iterations make happier programmers, and they don't come any faster than an interactive interpreter. Good interpreter exploitation gives you sandbox, testing, and prototyping at the same time.

    Beware programming by permutation, however. My personal rule of thumb is that it's just because it works doesn't mean it's ready, when you can explain why it works it's ready.

    0 讨论(0)
  • 2021-02-01 04:10

    One way I typically find myself taking advantage of dynamic programming languages is in simplifying and clarifying syntax. If I'm representing a database, for example, the syntax I use for interacting with it can be much cleaner if I can dynamically load properties and methods on the database object for its tables, the tables and rows for their columns, and so on. The difference might be between:

    $row = $db->getTable('user')->getRow(27);
    $row->setValue('name', 'Bob');
    

    and

    $row = $db->user->getRow(27);
    $row->name = 'Bob';
    

    The 'visual noise savings' of the second form really starts to add up when you're doing complex things.

    0 讨论(0)
  • 2021-02-01 04:10

    I think the most dramatic difference in choice of data structures.

    In Java or C I define structs or classes very strictly. If I need to add a property, I go back and change the definition.

    In Perl I'll just use a hash, and 'invent' keys as I code.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题