本文介绍了使用“天然的"香精油更好吗?语言写代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近看到了一种叫做 supernova 的编程语言,他们在网页中说:

I recently saw a programming language called supernova and they said in the web page :

第一个提出了 直接小说编程 使用

First one presents the concept of programming with direct Fiction Description using

纯人类语言的清晰子集.

Clear subset of pure Human Language.

,您可以编写如下代码:

and you can write code like:

i want window and the window title is Hello World.
i want button and button caption is Close.
and button name is btn1.

btn1 mouse click. instructions are
   you close window
end of instructions

我的问题不是关于语言本身的问题,而是我们是否需要这种语言,它们是否使编写代码更容易?

my question is not about the language itself but it is that are we need such languages and did they make writing code easier or not?

推荐答案

代码可能看起来像自然语言,但实际上只是带有不同关键字的常规计算机代码.在您的示例中,I want可能与new同义.并不是说您可以直接使用自然语言并改为说make me a window(如果可以的话,事情会变得更加难看...).

The code may look like natural language, but it's really just regular computer code with different keywords. In your example, I want is probably synonymous with new. It's not like you can use natural language directly and say make me a window instead (and if you could, things would get even uglier...).

让我们仔细看看您的代码和语言含义:

Lets take a close look at your code and the language implications:

i want window and the window title is Hello World. 

i want表示newand表示参数列表的开头. the <type_name> <member_name> is在要创建的对象上设置实例变量member_name.请注意,您必须两次编写type_name.

i want means new, and denotes beginning of the argument list. the <type_name> <member_name> is sets instance variable member_name on the object being created. Note that you have to write the type_name twice.

i want button and button caption is Close.
and button name is btn1.

.结束一条语句.但是,您可以通过使用and开始下一条语句来链接"对象的方法调用.另外,如何引用名为Close的变量而不是字符串"Close"?哎呀,我们甚至用普通英语也遇到了这个问题:说您的名字"和说您的名字"之间有什么区别?

. ends a statement. However, you can 'chain' method calls on an object by starting the next statement with and. Also, how do you refer to a variable named Close instead of the string "Close"? Heck, we even have this problem in regular English: what the difference between 'Say your name' and 'Say "your name"'?

btn1 mouse click. instructions are
   you close window
end of instructions

mouse click是包含空格的标识符,应为mouseClick. instructions are定义了一个lambda(请参阅isare的关键字混淆是否引起了麻烦?). you close window调用window.close(). end of instructions是lambda的结尾.所有这些都比需要的更长.

mouse click is an identifier containing a space, should be mouseClick. instructions are defines a lambda (see the is vs. are keyword confusion causing trouble yet?). you close window calls window.close(). end of instructions is end of a lambda. All of these are longer than they need to be.

还记得所有这些吗?这些只是我对语法的猜测,这可能是完全错误的.看起来还简单吗?如果是这样,请尝试编写一个更大的程序,而不破坏任何那些规则以及其他规则,您需要定义诸如条件逻辑,循环,类,泛型,继承,或者您需要的其他任何东西.您要做的就是将常规编程语言中的符号更改为自然语言"等价物,这些等价物难以记住,不必要的冗长且更加含糊.

Remember all that? And those are only my guesses at the syntax, which could be completely wrong. Still seem simple? If so, try writing a larger program without breaking any of those rules, AND the additional rules you'll need to define things like conditional logic, loops, classes, generics, inheritance, or whatever else you'll need. All you're doing is changing the symbols in regular programming languages to 'natural language' equivalents that are harder to remember, unnecessarily verbose, and more ambiguous.

尝试翻译:

var myWindow = new Window( title="Hello World" );
myWindow.addButton( new Button( caption="Close", name="btn1" ) );

btn1.onMouseClick = function() {
    myWindow.close();
}

在前面的示例中,每行如何映射到对应的行,但是更直接地说明意图?自然语言可能对人类执行有好处,但是要使用精确的语言来描述则非常困难.

See how each line maps to its counterpart in the previous example, but states the intent more directly? Natural language may be good for execution by humans, but it is terribly difficult to use for precise specifications.

您越想让英语轻松而清晰地传达这些想法,它看起来就越像我们已经拥有的编程语言.简而言之,编程语言在不失去清晰度和简单性的情况下,尽可能接近自然语言. :D

The more you try to make English communicate these ideas easily and clearly, the more it's going to look like programming languages we already have. In short, programming languages are as close to natural language as we can get without losing clarity and simplicity. :D

这篇关于使用“天然的"香精油更好吗?语言写代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 23:45