什么编程语言最像英语?
我主要是一名Python程序员,它经常被描述为“可执行的伪代码”。我使用过一点AppleScript,这似乎是我见过的最像英语的编程语言,因为几乎运算符都可以是单词,并且它可以让你在任何地方使用“the”(例如,我刚刚的这个愚蠢的例子)想出了:
set the firstnumber to 1
set the secondnumber to 2
if the firstnumber is equal to the secondnumber then
set the sum to 5
end if
是一个有效的 AppleScript 程序吗?是否有比这些更类似于英语的编程语言?
I'm mainly a Python programmer, and it is often described as being "executable pseudo-code". I have used a little bit of AppleScript, which seems to be the most English-like programming language I have ever seen, because almost operators can be words, and it lets you use "the" anywhere (for example, this stupid example I just came up with:
set the firstnumber to 1
set the secondnumber to 2
if the firstnumber is equal to the secondnumber then
set the sum to 5
end if
is a valid AppleScript program. Are there any programming languages that are even more English-like than these?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
如果你的意思是规则应用不一致,有很多奇怪的边缘情况和尖角伤害学习者,那么很少有编程语言比 C++ 更像英语。
If you mean inconsistent in application of rules with lots of bizarre edge cases and sharp corners to injure the learner, there's very few programming languages more English-like than C++.
莎士比亚的回答让我想起了 Inform 7,这是一种用于编写交互式小说的严肃编程语言。它可能是现存最接近英语的语言,并且具有明确定义的语义。
以下是来自 Wikipedia 的示例:
该示例使用可供用户使用的广泛对象库。但该语言本身实际上是图灵完备的,您可以定义具有任何行为的对象。
The Shakespeare answer reminded me of Inform 7, which is a serious programming language for writing interactive fiction. It's probably the language most closest to English that exists and has a well-defined semantics.
Here is a sample from Wikipedia:
The sample uses an extensive library of objects which is available for user. But the language itself is in fact Turing complete, and you can define objects with any behaviour in it.
冒着成为愤怒的手指摇晃的风险:我声称类似自然语言对于编程语言来说是一个糟糕的目标。具体来说,自然语言表达的目标是影响世界,让其他人想要亲吻你而不是打你;这与编程语言话语的目标非常不同,编程语言话语的目的是在计算机或其他人可以评估的明确定义的领域中提供明确的陈述。更好的问题可能是:哪种编程语言最不容易意外搬起石头砸自己的脚?
...当然,这根本不是你问的。
At the risk of being a raging finger-wagger: I claim that natural-language-like is a bad goal for programming languages. Specifically, the goal of a natural language utterance is to influence the world so that other human beings want to kiss you rather than punch you; this is very different from the goal of a programming language utterance, which is intended as an unambiguous statement in a well-defined domain that a computer or another person can evaluate. A better question might be: which programming language makes it most difficult to accidentally shoot yourself in the foot?
... which is not at all what you asked, of course.
COBOL 一直被认为是非常“自然的语言”。以下是 99 瓶啤酒页面的摘录:
当然,“自然语言”并不总是(通常?)编程语言的优点,其中精确性是当今的秩序(自然语言几乎总是模棱两可的 - 添加编程语言所需的精确性只会使其变得冗长)。
COBOL was always considered pretty "natural language". Here's an extract from the 99 bottles of beer page:
Of course, "natural language" is not always (often?) a virtue amoung programming languages, where preciseness is the order of the day (and natural language is almost always ambiguous - adding the preciseness required by a programming languages just makes it verbose).
莎士比亚编程语言怎么样?这是“hello world”源代码的一部分,来自 wikipedia
:就像代码突出显示在这里不起作用一样。 :/
How about the Shakesspeare programming language. Here's a part of the "hello world" source, out of wikipedia:
Seems like code highlighting doesn't work here. :/
VB.NET(尽管您的 AppleScript 示例胜过 VB.NET)、SQL 或 COBOL(这种风格的来源)。 Lolcode 类似于“语言”,但我很高兴英语不喜欢它。
VB.NET
COBOL
SQL
Lolcode
VB.NET (though your AppleScript example beats VB.NET), SQL or COBOL (the source of this style). Lolcode is "language"-like but I'm glad English isn't like it.
VB.NET
COBOL
SQL
Lolcode
在查看了所有答案后,我确信 AppleScript 实际上是最自然的语言。
After reviewing all the answers, I'm convinced that AppleScript actually is the most natural language like.
您听说过超新星吗?它是一种自然的编程语言。即使您只需说“我想要窗口,窗口标题是你好”,也可以在 Supernova 中创建一个窗口。
Have you heard about Supernova. It's a natural programming language. Even you can create a window in Supernova by just saying
I want window and the window title is hello.
我讨厌插入自己的东西(其实不是),但是 7Basic 有一个非常类似英语的语法:
I hate to plug my own stuff (well not really) but 7Basic has a pretty english-like syntax:
我认为讨论 Dijkstra 式的编程精度在哪里是必要的,在哪里不需要,会很有趣。在需要细节的低级编程中,精度也很重要。由于编程原语的级别更高,也许没有那么多......
I think a discussion of where Dijkstra-like programmatic precision is necessary vs where it is not would be interesting. In lower level programming where detail is needed, so is precision. As programming primitives are higher level, perhaps not so much ...
也许是 Common Lisp? Lisp 中的宏允许您将抽象定义为“新词”。这与您想要的伪代码或英语非常接近(因为在我们的想法或讨论中描述程序时,我们使用了许多来自特定语言机制的抽象)。
一个有趣的例子是照应宏,Paul Graham 在他的《On Lisp》一书中对此进行了描述。照应宏是一个将某些表达式绑定到其体内的符号“it”的宏,因此我们可以轻松引用它:
在这一行中,获取数据是返回某个对象或返回 nil 的函数。如果它返回数据,它们将绑定到“it”变量,该变量由“do-something”函数处理。如果返回的数据为零,则不满足条件,并且不执行该子句。
还有许多其他照应宏的示例,例如绑定循环变量的 for 循环等。事实上,您甚至可以使用宏来为您生成照应宏。
Maybe Common Lisp? Macros in Lisp allow you to define abstractions as "new words". That's as close to pseudocode or English as you want to get (because when describing program in our thoughts or discussions, we use a lot of abstractions from the mechanics of particular language).
An interesting example are anaphoric macros, which Paul Graham describes in his book On Lisp. Anaphoric macro is a macro that binds some expression to the symbol "it" inside it's body, so we can easily refer to it:
In this line, the get-data is function which either returs some object or nil. If it returns the data, they are bind to "it" variable, which is the processed by "do-something" function. If the data returned are nil, the condition is not satisfied and the clause is not executed.
There are many other examples of anaphoric macros, like for loops, that bind the loop variable, and so on. In fact, you can even have macros that generate anaphoric macros for you.