如何衡量“可理解性”一种语言的?

发布于 2024-09-25 01:03:56 字数 199 浏览 6 评论 0原文

我经常读到一些编程语言比其他语言更清晰,我多次问自己是否有一种客观的方法来衡量一种语言的清晰度,以便在给定抽象语法的情况下设计出一种像这样清晰且人性化的具体语法可能的。也许存在某种用于此目的的设计模式?

简而言之:如何才能实现语法的最大清晰度?知道有什么方法可以量化语言的“清晰度”或“表达力”吗?

尝试衡量这些方面是否有意义?

谢谢。

I have often read that some programming languages are clear than others and I asked myself several times if there is an objective way to measure the clarity of a language in order to design, given an abstract syntax, a concrete syntax as clear and human friendly as possible. Perhaps exist some kind of designs patterns for that purpose?

In short: How can be achieved the maximum clarity of a syntax? Know any way to quantify the "clarity" or "expressiveness" of a language?

Makes sense to try to measure these aspects?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

不语却知心 2024-10-02 01:03:56

我已经多次听到这句话不经意地扔给不同的语言,不同的人会根据不同的标准选择不同的语言。

美丽的代码中,Yukihiro Matsumoto(Ruby 的设计者)争论了编写 Hello 是多么简单Ruby 中的世界程序比 Java 中的程序要好。尽管我不认为这个示例是为了扩展,但作者的观点是,您必须添加到代码中的繁琐内容反映了理解用该语言编写的程序的困难。也就是说,你受到的干扰越少,程序就越“可读”。

现在,根据我的经验,优秀的程序员会用他们编程所用的所有语言编写清晰的代码,甚至用他们更熟悉的语言编写更清晰的代码。作者的才华以及他在该语言方面丰富的经验最终使该语言本身的清晰度或表现力相形见绌。

另一点需要考虑的是可用库的数量和 API 的质量。如果您必须编写更少的“支持代码”来完成工作,那么生成的程序可能会更清晰,因为它看起来更直接切中要点。

I have heard this phrase too many times carelessly thrown at different languages, and different people will choose different languages based on different criteria.

In Beautiful Code, Yukihiro Matsumoto (Ruby's designer) makes an argument about how much simpler it is to write a Hello World program in Ruby than in Java. Although I don't think this example is meant to scale, the author's point is that the amount of cruft you have to add on to your code reflects the deficulty in understanding a program written in a that language. That is, the less distraction you get, the more "readable" the program is.

Now, in my experience, good programmers write clear code in all languages they program in, though even more clearly in languages they are more familiar with. The author's talent as well as the breadth of his experience in that lenguage end up dwarfing the language itself's clarity or expressiveness.

Another point to consider is the amount of available libraries and the quality of the APIs. If you have to write less "support code" to get the job done, then it's likely the resulting program is clearer because it appears more straight to the point.

败给现实 2024-10-02 01:03:56

有一些关于“自然编程”的研究,您可能会感兴趣:

http://www.cs.cmu.edu/~NatProg/index.html

他们尝试设计语言来满足人类的期望,而不是试图让人们遵循最简单的计算机语言。他们是基于实验。例如,当您指示他们“带回不是苹果或梨的东西”时,研究有多少人从水果盒中带回梨。 (我没有跟上他们的结果,但这听起来像是一个有前途的项目。)

尽管如此,“清晰度”和“表现力”仍然是难以衡量的模糊事物。当然,有一些研究可以对语言之间的相互进行定量测量,例如计算机语言基准游戏 。有些人从该游戏中提供的解决方案中获取了数据,并绘制了诸如“代码大小与性能”之类的趋势图:

http://blog.gmarceau.qc.ca/2009/05/speed-size-and-dependability-of.html

您也许可以关于通用语言的一些不稳定的基于度量的命题,基于有效执行给定任务所需的代码大小的趋势。但随后你就确定了“清晰度”和“表现力”的相当主观的概念。 (我倾向于认为,完成相同工作的时间较短的程序通常会更清晰,但有很多反例。)

因此,我想说,在没有明确的目标受众的情况下,您可以对测试对象进行可用性研究,对于语言的概括,你不会比这些类型的指标做得更好。

(注意:我喜欢 Rebol 并且我认为它有能力变得非常清晰和富有表现力......但是只有当您以某种方式使用它时,这涉及到开发 DSL 方言,但这并不是很多人在编程时的想法!)

There have been some studies in what is called "natural programming" which may be of interest to you:

http://www.cs.cmu.edu/~NatProg/index.html

They attempt to design languages to meet human expectations instead of trying to conform people to what's simplest for a computer. And they're basing it on experiments. For instance studying how many people bring back a pear from a box of fruit when you instruct them to "bring back something is not an apple or a pear". (I haven't kept up with their results, but it sounded like a promising project.)

Still, "clarity" and "expressiveness" are nebulous things to gauge. There are of course studies which do quantitative measure of languages against one another, like the Computer Language Benchmarks Game. Some people have taken data from solutions offered in that game and graphed trends like "code size vs. performance":

http://blog.gmarceau.qc.ca/2009/05/speed-size-and-dependability-of.html

You might be able to make some shaky metrics-based propositions about a general-purpose-language based on trends in code size it takes to perform a given task efficiently. But then you're pinning down fairly subjective notions of what "clarity" and "expressiveness" are. (I'm biased to believe shorter programs that do the same work faster are often clearer, but there are many counterexamples.)

So I'd say that in the absence of a defined target audience with which you can do usability studies with test subjects, you won't do much better than these kinds of metrics for making generalizations about languages.

(Note: I like Rebol and I think it has the power to be incredibly clear and expressive...but only if you use it a certain way which involves developing DSL dialects as you go, which is not the way a lot of people think when they program. Yet!)

三生殊途 2024-10-02 01:03:56

我认为不存在。清晰度是主观的,设计模式并不是衡量语言清晰度的好标准(事实上,设计模式通常是为了规避语言的限制而生的)。

有些人喜欢语义丰富简洁的语言(例如perl),并不介意符号的使用,而另一些人则喜欢类似于自然语言的语法,这样你看起来就像在与计算机交谈(例如Hypercard)并且不介意使用符号。真的不介意冗长或含糊不清。

I don't think there is. Clarity is subjective, and design patterns are not a good measure for clarity of a language (indeed, design pattern are usually born to circumvent the limitation of a language).

Some people likes a language with rich and concise semantic (e.g. perl) and doesn't really mind the use of symbols, while other prefers a syntax that resembles natural language, such that you appear to speak to the computer (e.g. Hypercard) and doesn't really mind the verbosity or the ambiguousness.

简单气质女生网名 2024-10-02 01:03:56

像这样的问题通常会得到迂腐的答案。

语言就像工具。

它们是为了满足某些目的而构建的。逻辑编程语言以比面向对象程序更优雅的方式解决某些问题。类似地,许多主流解决方案可以通过典型的面向对象或过程语言轻松完成。

工具用户(在这种情况下程序员)的气质和其他因素也很重要。有些人已经用 Perl 实现了漂亮的解决方案,但对我来说它总是像黑魔法。我更喜欢 Python 的结构简单性。对于某些人来说,使用空白是令人厌恶的。

如果可以对语言的清晰度和表现力进行评价,那充其量只是一个非常主观的评价。

然而,一个明显的迹象是该语言产生了大量的代码。有些语言如 Brainfuck 还没有被采用,而 Python、Ruby 等已经流行起来。虽然,这些和许多因素只能作为一个指标。有些语言尽管结构良好,但可能不会找到太多接受者。

网络效应也会影响语言的采用。

A question like this usually results in a pedantic answer.

Languages are like tools.

They are built to suit certain purposes. Logic programming language solve certain problems in a more elegant way than an object oriented program would. Similarly, many main stream solution are easily done by a typical object oriented or procedural language.

Temperament and other factors of the tool user, in this case a programmer also matters. Some folks have achieved nifty solutions in Perl but it has always looked like black magic to me. I prefer Python's structural simplicity. For some, it's use of white space has been abominable.

It would be at best a very subjective evaluation, if there can be an evaluation of a language clarity and expressivity.

How ever, a clear indication is wealth of code production in that language. Some language like brainfuck has not been adopted while Python, Ruby etc have gained popularity. Although, these and many factor can be an indicator only. Some language, despite good constructs may not find much takers.

Network effect also affect the language adoption.

鹊巢 2024-10-02 01:03:56

我发现 LOLCODE 是其中最容易理解的语言:

HAI
CAN HAS STDIO?
I HAS A VAR
IM IN YR LOOP
    UP VAR!!1
    VISIBLE VAR
    IZ VAR BIGGER THAN 10? KTHXBYE
IM OUTTA YR LOOP
KTHXBYE

I find LOLCODE to be the most understandable language of them all:

HAI
CAN HAS STDIO?
I HAS A VAR
IM IN YR LOOP
    UP VAR!!1
    VISIBLE VAR
    IZ VAR BIGGER THAN 10? KTHXBYE
IM OUTTA YR LOOP
KTHXBYE
可爱咩 2024-10-02 01:03:56

衡量一种语言的可理解性并不像衡量程序员的可理解性那么重要。

Measuring the understandability of a language is not as important as measuring the understandability of a programmer.

老子叫无熙 2024-10-02 01:03:56

您还可以查看由 RW Sebesta 撰写的最新版《编程语言概念》一书。本书有一章(第一章或第二章我不太记得了)讨论了评估编程语言的标准。

You can also look at the book "Concepts of Programming Languages" by Latest Edition, BY R. W. Sebesta. There is chapter in this book (chapter 1 or 2 I don't remember exactly) discuss criteria to evaluate a programming language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文