Java是正交的吗?

发布于 2024-09-10 15:06:11 字数 141 浏览 15 评论 0原文

我想知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

各自安好 2024-09-17 15:06:12

UNIX 编程艺术,第 4 章。模块化、正交性,第 89 页:

正交性

正交性是最重要的之一
可以提供帮助的重要属性
使复杂的设计变得紧凑。在
纯正交设计、操作
没有副作用;每个动作
(无论是API调用,宏
调用,或语言操作
只改变一件事而不
影响他人。有一个和
更改每个属性只有一种方法
无论你是什么系统
控制。

编程语言语用学,第 6 章,第 228 页:

正交性意味着特征可以
可以任意组合使用,即
组合都有意义,而且
给定特征的含义是
一致,无论其他
它所结合的功能

关于 Lisp,5.2 正交性:

正交语言是这样一种语言:
你可以通过组合来表达很多
大量的操作员数量很少
不同的方式。


我认为正交编程语言的每个功能都具有最小或没有副作用,因此可以在使用它们时无需考虑该用法将如何影响其他功能。我借用了正交 API 的定义。

在 Java 中,您必须评估例如在标识符上同时使用时是否存在可能相互影响的关键字/结构的组合。例如,当将 publicstatic 应用于方法时,它们不会相互干扰,因此这两个是正交的(除了关键字的目的之外,没有副作用)

您必须对其所有功能执行此操作才能证明正交性。这是解决这个问题的一种方法。我认为在这个问题上也不存在明确的正交或正交。

The Art of UNIX Programming, Chapter 4. Modularity, Orthogonality, Page 89:

Orthogonality

Orthogonality is one of the most
important properties that can help
make even complex designs compact. In
a purely orthogonal design, operations
do not have side effects; each action
(whether it's an API call, a macro
invocation, or a language operation)
changes just one thing without
affecting others. There is one and
only one way to change each property
of whatever system you are
controlling.

Programming Language Pragmatics, Chapter 6, Page 228:

Orthogonality means that features can
be used in any combination, that the
combinations all make sense, and that
the meaning of a given feature is
consistent, regardless of the other
features with which it is combined
.

On Lisp, 5.2 Orthogonality:

An orthogonal language is one in which
you can express a lot by combining a
small number of operators in a lot of
different ways.


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 and static 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.

子栖 2024-09-17 15:06:12

使用术语“正交编程语言”是不常见的。通常,在计算机科学中,您真正谈论的是正交指令集。然而,如果我们将含义扩展到语言的语法:

“...意思是[语言]具有相对较少数量的基本构造和一组用于组合这些构造的规则。每个构造都有一个与之关联的类型,并且对这些类型没有限制......” 参见 ALGOL

那么我们可以假设,如果不是该语言中的所有指令都可以在所有数据类型上工作,那么就会产生非正交性。然而,这并不意味着反之亦然,也就是说,如果所有语言指令都适用于所有数据类型,则不一定意味着该语言是正交的。

更正式地说,正交语言只有一种方法来执行给定的操作。非正交语言有不止一种方法可以达到相同的效果。

最简单的例子:

for loop; vs. while loop;

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 loop; vs. while loop;

for and while are non-orthogonal.

护你周全 2024-09-17 15:06:12

正交性是独立于语言的设计特征。当然,某些语言可以让您更轻松地为系统进行正交设计,但您不应该专注于特定语言来保持系统设计尽可能正交。

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.

属性 2024-09-17 15:06:12

正交性本身并不是真正的语言特性,尽管某些语言具有促进正交性的特性(例如注释、内置 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.

眼趣 2024-09-17 15:06:12

C 中缺乏正交性:

  • 数组可以包含除 void 之外的任何数据类型
  • 参数按值传递,但数组按引用传递

编程语言被认为是正交的,如果:

  1. 有一个相对较小的原始结构集,可以以相对较少的方式组合来构建数据和控制结构

  2. 每种可能的结构都是合法的

例如具有 4 种基本数据类型(Int、Float、Double、Char)和两种
的语言
类型运算符(数组和指针)可以创建相对大量的数据结构。

所以正交性的优点是使语言变得简单和规则,因为例外较少。

Lack of Orthogonality in C:

  • An array can contain any data type except void
  • Parameters are passed by value but array are passed by reference

A programming language is consider orthogonal if:

  1. 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

  2. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文