Uses for Dynamic Languages

前端 未结 13 1975
刺人心
刺人心 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:26

    I was going to say closures but found this thread... (not that I understand how it would work in a "static" language)

    Related concepts are functions-as-first-class-objects and higher-order procedures. (e.g. a function that takes a function as input and/or returns a function as output)

    edit: (for the nitpickers here) I'll echo a comment I made on @David Locke's post. Dynamically-interpreted languages make it possible to use an existing software program/project in conjunction with a small function or class created at the spur-of-the-moment to explore something interactively. Probably the best example is function graphing. If I wrote a function-graphing object with a graph(f,xmin,xmax) function, I could use it to explore functions like x2 or sin(x) or whatever. I do this in MATLAB all the time; it's interpreted and has anonymous functions (@(x) x^2) that can be constructed at the interpreter prompt to pass into higher-order functions (graphing functions, derivative operators, root finders, etc).

    0 讨论(0)
  • 2021-01-02 11:27

    In theory, there's nothing that dynamic languages can do and static languages can't. Smart people put a lot of work into making very good dynamic languages, leading to a perception at the moment that dynamic languages are ahead while static ones need to catch up.

    In time, this will swing the other way. Already various static languages have:

    • Generics, which make static types less stupid by letting it select the right type when objects are passed around, saving the programmer from having to cast it themselves

    • Type inference, which saves having to waste time on writing the stuff that should be obvious

    • Closures, which among many other things help to separate mechanism from intention, letting you pull together complicated algorithms from mostly existing ingredients.

    • Implicit conversions, which lets you simulate "monkey patching" without the risks it usually involves.

    • Code loading and easy programmatic access to the compiler, so users and third parties can script your program. Use with caution!

    • Syntaxes that are more conducive to the creation of Domain Specific Languages within them.

    ...and no doubt more to come. The dynamic movement has spawned some interesting developments in static language design, and we all benefit from the competition. I only hope more of these features make it to the mainstream.

    There's one place where I don't see the dominant dynamic language being replaced, and that's Javascript in the browser. There's just too much of an existing market to replace, so the emphasis seems to be towards making Javascript itself better instead.

    0 讨论(0)
  • 2021-01-02 11:28

    Here's Steve Yegge on the subject.

    Guido van Rossum also linked to that talk in his take of Scala.

    0 讨论(0)
  • 2021-01-02 11:36

    One big advantage of dynamic typing when using objects is that you don't need to use class hierarchies anymore when you want several classes to have the same interface - that's more or less what is called duck typing. Bad inheritance is very difficult to fix afterwards - this makes refactoring often harder than it is in a language like python.

    0 讨论(0)
  • 2021-01-02 11:39

    The point is that in a dynamic language you can implement the same functionality much quicker than in a statically typed one. Therefore the productivity is typically much higher.

    Things like templates or polymorphism in principle give you lots of flexibility, but you have to write a large amount of code to make it work. In a dynamic language this flexibility almost comes for free.

    So I think you look at the difference in the wrong way, productivity really is the main point here (just like garbage collection improves productivity, but otherwise does not really allow you to do new things).

    0 讨论(0)
  • 2021-01-02 11:39

    With a dynamic language it's much easier to have a command line interpreter so you can test things on the command line and don't have to worry about a compile step to see if they work.

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