您如何用动态语言编写不同的程序? [英] How do you program differently in dynamic languages?

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

问题描述

真正了解如何利用动态编程语言的人与使用静态语言工作的人如何进行编程?

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'm familiar with the whole debate over static versus dynamic typing, but that's not what I'm getting at. I'd like to discuss problem solving techniques that are practical in dynamic languages but not in static languages.

我见过的大多数用动态编程语言编写的代码与用静态编程语言编写的代码没有太大区别.俗话说,您可以用任何语言编写FORTRAN,很多人都可以.但是有些人使用动态编程语言来解决问题,而这种方式很难转换成C ++.他们有什么技巧?

Most of the code I've seen written in dynamic programming languages isn't very different than code written in static programming languages. As the saying goes, you can write FORTRAN in any language, and many people do. But some people use dynamic programming languages to solve problems in a way that wouldn't easily translate into, for example, C++. What are some of their techniques?

有什么好的资源讨论如何使用动态编程语言?不是有关语言语法或API参考的书籍,而是有关利用动态语言功能的问题解决方法的资源.

What are some good resources that discuss how to use dynamic programming languages? Not books on language syntax or API reference, but resources on problem solving approaches that take advantage of dynamic language capabilities.

编辑(1/5/2009):我很欣赏下面的回答,但是它们似乎不能解释动态语言倡导者说的体验所带来的生产率的巨大提高.

EDIT (1/5/2009): I appreciate the answers below, but they don't seem to account for the huge increases in productivity that dynamic language advocates say they experience.

推荐答案

我喜欢苗条的答案.我确实在Java和C ++上花费了大量的时间来制作自定义数据结构,而这些数据在Python/Ruby中是免费的.并设计专门的功能来处理这些自定义数据结构.是的,在C ++中,STL非常好.是的,Java中的泛型很好.它们有助于更快地创建自定义数据结构,但是仍然需要大量的思考和考虑.

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.

但是,动态语言更易于使用是一个更根本的原因.这是一个很深的想法,被称为鸭子打字.上面的一些评论是关于鸭子类型的,但是请花一些时间来思考什么是鸭子类型.这是观察世界的根本不同的方式.与Java和C ++等语言不兼容的视图.

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

鸭子打字被证明是非常有用的. XML中的必须忽略"原则使XML在网络上如此重要和有用.但这只是鸭子输入的一个例子.

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.

最后,您可能想回到我的一篇很长的博客文章,其中我解释了鸭子的类型及其与AI和建模之类的关系:

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

这篇关于您如何用动态语言编写不同的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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