注册 登录
中国红客联盟 返回首页

毁灭_perish的个人空间 http://www.cnhonkerarmy.com/?837563 [收藏] [复制] [分享] [RSS]

日志

Programming Languages: More Powerful with Less Freedom?

热度 6已有 1331 次阅读2016-9-4 10:32 | Freedom

in quest for more power, C# has recently been grown with new features and Java might follow soon the same path. While extending the choice of features provides programmer with more freedom, does this necessarily provide more power? And does a language need to offer a lot of freedom and flexibility to be genuinely powerful? 

Reg Braithwaite believes that this is not necessarily true. In response to Azubuko Obele’s statement that “people who argue for languages with more power are actually arguing for less rules”, Braithwaite asserts that there is no causal relationship between power and freedom even though the two are correlated in many languages, e.g. Ruby. According to Reg, Python is “a considerably more powerful language than Java” even though both are “built with the philosophy that removing certain programmer freedoms would produce better programs”. In Python, features were not rejected simply because they could be potentially misused but rather when they were judged unnecessary, either because there were already “a perfectly serviceable way” to achieve the desired outcome or because they concerned things “that don’t matter, like indentation”. And this approach did not prevent from adding new features to the languages if those could “fit within Python’s style and design æsthetic”.  

Some functional languages also impose strict rules, which does not mean they offer less power: 

Haskell is quite possibly the most extremely limiting language in common use: there is one way to do everything, mathematically pure functional programming. You have strong, expressive static typing 

[…] 

Likewise, the Factor programming language imposes a single, constraining set of rules on the programmer: programmers switching to Factor must relinquish their local variables to gain Factor’s higher-order programming power.

Hence, Reg argues that “languages can provide more power while also providing more rules and, paradoxically, less freedom.” What really matters, according to him, is careful design that follows a guiding philosophy and brings coherence into the language. The languages can then provide more power by letting programmer achieve more with less and it can be grown without “throwing more [often unrelated] features on top of the pile”:

Good design in every field accomplishes the “antigravity” trick of accomplishing more with less. With poor design, adding new power requires adding more check boxes, more features, more ways to do things that interact with each other unexpectedly.

While sharing Braithwaite’s opinion that power and freedom are not necessarily correlated, one of commentators, Daniel, argues that power of a language does not depend on rules it imposes on programmers but on “computer language "theorems" it provides: 

A computer language is not akin to rules, but akin to mathematics. […] So, compare it to algebra. The more theorems you have, the more powerful you are. Are theorems freedom? Not, of course not. Theorems are fundamental truths that can be combined to more easily achieve further results.

According to Daniel, what makes the difference between languages is to which extent theorems they provide are constructs that are easy for human minds to deal with: 

For instance, in machine code there is no "for" loop as most of us would understand them. What you have are conditional jumps based on CPU flags. 

But from that we developed a very useful construct, which is the "for" loop.
Now, even though the "for" loop is a very powerful construct, it is often prone to misuse. Few people can really truly simulate in their minds a "for" loop, so errors in that construct are not uncommon. 

Now, a "foreach" (list iterator or mapper) construct might not be as flexible as a "for" construct, but it is easier for us to understand.

Daniel advocates for using such easy to understand constructs because this limits the risk of misusing them and makes a language more “prone to correct programs”. Even though these constructs can be “powerful and easy to use at the same time”, this is not always the case and some “theorems” prone to be misused are actually more powerful. Hence, not only is there no direct correlation between freedom and power, but one may need to renounce to some power in the name of code quality.  

In spite of underlying conceptual difference, these two approaches don’t oppose each other. Based on arguments of both Reg and Daniel, one could argue that to be genuinely powerful, a language needs to have a carefully conceived design that guarantees the coherence of different features and to offer constructs that make sense for humans in order to limit the risk of misuse and to rise the quality of code.



C#最近一直在增加新特性以变得更加强大,Java也在步其后尘。当它向开发者提供更多的自由时,其是否会变得越来越强呢?一种语言是否需要提供高度的自由和灵活性才能变得强大?

  Reg Braithwaite深信未必如此。在回应Azubuko Obele的论调“希望语言变得强大的人们实际上是希望有更多的自由”时,Braithwaite声称强大与自由之间根本没有因果关系,即使在很多语言中这两者都是相互关联的,比如Ruby。根据Reg所述,Python是“一个比Java强大的多的语言”,尽管这两者都是“根据如下哲学构建的:适当去除开发者的自由会生成更好的程序”。在Python中,特性之所以被去除不是因为他们可能被误用,而是由于他们被认为是不必要的。这既可能是因为已经存在了“一个完美的方案”来获得期望的结果,也可能是因为这些特性关心的是“不重要”的东西,比如“缩进”。但是如果这些特性能“适合 Python的风格和设计艺术”,这种方式并不会阻止向语言中增加新的特性。

  
以下是引用片段:
一些函数式语言也增加了严格的规则,但这并不意味着他们就不强大:通常情况下,Haskell可能是限制最严格的语言:一种方式可以做所有的事情,这就是数学上纯函数式语言。你有强大、富有表现力的静态类型
  […]
  同样,Factor编程语言对开发者施加了一种单一的约束规则集:转向Factor的开发者必须放弃本地变量以获得Factor的更高层次的编程能力。

  因此,Reg认为“语言可以提供更强功能的同时也(自相矛盾地)提供了更多的规则以及更少的自由”。按照他的说法,真正重要的事情是遵循指导理念而且保持语言一致性的精心设计。那么语言就能以事半功倍的效果提供更多的能力,同时它还可以不断成长而不会“抛出更多[通常是不相关的]的特性”。

   
以下是引用片段:
在任何领域,好的设计都会做到事半功倍。而在差的设计下,增加新的能力将需要添加更多的检查框、更多的特性、更多的做事方法(彼此间还会产生干扰)。

  在分享Braithwaite的能力与自由并没有必然联系的观点时,评论员之一Daniel认为一种语言的能力不依赖于它施加到开发者上的规则,而是依赖于它所提供的“计算机语言定理”:

 

以下是引用片段:
 计算机语言并不类似于规则,而是类似于数学。[…]所以可以将其与代数相比。你拥有的定理越多,你就会变得更强大。定理是自由的吗?当然不是。定理是基本的原理,我们可以将其组合起来以获得更多的成果。

  根据Daniel所述,造成语言之间差异性的原因在于他们所提供的定理在多大程度上是人脑便于处理的结构:

以下是引用片段:
例如,机器码中并没有我们所熟知的“for”循环。你可以使用的仅仅是基于CPU标志的条件跳转。
  然而由此我们发明了一个非常有用的结构,这就是“for”循环。
  现在,尽管“for”循环是一个非常强大的结构,但它也经常被滥用。很少有人真正能在他们脑子中模拟“for”循环,因此该结构中的错误不胜枚举。
  现在,“foreach”(list iterator或者mapper)结构可能不像“for”结构那样灵活,但它更容易理解。
  Daniel提倡使用这种容易理解的结构,因为它降低了误用的风险并且使得语言更加“容易编写出正确的程序”。尽管这些结构可能“既强大又易用”,但事实并非总是如此,一些容易被误用的“定理”实际上更加强大。所以,自由与强大之间不但没有必然联系,而且我们很有可能为了代码质量而放弃一些强大的功能。

  如果不考虑概念上的差异,这两种方式并不是截然对立的。基于Reg和Daniel的论点,我们可以得出如下结论:语言需要精心设计以保证不同特性之间的一致性,并且提供对人脑有意义的结构来降低误用的风险以及提升代码质量,这样的语言才是真正强大的语言


发表评论 评论 (5 个评论)

回复 风的低语 2017-8-25 10:09
每一门语言都有他独有的特性
回复 Ariza 2018-3-20 00:07
回复 BLSP 2018-8-20 18:39
我还是第一次看到这么多英文的日志,自叹不如,继续努力
回复 沉默的某人 2018-8-20 23:40
Basically,it depends on the programmer,as we are unable to tell or justify by our views.
回复 shizherusifu 2019-9-23 21:59
加油 努力奋斗   这篇英文翻译完毕

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

红盟社区--中国红客联盟 

Processed in 0.088202 second(s), 8 queries.

站点统计| 举报| Archiver| 手机版| 黑屋 |   

Powered by HUC © 2001-2017 Comsenz Inc.

手机扫我进入移动触屏客户端

关注我们可获取更多热点资讯

Honor accompaniments. theme macfee

返回顶部