一切都是表达 [英] Everything is An Expression

查看:154
本文介绍了一切都是表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到许多语言,如Ruby和CofeeScript(以及转换编译器)都支持所有表达式。



现在它使语言变得简单易懂表面看起来很整洁,但我想看一些关于这两种方法的正面和负面的学术出版物。



如果出版物有清晰的例子,那将是有益的。比较了让所有东西都成为表达的好处,而不是,好吧,不是。



CoffeeScript vs Javascript中的例子会很好,但不是必需的。



这个概念绝对很酷,但我仍然不确定整个想法究竟是多么具有革命性(显然革命性的东西有点意见)。



谢谢!

解决方案

这本身没什么革命性的。 面向表达式的方法是函数式编程技术。



面向表达式的代码比面向语句的代码更简单,更简洁,因为作业并且没有明确的返回语句。表达式和命令之间缺乏区别可以实现概念统一(参见参考透明度)和自下而上结构。



<一些现代语言采用了函数式编程概念(例如C#, Python ,Ruby) 。


关于功能实践的好处的一些学术见解:





有趣的文章:




关于性能问题的评论,与范式选择相关的可能开销可能微不足道。即使在C语言中,大多数语句评估为表达式 - 但是,编译后的比较语言(C)和解释语言(CoffeeScript)相当无用。



理论上,命令式语言以更多面向机器的方式表示控制流程,这可以允许比功能语言更容易手动优化。



语言表现及其重要性在很大程度上取决于用例。关于JavaScript及其上的任何代码转换,这种性能讨论完全无关紧要。生产力的提升超过任何轻微的性能损失。


I've noticed many languages like Ruby and CofeeScript (well a transcompiler) support everything being an expression.

Now it makes the language somewhat simple to understand and definitely seems neat at the surface, but I was looking maybe for some scholarly publications about the positives and negatives of the two approaches.

It would be beneficial if the publications had clear examples that compared the benefits of having everything be an expression vs., well, not.

Examples in CoffeeScript vs Javascript would be nice, but not required.

The concept is definitely cool, but I'm still slightly unsure how revolutionary the whole idea really is (obviously something being revolutionary is somewhat an opinion).

Thanks!

解决方案

There is nothing revolutionary about this per se. The expression-oriented approach is a functional programming technique.

Expression-oriented code is simpler and less cluttered than statement-oriented code, because of fewer assignments and no explicit return statements. The lack of distinction between expressions and commands enables conceptual uniformity (see Referential transparency) and bottom-up structure.

Some modern languages have adopted functional programming concepts (e.g. C#, Python, Ruby).

Some scholarly insight on the benefits of functional practices:

Interesting articles:

As to the comment about performance concerns, the possible overhead related to choice of paradigm is probably negligible. Even in C, most statements evaluate as an expression - however, a comparison between a compiled language (C) and an interpreted language (CoffeeScript) is rather useless.

On a theoretical note, an imperative language represents the control flow in more of a machine-oriented way, which may allow for easier hand-optimization than a functional language.

Language performance and its significance depend heavily on the use case. Concerning JavaScript and whatever code transformation on top of it, this performance discussion is completely irrelevant. The gains in productivity outweigh any slight performance hit.

这篇关于一切都是表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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