是否存在不基于操作变量和函数的编程范例?
事实上,我所知道的每种语言基本上都是一个主题的变体:创建变量和函数,然后使用条件和其他结构来操作它们。我知道函数式编程等与“传统”语言有些不同,但本质上它们几乎是相同的。您仍在使用变量(某种程度上,即使它们是不可变的等),并创建函数。
是否有任何语言或系统完全废除了我们现在使用的语言或系统,并采用完全不同的方法?
Virtually every language I know of is basically a variation on a theme: you create variables and functions, then manipulate them using conditionals and other constructs. I understand Functional Programming and the like are somewhat different from 'traditional' languages, but underneath they are almost the same. You are still working with variables (somewhat, even though they are immutable and such), and creating functions.
Is there any language or system that completely does away with what we tend to use now and has a completely different approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
尽管你对函数式编程不屑一顾,但我认为你只需要再看一遍花时间阅读来理解和学习,而不是使用确认偏差将其视为“更多相同”。以函数式风格编写代码与以命令式风格编写代码有很大不同。但是,如果它对您来说还不够不同,为什么不看一下其中任何一个?:
基本上,只需查看数十种可用的编程范例中的任何一种,并阅读描述即可理解和启发而不是通过确认偏差来解雇。为您正在使用的“不同”的模糊定义看起来足够不同的每种语言学习一种语言,并享受乐趣。
Despite your high-handed dismissal of Functional Programming, I think you need to look at it again only this time reading for comprehension and learning instead of using confirmation bias to dismiss it as "more of the same". Writing code in a functional style is profoundly different than writing code in an imperative style. If it isn't different enough for you, however, why not take a look at any of these?:
Basically, just look at any of the dozens of programming paradigms available and read the descriptions for comprehension and enlightenment instead of dismissal through confirmation bias. Learn one language for each that appears sufficiently different for the vague definition of "different" you're using and have fun.
本身不是一种语言,但模拟计算机在某些方面与更流行的数字计算机有很大不同。
Not a language per se, but analog computers are in some ways quite different from the more popular digital computers.
人们在图形语言方面进行了多次尝试。 LabVIEW 系统
美国国家仪器公司可能是最成功的。它使用数据流图
具有作用于数据的组件。
图形语言的另一种尝试是UML。我猜陪审团对此还没有定论。在标准委员会介入并将其变成适合每个人的东西之前,这可能是一个好主意。
大量机电系统由 PLC 控制,它们是
使用梯形逻辑编程。它本质上是一门创造高度的学科
可靠的有限状态机,但与程序机几乎没有相似之处
语言。
还有一些深奥的、晦涩的和另类的语言,它们除了提醒人们图灵完备并不要求语言是明智的之外,基本上没有任何实际目的。有些人可能会将图灵机本身归为此类,但是 BrainF*ck 和 Piet 在这群人中对我来说真的很突出。
深奥的语言 whenever 也是一个有趣的练习,因为它根本没有流量控制。
编辑:我几乎忘记了Befunge。它的源文本是一个 ASCII 字符网格,其中每个单元格都是一个操作码。执行可以在四个方向中的任何一个方向上运行,因此可以以四个不同的序列流过单个操作码。它是另一种深奥的语言,并且被设计为尽可能难以为其编写编译器(1993 年)。但这实际上并没有阻止某人这样做。
我指出的几种语言都是深奥的语言。这些通常是用户社区较小(通常只有一两个)的语言。它们的创建有多种原因,而探索图灵完备意味着什么以及如何表示程序的边界是所引用的更重要的原因。
所有深奥语言的鼻祖是INTERCAL,它创建于1972年。它是一种表面上类似于COBOL的语言,但其中的许多怪癖要求程序足够礼貌(但不要太礼貌)才能继续执行。为了支持礼貌,
PLEASE DO
是DO
的礼貌形式。一个值得注意的扩展是COME FROM
语句,它可以使控制从指定位置流到此处。There have been several attempts at graphical languages. The LabVIEW system from
National Instruments is probably the most successful. It uses a graph of the data flow
with components that act on data.
Another attempt at a graphical language is UML. I'd guess that the jury is out on this one. It was probably a good idea before a standards committee got involved and turned it into something for everyone.
A huge amount of electro-mechanical systems are controlled by PLCs, which are
programmed with ladder logic. It is essentially a discipline for creating highly
reliable finite state machines, but bears very little resemblance to procedural
languages.
Then there are the esoteric, obscure, and alternative languages which largely serve no practical purpose other than to remind people that Turing-complete doesn't require that the language be sensible. Some might put a Turing machine itself in this category, but BrainF*ck, and Piet really stand out for me in this crowd.
The esoteric language whenever is also an interesting exercise in that it has no flow control at all.
Edit: I almost forgot about Befunge. Its source text is a grid of ASCII characters, where each cell is an opcode. Execution runs in any of four directions, and so it is possible to flow through a single opcode in four different sequences. It is another esoteric language, and was designed to be as difficult as possible (in 1993) to write a compiler for. Not that that has actually stopped someone from doing it.
Several of the languages I've pointed out have been esoteric languages. These are generally languages with small (often only one or two) user communities. They are created for a variety of reasons, and exploring the boundaries of what it means to be Turing complete and how one might represent a program are the more serious reasons cited.
The granddaddy of all esoteric languages is INTERCAL which was created in 1972. It is a language which superficially resembles COBOL, but which among its many quirks requires that the program be sufficiently polite (but not too polite) in order to continue executing. In support of politeness,
PLEASE DO
is a polite form ofDO
. A notable extension is theCOME FROM
statement, which can cause control to flow to here from the named location.好吧,有Piet。那是非常不同的。 (下面是 Piet 中的 Hello World。)尽管如此,您可能会认为您正在处理包含一定数量整数的数据结构(在本例中为堆栈),然后您在堆栈中添加和删除内容,操纵价值观等等,所以实际上它仍然是一样的。
Well, there's Piet. That's pretty different. (Below is Hello World in Piet.) Although even then, you might argue that you're dealing with a data structure (in this case a stack) containing some number of integers and then you're adding and removing things from the stack, manipulating the values, etc. so really it's still kind of the same.
这取决于你问的是什么,但答案可能是否定的。
原因是当前所有图灵完备的计算机语言都是图灵完备的。这意味着这些语言中的任何一种都可以由该组中的任何其他语言来模拟。那么任何编程语言都可以有一个可以在我们当前的计算机上运行的编译器或解释器(近似值)。这些在架构上确实具有代码和数据的概念。
因此,如果您认为函数式编程和命令式(“传统”)编程是相同的,因为它们在底层运行在计算机上,那么就没有其他选择了。
代码和数据转换为函数和数据结构(变量)。它们确实允许变化:
另一方面,如何表达程序的编写方式也可能略有不同。使用函数组合作为基础可能会引导您走向串联编程的方向,尽管数据流编程(包括许多图形语言)和函数编程也类似地支持它。
最后一组表达语言的方法是建模为数据结构上的优化或搜索过程的方法:
这都有些学术性。我的建议是尝试确定“不同”的含义。函数式编程可能足以满足您的目的。
编辑:我刚刚注意到您使用了“使用条件和其他结构操纵它们”这一表达方式。控制流构造不必是与代码和数据不同的构造。例如,条件
if
可以表示为filter
,或者循环可以表示为map
。给定高阶函数和惰性求值,您可以无需显式的if
或for
,仅使用函数和数据结构。这并不意味着您实际上失去了这样做的能力。如果您想看到类似的内容,您可能会对 Haskell 感兴趣。另外,请参阅看起来不同的语言的其他答案,例如图形语言和深奥语言,同时仍然使用应用于具有控制结构方法的数据结构的函数。
It depends on what you are asking about, but the answer is probably no.
The reason is that all the current computer languages that are Turing Complete are, well, Turing complete. This means that any of these languages can be simulated by any of the others in this group. Then any programming language can have a compiler or interpreter that can run on our current computers (approximation). These architecturally do have the concept of code and data.
So, if you think that functional programming and imperative ('traditional') programming are the same because underneath they run on a computer, then there are no other options.
Code and data translate into functions and data structures (variables). They do allow variations:
On the other hand, how to express the program may be also written a bit differently. Using function composition as a basis may lead you in the direction of concatenative programming, though dataflow programming (including many graphical languages) and functional programming also similarly support it.
The last group of ways to express a language are those modelled as an optimisation or search process over a data structure:
This is all somewhat academic. My advice is that try to identify what you mean by different. Likely, functional programming is different enough for your purposes.
Edit: I have just noticed your use of the expression "manipulate them using conditionals and other constructs". Control flow constructs need not be different constructs to code and data. For example, a conditional
if
can be expressed as afilter
or a loop can be expressed as amap
. Given higher order functions and lazy evaluation you can do without an explicitif
orfor
, using only functions and data structures. That doesn't mean you actually lost the ability to do that. You might be interested in Haskell if you want to see something like that.Also, see the other answers for languages that look different, such as graphical languages and esortic languages, while still using the functions applied to data structures with control structs approach.
好问题。让我们退后一步。在我的第一个问题中,我将尝试解释,您正在寻找的不是一种新语言,而是一种新架构,而且我确信,您至少知道其中的重要内容。
20 年前,计算机程序是使用“串行”逻辑构建的,就像基本程序一样:
MS-DOS 程序也一样:它们运行一段时间,然后等待用户输入,然后再次运行。在Unix系统上,即使是多任务系统,游戏也非常相似,多个用户可以以这种方式运行程序。
出现了两种突破浪潮:
同时,编译和程序构建也发生了变化,但我认为少了一些:
此外,编程目标环境也发生了很大变化:
一些大而胖的程序成为了平台:
我没有提到任何新的语言,但是即使使用同一种语言,编程也可以有很大的不同,比如为手机编写 J2ME 游戏和为 Oracle SQL 编写存储过程,都是用 JAVA 编写。
也许您正在寻找的不是编程语言。比如说,任务是在浏览器中显示数据列表,某种表格。 Web 应用程序应如下所示:
HTML+XSLT 是一种编程语言吗?不是。它们执行的任务与 PHP 在服务器端执行的任务或 JS 在客户端执行的任务相同吗?绝对是。是通用平台吗?是的,所有浏览器都支持它。
我认为,低级编程语言已经足够多了,我指的是过程语言、OOP 语言或其他图灵完备语言。新的(非编程)语言的目标是更加有效:更快的代码生成、更灵活的应用程序、社区工作支持、可扩展性、更容易维护、可重用性等。
(我分开了我的答案在这里;在下一部分中,我将向您展示一个,我正在使用它一段时间。)
Good question. Let's take a step back. In my first aswer, I'll try to explein, that what you're looking for is not a new language, but a new architecture, and I'm sure, you know at least the important ones.
20 years ago, computer programs were built using "serial" logic, like a Basic program:
MS-DOS programs are the same: they run for a wile, then waiting for user input, then run again. On Unix systems, even it's a multitasking system, the game is very similar, more than one user can run programs that way.
There were two berakthrough wave:
Meanwhile, the compiling and program construction is changed, but I think some less:
Also, programming target environments changed lot:
Some big, fat programs became platform:
I did not mention any new laguage, but it can be so different programming even in the same language, say, writing a J2ME game for mobile phone and writing stored procedures for Oracle SQL, both in JAVA.
Maybe what you're looking for is not programming languages. Say, the task is to display a list of data, some kinda table in a browser. The web app should look:
Is HTML+XSLT a programming language? Not. Do they do the same task which the PHP does server-side, or JS does on client-side? Absolutelly. Is it a common platform? Yep, all the browser supports it.
I think, there are far enough low-level programming languages, I mean procedural, OOP or other Turing-complete languages. The goal of new (less-than-programming) languages is to be more effective: faster code generation, more flexible apps, community work support, scalability, easier maintanence, reusability etc.
(I split my answer here; in the next part, I'll show you one, which I'm playing with for a while.)
通读 http://en.wikipedia.org/wiki/Programming_paradigm 以及所有链接的页面在右侧的链接框中。根据你如何看待它,有些是完全不同的,有些是基本相同的。
Read through http://en.wikipedia.org/wiki/Programming_paradigm and all the pages linked in the link box on the right. Depending on how you look at it, some are quite different or they are all basically the same.
看看 Forth,这是一个相当不同的系统,几乎所有内容都是关于操作堆栈。它几乎就像一个非常原始的小型虚拟机。
Check out Forth, it is a rather different system where pretty much everything is about manipulating a stack. It's almost like a small very primitive VM.
正如我所说,当今有很多可以编程的平台或环境。对于某些平台,您可以从一长串语言中进行选择,例如Microsoft .NET,可以用VisualBasic、C#等进行编程;其他情况下,非常不同的平台使用相同的语言,例如Android中使用的JAVA、Oracle SQL服务器存储过程等。
此外,还有一些非编程语言,它们涵盖一个领域或阐明某种配置,这比真正的编程语言简单,但可以比编程语言更好地使用。一个例子:PLC 的梯形逻辑编程。
数据流编程就是这种编程的一种。我们看一下维基百科,什么是数据流编程(也叫基于流的编程):
来自:http://en.wikipedia.org/wiki/Flow-based_programming,
另请参阅 http://en.wikipedia.org/wiki/Dataflow_programming
维基百科文章很棒,我已经回答了其他一些问题,所以我不想重复。相反,我正在描述我用于异步数据流服务器的语言。
有 3 个语言元素。
组件声明
cmp: Compare
这是一个名为“cmp”的组件实例,它是一种 Compare 类型。
消息定义
src.out>> cmp值
cmp.gt>> dst1.in
cmp.lt>> dst2.in
cmp.eq>> dst3.in
点之前的单词是组件实例的名称,点之后的单词是端口名称,左侧的组件端口对是源,右侧是目的地。 (端口是组件发送或接收消息的关键点。请参阅 Wkikpedia 文章。)
属性
cmp.base = 8
这定义了组件实例的端口值。
(将这些行放在一起,我们得到一个简短的数据流程序,这意味着:一个值来自 src,cmp 检查它的值,如果大于 8,则将其传递给 dst1;如果小于 8,则传递给 dst2;如果正好是 8。)
我认为,这种语言符合您的标准,它不是过程性的,没有传统的变量,没有子例程,没有循环。
有趣的是,有一些严肃的项目,实现了数据流编程,但他们甚至没有提到它:
(我有我的数据流项目还没有网页,它正在建设中。)
可以显示数据流程序,也可以将其编辑为图形(请参阅 SynthEdit)。
As I said, there are lot of platforms or environments today, which can be programmed. In case of some platform, you can choose from a long list of languages, e.g. Microsoft .NET, which can be programmed in VisualBasic, C# etc.; other cases, very different platforms use the same language, e.g. JAVA, which is used in Android, Oracle SQL server stored procedures and so on.
Also, there are non-programming languages, which covers a domain or they articulate some kind of configuration, which is far simple as a real programming language, but can be used better than a programming language. An example: PLCs' ladder logic programming.
The Dataflow Programming is one of this kind of programming. Let's see Wikipedia, what is Dataflow Programming (also called Flow-Based Programming):
from: http://en.wikipedia.org/wiki/Flow-based_programming,
see also http://en.wikipedia.org/wiki/Dataflow_programming
The Wikipedia articles are great, and I've answered some other questions, so I don't want to repeat myself. Instead, I'm describing the language which I'm using for my Asynchronous Dataflow Server.
There are 3 language elements.
Component declaration
cmp: Compare
This refers a component instance, named "cmp", which is a type of Compare.
Message definition
src.out >> cmp.value
cmp.gt >> dst1.in
cmp.lt >> dst2.in
cmp.eq >> dst3.in
The words before the points are the names of component instances, the words after the point are port names, the left component-port pair is the source, the right is the destination. (Ports are the pin points of components for sending or receiving messages. See Wkikpedia articles.)
Properties
cmp.base = 8
This defines the value of a port of the component instance.
(Putting these lines together, we get a short dataflow program, which means: a valus comes from src, cmp checks its value, and passes it to dst1, if it's more than 8, dst2, if it's less than 8, and dst3 if it's exactly 8.)
I think, this language meets your criteria, it's not procedural, there're no traditional variables, no subroutine, no cycle.
It's funny that there are some serious projects, which implements dataflow programming, but they don't even mention it:
(I have no web page for my dataflow project yet, it's under construction.)
Dataflow programs can be displayed, or can be edited as graph (see SynthEdit).
影响最大的不是语言,而是你用它所做的事情。许多语言都会把你推向某个方向,像 Haskell 这样的纯函数式语言会让你几乎不可能进行命令式编程,但只要你不花时间去学习范式,大多数语言看起来就会和机器一样实际运行的语言,评估条件并将值分配给内存空间。
这些范式为您提供了您正在寻找的抽象。好的面向对象或函数式代码看起来与您所描述的完全不同。而且你不需要语言来做到这一点。我见过用纯 C 编写的优秀的面向对象代码和用 C++ 编写的函数代码。尽管为正确的工作使用正确的语言有很大帮助。不幸的是,事情也有相反的情况。如果您不花时间理解范例,您仍然会在Scheme 或Smalltalk 中编写命令式代码。
It's not about the language, it's what you do with it that makes the most difference. Many languages will push you in a certain direction, pure functional languages like Haskell will make it pretty much impossible to program imperatively for example but as long as you don't take the time to learn the paradigms most languages will look the same as the machine language that's actually running, evaluating conditionals and assigning values to memory spaces.
The paradigms give you the abstractions you're looking for. Good object oriented or functional code will look nothing like what you describe. And you don't need languages to do this. I've seen great object oriented code written in plain C and functional code in C++. Although using the right language for the right job helps a lot. Unfortunately things work the other way around too. If you dont take the time to understand the paradigms you will still write imperative code in Scheme or Smalltalk.
研究图灵机。维基百科文章列出了一些可以运行程序的模拟器。至少在美学上会有所不同。
Study up on the Turing Machine. The Wikipedia article lists some simulators you can run programs on. It will be at least aesthetically different.