问题描述
我读或听过如下句子:
或
但我不确定我是否理解规范究竟是什么。
but I am not sure if I understand what a specification exactly is..
假设我创建了一个新规范JMA,Java Math API,它是一个Java数学规范..
Lets say I create a new specification JMA, Java Math API, which is a Java Math Specification..
我的规范定义如下:
或者,我是否必须创建如下文档:
or, do I have to create a document something like:
或者,我是否必须创建接口和分发源代码?
or, do I have to create the interfaces and distrubute the source code?
public interface JMA{
int jmaAdd(int x,int y);
}
还是我必须编译接口并将其发布为jar?
or do I have to compile the interfaces and publish it as jar?
此外,规范是否可以包含抽象类或类?或者它必须只包含接口?
Also, can a specification contain abstract classes or classes at all? Or must it consist only of interfaces?
什么是规范,规范?
推荐答案
这是一个规范。
它不是一个非常有用的,因为它没有给用户提供该规范实现的许多保证。如果我想编写一个添加两个整数的程序,我只能通过阅读规范来做到这一点。
It's not a very useful one, because it doesn't give many guarantees to the user of an implementation of that specification. If I wanted to write a program that adds two integers, I couldn't do it just from reading the specification.
它 给出了但是,实现者有很多自由。通常,您希望您的规范在与用户相关的点上精确,但在与重要的点上模糊 >实现者。这样,用户就可以获得他能够编写程序所需的保证,但它也让实现者可以自由地将他的实现定制到他的特定领域。
It does give the implementor a lot of freedom, though. Generally, you want your specification to be precise in the points that matter to the user, but vague in the points that matter to the implementor. That way, the user gets the guarantees he needs to be able to write his programs, but it also gives the implementor the freedom to tailor his implementation to his particular niche.
例如,Java语言规范没有说垃圾收集。它仅定义何时何时可以访问对象,并定义您可以创建新对象。内存分配如何工作,垃圾收集器如何工作,是否是引用计数,跟踪或基于区域的收集器等等,所有这些都被省略了,因此不同利基的不同实现可以使用不同的垃圾收集器实现,同一利基的不同实现可以相互竞争。
For example, the Java Language Specification doesn't say anything about Garbage Collection. It only defines when objects are and aren't reachable, and it defines that you can create new objects. How the memory allocation works, how the garbage collector works, whether it is a reference-counting, tracing, or region-based collector, etc. all of those are left out, and thus different implementations for different niches can use different garbage collector implementations, and different implementations for the same niche can compete with each other.
这也是一个规范。它甚至没有上面的那么有用。它 定义方法的名称,但它没有定义它的作用。
That's also a specification. It is even less useful than the one above. It does define the name of the method, but it doesn't define what it does.
int jmaAdd(int x, int y) { return x - y; }
是该规范的完全有效的实现,因为
is a perfectly valid implementation of that specification, as is
int jmaAdd(int x, int y) { return 0; }
同样,对用户没有任何保证,也没有太多余地(或者更确切地说:余地实现者的错误区域。
Again, there are no guarantees for the user and too much leeway (or more precisely: leeway in the wrong areas) for the implementor.
public interface JMA{
int jmaAdd(int x,int y);
}
我不一定称之为规格。这是代码,因此也就是实现。
I wouldn't necessarily call that a specification. That's code, and thus an implementation.
注意:当然,在Java中, interface
s提供规范行为 class
es然后实现。但 这个术语规范的含义是你在问题中使用它的方式。
Note: of course, in Java, interface
s provide specification of behavior that class
es then implement. But that's not what is meant by the term specification the way you used it in your question.
再次,这是一个实现。
规范不包含任何内容。这是一张纸。
A specification doesn't contain anything. It's a piece of paper.
通常,规格是用英文写的。实际上,它们是用专门的规范编写语言编写的,它通常是具有特定语义的高度风格化的英语正式子集。例如,定义了一些常用英语单词的准确含义与IETF标准文件有关。 (有趣的是,它也是一个规范,因此使其成为编写规范的规范。)
Typically, specifications are written in English. Well, actually, they are written in a specialized specification-writing language, which is often a highly stylized formal subset of English with specific semantics. For example, BCP14/RFC2119: Key words for use in RFCs to Indicate Requirement Levels defines the precise meaning of some common English words in relation to IETF standards documents. (Interestingly, it is also a specification, thus making it a specification for writing specifications.)
有时也使用形式逻辑,特别是在编程语言规范中描述类型规则。有时甚至使用专门的正式规范语言,如。
Formal Logic is also sometimes used, especially in Programming Language specifications to describe typing rules. And sometimes, even specialized Formal Specification Languages are used, like the Z Notation.
简单且不太令人满意的答案是规范是规范,如果它被关注规范的人称为规范。 (或者更一般地说:将视为规范。)
The simple and not very satisfying answer is that a specification is a specification if it is called a specification by people who care about specifications. (Or more generally: thought about as a specification.)
不同的社区对规范有不同的看法。并为它们命名。
Different communities have different views on specifications. And different names for them.
例如,编程语言简单地发表在科学报告中。经过几轮改进和新报告后,他们发表了关于算法语言方案的修订报告。之后是修订后的算法语言计划修订报告。随之而来的是一种开玩笑,并且该语言的当前版本在经修订的修订的修订的修订的修订的修订的关于算法语言方案的报告中定义,通常写成修订的关于算法语言方案的报告或只是。
For example, the original specification for the scheme programming language was simply published in a scientific report. Then after a few rounds of improvements and new reports, they published the "Revised Report on the Algorithmic Language Scheme". And after that the "Revised Revised Report on the Algorithmic Language Scheme". With that began a kind of in-joke, and the current version of the language is defined in the "Revised Revised Revised Revised Revised Revised Revised Report on the Algorithmic Language Scheme", commonly written the "Revised Report on the Algorithmic Language Scheme" or just "RRS".
这些报告都不称为规范,但每一个报告都是规范。在Scheme之前,ALGOL也使用了报告一词,其他几种语言也是如此。
None of those reports is called a "specification", yet every single one is a specification. Before Scheme, ALGOL also used the term "Report", as did several other languages.
互联网RFC也是一个很好的例子。从技术上讲,所有RFC都是征求意见。这些RFC中只有极少数实际上升级到标准状态。有些也是最佳实践。它们都不被称为规范,但其中许多都被这样对待。例如,HTTP不是一个标准,但它被视为标准和规范,我们新世界经济的重要部分建立在此基础上。
Internet RFCs are also a good example. Technically, all an RFC is, is a "Request for Comments". Only very few of those RFCs are actually elevated to "Standards" status. Some are also "Best Current Practices". None of them are called "Specification", but many of them are treated that way. For example, HTTP is not a standard, but it is treated as both a standard and a specification, and significant portions of our new world economy are built on that.
如果你想要了解规格,最好是你只读一些:
If you want to get a feel for specifications, it's probably best if you just read some:
- (另一个名为报告的例子)
- ,包括但不限于
- Haskell 2010 Language Report (Another example of the name "Report")
- Scala Language Specification Version 2.11
- ECMA-262 6th Edition, The ECMAScript 2015 Language Specification
- The Java Language Specification, Java SE 8 Edition
- The Java Virtual Machine Specification, Java SE 8 Edition
- The HTTP Specifications, including but not limited to
- RFC7230: HTTP/1.1 Message Syntax and Routing
- RFC7231: HTTP/1.1 Semantics and Content
- RFC7540: HTTP/2
- RFC7541: HPACK Header Compression for HTTP/2
这篇关于什么是规格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!