What exactly is a Specification?
Asked Answered
A

4

32

I read or hear sentences such as:

The Java Persistence API (JPA) is a Java application programming interface specification...

or

JavaServer Faces (JSF) is a Java specification...

but I am not sure if I understand what a specification exactly is..

Lets say I create a new specification JMA, Java Math API, which is a Java Math Specification..

Is it enough that I define my specification as follows:

JMA must provide a method that adds two integers?

or, do I have to create a document something like:

JMA must provide the method: int jmaAdd(int x,int y)?

or, do I have to create the interfaces and distrubute the source code?

public interface JMA{
    int jmaAdd(int x,int y);
}

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?

What makes a specification, a specification?

Amathist answered 24/12, 2015 at 18:26 Comment(3)
Is your question specific to the Java Programming Language, the JVM or can answers be generalized to software specifications?Horseleech
@Horseleech It is general but I only know about Java so I am not sure how "specifications" are in other languages and platforms..Amathist
Are you asking us to specify what a specification is?Stephanystephen
C
23

Is it enough that I define my specification as follows:

JMA must provide a method that adds two integers?

That's a specification.

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.

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.

or, do I have to create a document something like:

JMA must provide the method: int jmaAdd(int x,int y)?

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.

or, do I have to create the interfaces and distrubute the source code?

public interface JMA{
    int jmaAdd(int x,int y);
}

I wouldn't necessarily call that a specification. That's code, and thus an implementation.

Note: of course, in Java, interfaces provide specification of behavior that classes then implement. But that's not what is meant by the term specification the way you used it in your question.

or do I have to compile the interfaces and publish it as jar?

Again, that's an implementation.

Also, can a specification contain abstract classes or classes at all? Or must it consist only of interfaces?

A specification doesn't contain anything. It's a piece of paper.

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.

What makes a specification, a specification?

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 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 "Revised7 Report on the Algorithmic Language Scheme" or just "R7RS".

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.

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:

Cockboat answered 25/12, 2015 at 0:7 Comment(4)
So essentially, Oracle (along with the community i.e. JSRs?) creates Java specifications, and then they themselves also provide an implementation for it (with help from the community since OpenJDK is the reference implementation). This would mean you can have different flavors of Java the language i.e. Oracle Java, IBM Java etc., as well as more commonly, different JVM and GC implementations. Is my understanding of it correct?Laissezfaire
@Abdul: No, you cannot have different flavors. That's the whole point of a specification. (Unless, of course, the specification itself defines different flavors, e.g. the ECMAScript spec defines loose mode and strict mode.) Oracle's implementation of Java (or implementations, since Oracle has more than one), IBM's implementation of Java, etc. are all exactly the same language. Oracle has even trademarked the name "Java" which makes it illegal to use the name commercially unless you obtain a license from Oracle, which you only get if run the testsuite and demonstrate that your "Java" …Taffy
… is 100% equivalent to everybody else's "Java". That's why Android isn't "Java", for example, because Google isn't allowed to use the name without a license from Oracle, but Oracle doesn't give a license to Google because Android is not 100% compatible.Taffy
I suppose my use or understanding of "flavor" was incorrect. What I meant for example was: Something like JAX-RS, which has different implementations (i.e. Jersey, Apache), but all do the same thing. Or how there are different JVMs. Or am I mixing up interfaces with specifications? In the Java EE world, you see man different implementations, but in Java SE, it's always OpenJDKLaissezfaire
K
16

I think the key idea here is "specification doesn't include an implementation."

When Sun was the steward of Java, they would write specifications for features like Java EE and JPA, giving other vendors the freedom to implement as they wished. Sun would usually have an implementation of their own with which to compete, but their goal was to sell hardware. Encouraging other vendors to provide competing implementations only furthered that aim.

Sun's specifications would come with neither code nor JARs; they were prose descriptions of how the code would work.

Kowloon answered 24/12, 2015 at 18:32 Comment(4)
"they were prose descriptions of how the code would work." -> What code?Amathist
The code that vendors would write to implement the specification.Kowloon
Ah, I think the mention of Java EE hit the nail on the head for me. I was confused because although I see many different JVM and GC implementations, I don't see many different Java, the language, implementations (I could be wrong). But with Java EE, there are many different implementations. This, however, kinda tangles up interfaces with specifications for me.Laissezfaire
There are multiple JVM and GC implementations: Oracle/Sun, IBM, Azure, etc. That has a specification, too: en.wikipedia.org/wiki/List_of_Java_virtual_machinesKowloon
T
5

In Java-land these specifications are started as Java Specification Requests (JSRs).

Defined here:

https://jcp.org/en/jsr/overview

Once accepted, these are specifications.

Tolbutamide answered 24/12, 2015 at 18:31 Comment(0)
S
4

If one does a Google search, one gets:

spec·i·fi·ca·tion ˌspesəfəˈkāSH(ə)n/ noun noun: specification; plural noun: specifications

an act of describing or identifying something precisely or of stating a precise requirement.

example: "give a full specification of the job advertised"

(...)

It thus means you describe how something should work, not what one has to do in order to let it work (which is the implementation)

There are formal languages to specify for instance pre- and postconditions of a method. One can then use tools to (semi-)automatically verify a subset of these conditions.

Other formal languages enable you to do automated constraint programming (like for instance my specification to solve a multi-sudoku puzzle).

Another example is CSS: you specify how your webpage should look like, the instructions on how to make a button green are not part of CSS.

Stilton answered 24/12, 2015 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.