人们对动态语言有什么吸引力? [英] What do people find so appealing about dynamic languages?

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

问题描述

似乎每个人最近都在使用动态的,未编译的潮流.我主要只使用编译的静态类型语言(C,Java,.Net)工作.我对动态语言的经验是诸如ASP(Vb脚本),JavaScript和PHP之类的东西.在考虑动态语言时,使用这些技术给我留下了不好的印象.编译器通常会捕获诸如拼写错误的变量名以及为变量分配错误类型的值之类的东西,直到运行时才发生.即使那样,您可能也不会注意到错误,因为它只是创建了一个新变量,并分配了一些默认值.我也从未见过intellisense在动态语言中能很好地发挥作用,因为变量没有任何显式类型.

It seems that everybody is jumping on the dynamic, non-compiled bandwagon lately. I've mostly only worked in compiled, static typed languages (C, Java, .Net). The experience I have with dynamic languages is stuff like ASP (Vb Script), JavaScript, and PHP. Using these technologies has left a bad taste in my mouth when thinking about dynamic languages. Things that usually would have been caught by the compiler such as misspelled variable names and assigning an value of the wrong type to a variable don't occur until runtime. And even then, you may not notice an error, as it just creates a new variable, and assigns some default value. I've also never seen intellisense work well in a dynamic language, since, well, variables don't have any explicit type.

我想知道的是,人们发现动态语言如此吸引人吗?就动态语言允许您完成的事情或在编译语言中很难做到的事情而言,主要优势是什么?在我看来,我们早就决定了,诸如未编译的ASP页面引发运行时异常之类的事情是一个坏主意.为什么会有这种类型的代码复活?至少在我看来,为什么Ruby on Rails看起来真的不像十年前用ASP无法完成的任何事情?

What I want to know is, what people find so appealing about dynamic languages? What are the main advantages in terms of things that dynamic languages allow you to do that can't be done, or are difficult to do in compiled languages. It seems to me that we decided a long time ago, that things like uncompiled asp pages throwing runtime exceptions was a bad idea. Why is there is a resurgence of this type of code? And why does it seem to me at least, that Ruby on Rails doesn't really look like anything you couldn't have done with ASP 10 years ago?

推荐答案

我认为原因是人们习惯了具有非常有限且缺乏表现力的类型系统的静态类型语言.这些是Java,C ++,Pascal等语言,它们不再朝着更具表现力的类型系统和更好的类型推断的方向发展(例如在Haskell中,甚至在某种程度上甚至是SQL),有些人喜欢保持所有类型"信息都在他们的头脑中(以及在他们的测试中),并且完全消除了静态类型检查.

I think the reason is that people are used to statically typed languages that have very limited and inexpressive type systems. These are languages like Java, C++, Pascal, etc. Instead of going in the direction of more expressive type systems and better type inference, (as in Haskell, for example, and even SQL to some extent), some people like to just keep all the "type" information in their head (and in their tests) and do away with static typechecking altogether.

这最终能为您带来什么还不清楚.关于类型检查的概念有很多误解,我最常遇到的是这两个.

What this buys you in the end is unclear. There are many misconceived notions about typechecking, the ones I most commonly come across are these two.

虚假性:动态语言不太复杂.误解是类型信息等于类型注释.这是完全不正确的.我们都知道类型注释很烦人.机器应该能够弄清楚这些东西.实际上,在现代编译器中也是如此.这是两行Haskell(来自 haskell.org )的静态类型的QuickSort:

Fallacy: Dynamic languages are less verbose. The misconception is that type information equals type annotation. This is totally untrue. We all know that type annotation is annoying. The machine should be able to figure that stuff out. And in fact, it does in modern compilers. Here is a statically typed QuickSort in two lines of Haskell (from haskell.org):

qsort []     = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)

这是LISP中的动态类型的QuickSort(来自 swisspig.net ) :

And here is a dynamically typed QuickSort in LISP (from swisspig.net):

(defun quicksort (lis) (if (null lis) nil
  (let* ((x (car lis)) (r (cdr lis)) (fn (lambda (a) (< a x))))
    (append (quicksort (remove-if-not fn r)) (list x)
      (quicksort (remove-if fn r))))))

Haskell示例伪造了静态键入的假设,因此冗长. LISP示例伪造了假设冗长,因此是静态类型的.打字和冗长之间的任何方向都没有关系.您可以放心地将其排除在外.

The Haskell example falsifies the hypothesis statically typed, therefore verbose. The LISP example falsifies the hypothesis verbose, therefore statically typed. There is no implication in either direction between typing and verbosity. You can safely put that out of your mind.

虚假性:必须编译静态类型的语言,而不是对其进行解释.同样,这不是事实.许多静态类型的语言都有解释器.有Scala解释器,Haskell的GHCi和Hugs解释器,当然,SQL是静态类型的,而且解释的时间比我还活着的时间长.

Fallacy: Statically typed languages have to be compiled, not interpreted. Again, not true. Many statically typed languages have interpreters. There's the Scala interpreter, The GHCi and Hugs interpreters for Haskell, and of course SQL has been both statically typed and interpreted for longer than I've been alive.

您知道,也许充满活力的人群只是希望自由而不必对自己在做什么进行认真思考.该软件可能不正确或功能强大,但不一定必须如此.

You know, maybe the dynamic crowd just wants freedom to not have to think as carefully about what they're doing. The software might not be correct or robust, but maybe it doesn't have to be.

我个人认为,那些放弃类型安全而获得一点暂时自由的人既不应该享有自由,也不应该拥有类型安全.

Personally, I think that those who would give up type safety to purchase a little temporary liberty, deserve neither liberty nor type safety.

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

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