您自己的编程语言是什么样的?
您自己的(我认为是完美的)编程语言会是什么样子? 举一个小例子并解释你的新颖想法!
我对语法真的很感兴趣。
What would your own (I assume perfect) programming language look like? Give a small example and explain your novel ideas!
I'm really interested in the syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(25)
它将是机器可读/可写的,并且将由接受语音指令的智能软件编写。
It would be machine readable/writeable, and it would be written by intelligent software that takes instructions by voice.
唔。 这是困难的一个。 我的口味倾向于易于人类理解和轻型脚本风格的语言(尽管我确实相信这可以适用于较大的应用程序)。 看代码片段:
Hmm. this is a tough one. My tastes run towards the easily human understandable, and light scripting-style languages (though i do believe this could work for larger apps). See code snippet:
我希望看到一个函数能够包含任意数量的引用参数并将它们传递给嵌套函数调用的工具。 在 .net 中,可以通过类似的方式对任何固定数量的通用参数执行此操作(显示两个额外参数版本):
我的首选语法如下:
其中“...”将自动扩展由编译器以任何适当的方式。 这样的工具使得在许多情况下使用 Lambda 成为可能,而不必生成闭包实例,并且还可以执行如下代码:
编译器可以将其重写为类似于:
请注意,因为 lambda 表达式不会使用除了作为 ref 参数传递的实例成员或变量之外的任何实例成员或变量,它都可以作为静态函数实现,并且不需要生成闭包。
I would like to see a facility for a function to include an arbitrary number of by-reference parameters and pass them through to a nested function call. In .net, one could do this for any fixed number of generic parameters, via something like (two-extra-parameters version shown):
My preferred syntax would be something like:
where the "..."'s would automatically be expanded by the compiler in whatever fashion would be appropriate. Such a facility would make it possible to use Lambdas in many situations without having to generate closure instances, and would also make it possible to do code like:
which the compiler could rewrite as something akin to:
Note that because the lambda expression would not use any instance members or variables other than those passed as ref parameters, it could be implemented as a static function and would not need to generate a closure.
有点神秘,但这就是我想要的:
A little cryptic, but this is what i'd like:
Jon 说得对,“不同的任务适合不同的语言和范式。” 然而,有一些考虑因素在很大程度上与领域无关。 这些主要涉及语法,但由于代码的阅读次数多于编写次数,我实际上认为语法很重要。
一方面,许多语言都犯了错误,基于 C 的语法是完全任意的。C 实际上有一种非常糟糕的语法。 我只举两个例子。
第一个是没有争议的:分号是不必要的。 采取以下代码; 语法完全明确并且易于编译器解析。 分号和显式续行都不是必需的。
这实际上与 Python 非常相似,但更加宽松:
fraction
的定义跨越多行。 这是合乎逻辑的,因为第一行尚未完成。我必须选择类似 C 语法的另一个要点是它们很大程度上隐式的变量声明。 他们没有明确宣布“我正在声明一个
Foo
类型的变量
”,而是羞涩地低声说道“Foo var
”。 由于在大多数情况下Foo
甚至不是保留字,因此此处不会向程序员提供任何视觉提示。 我更喜欢 VB 的显式Dim var As Foo
,尽管这里使用的关键字非常暗淡。(C++ 实际上让事情变得更糟,因为它引入了许多几乎相同且常常模糊的语法,这些语法意味着从变量初始化到函数声明完全不同的东西)。
我的语言必须具备的另一件事是静态类型。 确实,动态类型有它的用途,但它们非常罕见。 即使大多数“脚本语言”也并不真正需要它们。 我认为这经常与具有更多用途的隐式类型相混淆。 再次以 Python 为例。 为什么它不提供静态类型? 它已经是强类型的,静态类型检查只会是随之而来的,并且会减少相当多的调试。 显式变量声明也是如此。 我看不出隐含变量声明有什么优点。
所以我们已经有了一种语言的轮廓:
类型此外,我非常喜欢某些 C++ 概念,例如通用模板、RAII(即避免垃圾而不是收集垃圾)、不变性以及通过迭代器定义的值范围的概念。 我在其他地方说过,我相信迭代器是有史以来最基本的创新之一。 给他们一点口红,你甚至不会认出 C++ 这个丑陋的野兽:
而不是
当然,我知道许多语言都提供了上述语法。 但它们都只提供了 C++ 强大迭代器概念的简化版本(用 C++ 术语来说,大多数语言所知道的唯一迭代器是输入迭代器,它基本上是最不强大的迭代器)。
在这一点上,我可能应该说,所有这些想法的唯一版权都是我的,正在申请专利(特别是
MayOrMayNotBe
运算符 并不真正比较对象引用)。Jon is right in saying that “[d]ifferent tasks suit different languages and paradigms.” However, there are a few considerations that are largely independent of the domain. These mostly concern syntax but since code is read more often than written, I actually think that syntax matters.
For one thing, and something that many languages do wrong, it's completely arbitrary to base the syntax off C. C actually has an exceptionally bad syntax. I'll just pick two examples.
The first is quite uncontroversial: semicolons are unnecessary. Take the following code; the grammar is completely unambiguous and easy to parse for a compiler. Neither semicolons nor explicit line continuations are necessary.
This is actually quite similar to Python but even more permissive: the definition of
fraction
spans multiple lines. This is logical since the first line isn't yet complete.Another bone I've got to pick with C-like syntaxes are their largely implicit variable declarations. Instead of announcing clearly “I'm declaring a
variable
of typeFoo
,” all they whisper shyly is “Foo var
”. SinceFoo
isn't even a reserved word in most cases, the programmer isn't offered a single visual hint here. I prefer VB's explicitDim var As Foo
, even thought he keyword used here is, well, quite dim.(C++ actually makes matters much, much worse by introducing a lot of nearly identical and often ambiguous syntaxes that mean completely different things, from variable initializations to function declarations).
Another thing my language would have to have is static typing. It's true that dynamic typing has its uses but they are surprisingly rare. Even most “scripting languages” wouldn't really need them. I think that this is often confused with implicit typing which has rather more uses. Take (again) the example of Python. Why doesn't it offer static typing? It's already strongly typed, statical type checking would only be consequent, and would cut down on debugging quite a bit. The same goes for explicit variable declaration. I fail to see what advantages implied variable declaration offers.
So there we've already got an outline for a language:
Furthermore, I'm a huge fan of certain C++ concepts, such as general-purpose templates, RAII (i.e. avoiding garbage rather than collecting it), immutability and the concept of value ranges defined via iterators. I've stated elsewhere that I believe iterators to be one of the most fundamental innovations ever. Give'em a little lipstick and you won't even recognize the ugly beast that is C++:
rather than
Of course I'm aware that the above syntax is offered by many languages. But they all only offer watered-down versions of C++' powerful iterator concept (to use C++ terminology, the only kind of iterators that most languages know are input iterators, which are basically the least powerful iterators).
At this point I should probably say that the sole copyright for all these ideas is mine, patents pending (in particular for the
MayOrMayNotBe
operator that doesn't really compare object references).我没有“完美”编程语言的概念,因为需要执行的不仅仅是一项任务。
不同的任务适合不同的语言和范例。
I have no concept of a "perfect" programming language because there isn't just one task to be performed.
Different tasks suit different languages and paradigms.
它看起来像 C#。 我很想拥有微软!
It would look like C#. I would love to own Microsoft!
我完美的语言将允许我根据需要增强功能。 如果我需要编写一个没有类的小型直接实用程序,我可以。 如果我需要使用类,我也可以这样做,如果我想编写一个完全面向对象的解决方案,我也可以这样做。 链接器足够智能,可以让我创建小型快速命令行实用程序(没有运行时依赖项)或我能想象到的最大的臃肿 OOP GUI 应用程序。
问题是我喜欢的东西有相反的目标,因此我总是被迫使用完全不同的语言。 我目前使用 PowerShell、VBScript、PowerBasic、Java 和 C#(有时使用 VB .NET、VB 6、C++、Python 和 Perl),没有特定的顺序。
现在,如果我可以使用一种类似 C# 的语言来完成这一切,该语言具有全局函数,在创建这些小型应用程序时没有运行时依赖性,但让我在需要时充分利用 .NET Framework 和 Java SDK 的强大功能,那么我'会很高兴。
My perfect language would allow me to ratchet up the functionality as I need it. If I need to write a small straight forward utility program without classes I could. If I needed to use classes I could do that also, and if I wanted to write a completely object oriented solution I would be able to do that too. The linker would be smart enough to let me create small fast command line utilities (with no runtime dependencies) or the largest bloated OOP GUI app I could imagine.
The problem is that what I like has opposing goals and thus I've always been forced into using completely different languages. I currently use in no particular order PowerShell, VBScript, PowerBasic, Java, and C# (and sometimes VB .NET, VB 6, C++, Python, and Perl).
Now if I could do it all with one C# like language that had global functions with no runtime dependencies when creating those small apps, but let me make full use of the power of the .NET Framework and Java SDK when I needed to, I'd be happy.
完美的编程语言往往出现在科幻小说中。 例如:
这一切仍然归结为同样的基本困境。 任何不强迫人类学习技能的编程语言往往会限制思想自由。 自然语言也不好,因为它有很多歧义。
我不介意将自由与强大和最少语法结合起来的一种。 我最近开始学习lisp,目前看来还不错。
Perfect programming languages tend to be found in science fiction novels. For example:
It all still comes down to the same basic quandary. Any programming language that does not force the human to learn a skill tends to limit the freedom of thought. Natural language is not good either since it has many ambiguities.
I wouldn't mind one that combines freedom with power and minimal syntax. I've recently started learning lisp, and it seems very good so far.
Amazon Mechanical Turk 支持大规模并行性。
Massive parallelism empowered by Amazon Mechanical Turk.
我是 C 宏的忠实粉丝,但我认为如果您可以用您正在使用的相同语言编写宏或“元代码”,那可能会很好。 (C 是一个不好的例子;这在脚本语言中可能是好的。)
在这些例子中,我使用大括号来标识元代码。 您将能够通过“预处理器”运行源代码以扩展元代码。 否则它只会在运行时扩展一次。
或者
有时我们必须编写几行非常重复的代码; 现在想不出一个好的例子,但这种想法在这种情况下也会非常有帮助。
I'm a big fan of C macros, but I thought it might be nice if you could write macros or "meta-code" in the same language you're using. (C is a bad example; this could be good in scripting languages.)
In these examples I'm using braces to identify the meta-code. You would be able to run the source through a "preprocessor" to expand the meta-code out. Otherwise it would just be expanded once at runtime.
or
Now and then we have to write several lines of very repetitive code; can't think of a good example right now but this kind of think would also be very helpful in such situations.
这与采用 Eiffel 和 C# 的最佳想法没有太大区别(因为,很明显,我没有知识来想出更好的东西 - 我一开始就没有学过 CS)。
然而,我主要的实际关注点是超越经典的“源代码文本”方法。 我知道这是(或听起来像)IDE 的东西,但为什么我不能有一个可配置的代码视图,其中包含前置条件/正文/后置条件等列,而不是“线性”形式 (i):
为什么不 (ii) -想象这是一个表格(带边框):
而且,为什么我不能选择样式(i)中函数的“开始”和“结束”方式(大括号、关键字...)? 为什么我无法立即显示或隐藏私有或受保护的成员? 为什么我不能立即看到包含所有继承功能的“平面版本”? 重点
不在于拥有一个可供您编辑的神圣代码文件,然后是多个“酷视图”,而是能够以 (i)、(ii) 以及对您最有用的任何形式编辑和添加代码。
在某种程度上,在这里谈论“IDE”似乎是题外话。 但我认为这迟早会改变我们编写和阅读代码的方式。 这最终将影响语言的演变方式。 未来的目标不仅是增强可读性,而且是“可理解性”和交互性。
It wouldn't be very different from taking the best ideas of Eiffel and C# (because, plainly, I don't have the knowledge to come up with anything better - I haven't studied CS in the first place).
However, my main practical concern would be go to one step beyond the classical "source code text" approach. I know this is (or sounds like) an IDE thing, but why can't I have a configurable code view with columns such as preconditions/body/postconditions instead of a "linear" form (i):
Why not (ii) - imagine this is a table (with borders):
And also, why can't I choose how functions "begin" and "end" (braces, keywords...) in style (i)? Why can't I instantly show or hide private or protected members? Why can't I instantly see the "flat version" with all the inherited functions inside? etc.
The point would not be to have one holy code file where you edit and then multiple "cool views", but to be able to edit and add code in both (i), (ii) and whatever form is most useful to you.
In a way, talking about "IDE" may seem off-topic here. But OTOH I think this is going to change the way we write and read code, sooner or later. And this will ultimately influence the way languages evolve. The future goals would be to enhance not only readability but also "understandability" and interactivity.
我想我的应该介于 Brainf*ck 和 LOLCODE 除了还有很多括号。
I would imagine mine would be somewhere between Brainf*ck and LOLCODE except with A LOT more parentheses.
Python 对我来说非常接近理想...我只是想摆脱一些烦恼,比如 self 关键字...但是有了一个好的编辑器,Python 可以很快地做一些令人惊奇的事情...
Python is pretty close to ideal for me... I would just get rid of some annoyances like having the self keyword... but with a good editor, Python can do amazing things very quickly...
多媒体。
我希望能够书写一些图形符号,快速绘制连接,然后切换到其他模式,例如在需要精度的地方打字。
我还认为编程语言应该支持那些不会用英语思考的人(是的,甚至是美国人......开玩笑!)。 我已经学了足够多的日语,并尝试学习一些印度尼西亚语 - 我希望看到一种语言支持具有不同语法结构和命令的人们。
我在最近参加的一个关于网络未来的论坛上提出了一个问题,询问一位来访的中国教授,他是否认为中文书面语言比英语更有可能实现可行的语义网络。 他对这个想法很感兴趣。
我读到的很多科幻小说都谈到了未来计算机交互的 UI:
Multi-media.
I want to be able to scribble some graphical symbols, quickly sketch connections and then flip to other modes such as typing where precision is needed.
I also think programmming languages should support people who don't think in English (yes, even Americans ..... joking!). I've studied enough Japanese and tried to pick up some Indonesian - I would like to see a language support people with different grammatical constructs and orders.
I raised a question at a recent forum I attended on the future of the web, asking a visiting Chinese professor if he thought Chinese written language would be more likely to enable a workable semantic web than English. He was intrigued by the notion.
A lot of SF I read talks about future UI's for computer interaction:
一种没有结构或变量,只有一个函数的语言。
doEverything();//根据已经预测的输入自动生成所有内容
A language that features no structure or variables, just one function.
doEverything();//automatic generation of all content based on already predicted input
我设想一种语言必须被告知对输入、变量以及执行顺序的精确限制,因此可以编译成快速多线程(或可集群)软件。
这是一个有趣的想法:想象一下“函数”中的所有“语句”都可以按任何顺序执行。 如果某事物依赖于其他事物,则需要显式“调用”该依赖关系。 这将使并行设计成为该语言的一个组成部分。
不幸的是,我没有投入足够的想象力来想出更具体的东西。
I envision a language that must be told precise restrictions on input and variables and execution order, and so can be compiled into fast multithreaded (or clusterable) software.
And here's an interesting idea: imagine that all the "statements" within a "function" could be executed in any order at all. If something depends on something else, you need to "call" the dependency explicitly. This would make design for parallelism an integral component of the language.
Unfortunately I haven't invested enough imagination to come up with anything more specific.
Clojure 已经非常接近了...
Clojure is getting pretty close...
我不确定我梦想的语言会是什么样子,但我对 C 风格语言有一点改进。 我已经写了多少次这样的东西:
我知道有更优雅的功能方法,但有时你仍然会得到这样的代码。 一个简单的“guard”声明在这里会有帮助:
I am not sure what my dream language would look like, but I have a little improvement for C-style languages. How many times have I written something like this:
I know there are more elegant functional ways for this, but sometimes you still end up with code like this. A simple "guard" statement would help here:
我想要一种编程语言,可以让工具很容易正确编写。 提取方法、着色、自动完成、编译等。
我希望在实现这一点的同时仍然易于编写和阅读。
I would like a programming language that makes tools really easy to write correctly. Extract method, colorization, autocomplete, compilation, etc.
I want this to happen while still being easy to write and easy to read.
我理想的编程语言,代码应该是智能的,它会告诉我另一段代码是否有问题,我们会坐下来交谈,它会告诉我它的问题是什么,这样我们就可以解决它......我称之为“EmotionPeople++”
My ideal programming language, the code would be smart, it would tell me if it had a problem with another piece of code, we would sit down and talk and it would tell me what its problem was so we could work it out... I call it "EmotionPeople++"
它看起来和Scheme一模一样。 只有它可以编译为 IL 和 Java 字节码以及汇编,这样我就可以使用所有这些库。
It would look exactly like Scheme. Only it would compile to both IL and Java bytecode, and assembly so I could use all those libraries.
人们设计语言是为了满足特定的目标。
语法和语义应遵循所需的功能。
就我而言,我想要一种具有细粒度并行性的语言,
也就是说,每粒的开销非常低,允许小块
要并行化的代码。
我在 x86 SMP 系统上设计并实现了它,
作为大规模的基础,它已经使用了大约 10 年。
软件分析工具。
要点是让我(我们)指定
并行性很容易:
并行执行A和B,并让编译器
生成所有使这成为可能的碎片。
我们不关心语法是否正确
是否中缀,所以我们采用 LISP 风格来避免
论据。
一篇描述该语言和一些内容的论文
并行应用程序可以在以下位置找到:
http://www.semanticdesigns.com/Company/Publications/ parallelism-in-symbolic-computation.pdf
这篇论文简要讨论了我们如何没有做到这一点
成功避免语法争论
尽管我们做出了决定。
One designs languages to meet specific goals.
Syntax and semantics should follow desired function.
In my case, I wanted a language with fine-grain parallelism,
that is, very low overhead per grain to allow small chunks of
code to be parallelized.
I've designed and implemented it on x86 SMP systems,
and it has been in use for about 10 years as the foundation for a large-scale
software analysis tools.
The main point was to allow me (us) to specify
parallelism easily:
does A and B in parallel, and let the compiler
generate all the crud that makes this possible.
We didn't care about whether the syntax was
infix or not, so we went LISP style to avoid
arguments.
A paper describing the language and a number of
parallel applications can be found at
http://www.semanticdesigns.com/Company/Publications/parallelism-in-symbolic-computation.pdf
The paper briefly discusses how we didn't
succeed in avoiding arguments over syntax
in spite of our decision.
我将从主要特征开始:
目前我发现最接近我的愿望的是 Clojure,它满足了大部分要求。
由于OP指的是语法,我将给出一些代码示例:
适当的变量参数函数,支持大型参数列表:
运行时对编译器的交互式访问:
分布式代码执行(MapReduce风格)。 请注意,这意味着语言/库能够获取本地定义的
some-long-running-function
并将其透明地分发到集群中的所有节点以便在运行时执行嗯>。正确的类型推断(即编译器计算出 my-function 始终返回一个 String 并相应地进行优化/推断:
I'll start with the key features:
Currently the closest I've found to my wishlist is Clojure, which ticks most of these requirements.
Since the OP refers to syntax, I'll give a few code examples:
Proper variable arity functions, with support for large argument lists:
Interactive access to the compiler at runtime:
Distributed code execution (MapReduce style). Note that this implies that the language / library is able to take the locally defined
some-long-running-function
and transparently distribute it to all the nodes in the cluster for execution at runtime.Proper type inference (i.e. the compiler works out that my-function always returns a String and makes optimisations / inferences accordingly:
我的最佳语言看起来很像 Nemerle(减去任意限制)。 实际上,这取决于元编程工具; 我应该能够以我认为合适的任何方式任意扩展或修改语言以完美地适应该领域。
给我宏,让我能够按照自己的意愿处理所有代码的 AST,这样我就可以构建我的完美的语言。
My optimal language would look a whole lot like Nemerle (minus the arbitrary restrictions). Really it comes down to metaprogramming facilities; I should be able to arbitrarily extend or modify the language in any way I see fit (period) to fit the domain perfectly.
Give me macros that allow me to work on the AST of all of the code as I wish and I can build my perfect language.