Java是正交的吗?
我想知道 Java 是否是正交的,如果是的话,那么它的哪些特性使它成为正交的。如何确定一种语言是否是正交的?比如我在一些网站上发现C++不是正交的,但是没有解释,为什么不呢。还有哪些语言是正交的?请帮助我,因为互联网上几乎没有关于这个主题的信息。
谢谢
I am wondering if Java is orthogonal or not, and if yes, then which are its features that make it orthogonal. How can you determine if a language is orthogonal or not? For example, I found on some website that C++ is not orthogonal, but no explanations, why not. What other languages are orthogonal? Please help me, because there is almost no information on the internet about this topic.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
UNIX 编程艺术,第 4 章。模块化、正交性,第 89 页:
编程语言语用学,第 6 章,第 228 页:
关于 Lisp,5.2 正交性:
我认为正交编程语言的每个功能都具有最小或没有副作用,因此可以在使用它们时无需考虑该用法将如何影响其他功能。我借用了正交 API 的定义。
在 Java 中,您必须评估例如在标识符上同时使用时是否存在可能相互影响的关键字/结构的组合。例如,当将
public
和static
应用于方法时,它们不会相互干扰,因此这两个是正交的(除了关键字的目的之外,没有副作用)您必须对其所有功能执行此操作才能证明正交性。这是解决这个问题的一种方法。我认为在这个问题上也不存在明确的正交或正交。
The Art of UNIX Programming, Chapter 4. Modularity, Orthogonality, Page 89:
Programming Language Pragmatics, Chapter 6, Page 228:
On Lisp, 5.2 Orthogonality:
I think an orthogonal programming language would be one where each of its features have minimal or no side effects, so they can be used without thinking about how that usage will affect other features. I borrow this from the definition of an orthogonal API.
In Java you'd have to evaluate for example if there is a combination of keywords/constructs that could affect each other when used simultaneously on an identifier. For example when applying
public
andstatic
to a method, they do not interfere with each other, so these two are orthogonal (no side effects besides what the keyword is intended to do)You'd have to do that to all its features to prove the orthogonality. That is one way to go about it. I do not think there exists a clear cut is or is not orthogonal in this matter either.
使用术语“正交编程语言”是不常见的。通常,在计算机科学中,您真正谈论的是正交指令集。然而,如果我们将含义扩展到语言的语法:
“...意思是[语言]具有相对较少数量的基本构造和一组用于组合这些构造的规则。每个构造都有一个与之关联的类型,并且对这些类型没有限制......” 参见 ALGOL
那么我们可以假设,如果不是该语言中的所有指令都可以在所有数据类型上工作,那么就会产生非正交性。然而,这并不意味着反之亦然,也就是说,如果所有语言指令都适用于所有数据类型,则不一定意味着该语言是正交的。
更正式地说,正交语言只有一种方法来执行给定的操作。非正交语言有不止一种方法可以达到相同的效果。
最简单的例子:
for 和 while 是非正交的。
Using the term orthogonal programming language is unusual. Typically, in computer science you are really talking about orthogonal instruction-sets. However, if we are to extend the meaning to the grammar of a language:
"...meaning [the language] has a relatively small number of basic constructs and a set of rules for combining those constructs. Every construct has a type associated with it and there are no restrictions on those types...." see ALGOL
Then we can assume that if not all instructions in the language can work on all datatypes will yield non-orthogonality. This however does not mean that the converse is true, that is to say if all language instructions do work on all data types, it does not necessarily mean that the language is orthogonal.
More formally, an orthogonal language would have exactly ONE way to do a given operation. Non-orthogonal languages would have more than one way to achieve the same effect.
Simplest example:
for and while are non-orthogonal.
正交性是独立于语言的设计特征。当然,某些语言可以让您更轻松地为系统进行正交设计,但您不应该专注于特定语言来保持系统设计尽可能正交。
Orthogonality is feature of your design independent of the language. Sure some language make it easier for you to have an orthogonal design for your system but you shouldn't focus on a specific language to keep your system's design as orthogonal as possible.
正交性本身并不是真正的语言特性,尽管某些语言具有促进正交性的特性(例如注释、内置 AOP 等)。关于Java中的正交性:我以log4j为例写了一个关于此的小案例研究:“正交性示例" - 您可能会发现这很有用。
Orthogonality is not really a language feature as such, even though some languages have features that promote orthogonality (such as annotations, built-in AOP, ..). Regarding orthogonality in Java: I have written a little case study about this using log4j as example: "Orthogonality By Example" - you might find this useful.
C 中缺乏正交性:
void
之外的任何数据类型编程语言被认为是正交的,如果:
有一个相对较小的原始结构集,可以以相对较少的方式组合来构建数据和控制结构
每种可能的结构都是合法的
例如具有 4 种基本数据类型(Int、Float、Double、Char)和两种
的语言
类型运算符(数组和指针)可以创建相对大量的数据结构。
所以正交性的优点是使语言变得简单和规则,因为例外较少。
Lack of Orthogonality in C:
void
A programming language is consider orthogonal if:
there is a relatively small set of primitive constructs that can combine in a relatively small number of ways to build data and control structures
every possible structure is legal
For example a language with 4 primitive data types (Int, Float, Double, Char) and two
type operators (Array and Pointer) can create a relatively large number of data structures.
So the advantage of orthogonality is to make the language simple and regular because there are less exceptions.