动态语言的用途 [英] Uses for Dynamic Languages

查看:76
本文介绍了动态语言的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在的主要语言是D,并且我正在学习Python,因为它是我所修课程的必需条件.虽然我了解了为什么动态语言会为使用静态语言进行编程的人们带来新鲜空气,而无需使用类型推断或模板(IMHO模板在很大程度上是编译时的鸭子输入),但我很好奇动态语言的好处即使你有那些.

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 would be a breath of fresh air for people programming in static languages without type inference or templates (IMHO templates are to a large extent compile-time duck typing), I'm curious what the benefits are of dynamic languages even when you have those.

最重要的是,如果我要学习Python,我想以一种真正改变我对编程思想的方式来学习它,而不仅仅是用Python编写D.自从我还是一名新手程序员以来,我就没有使用过动态语言,无法欣赏它们应该提供的灵活性,并想立即学习充分利用它们.

The bottom line is that, if I'm going to learn Python, I want to learn it in a way that really changes my thinking about programming, rather than just writing D in Python. I have not used dynamic languages since I was a fairly novice programmer and unable to appreciate the flexibility they supposedly offer, and want to learn to take full advantage of them now. What can be done easily/elegantly in a dynamically typed, interpreted language that's awkward or impossible in a static language, even with templates, polymorphism, static type inference, and maybe runtime reflection?

推荐答案

从理论上讲,动态语言无能为力,而静态语言则无能为力.精明的人为使非常好动态语言付出了很多工作,这使人们立即意识到动态语言是领先的,而静态语言则需要赶上.

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.

在一个地方,我看不到主要的动态语言被替换,那是浏览器中的Javascript.现有市场太多,无法替代,因此重点似乎在于使Javascript本身变得更好.

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.

这篇关于动态语言的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆