What Does it Mean for Programing Language to Have a Spec

By Xah Lee. Date: . Last updated: .

Meaning of Having a Specification

Now, let me philosophizing about what does it mean for a prog lang to have spec. Let's look at the most common case, a lang without spec whatsoever, e.g. Perl. JavaScript, in its first year no spec. And php, ruby basically any lang, in the beginning is like that, Including c, cpp. Often, these been going for 10 plus years, sans any word about spec at all, not even pretend to have one.

This is how real world situation is. Basically, for a comp lang to succeed even massively popular, u no really need a spec. But often, when it became pop enough, spec start be thought about or written. But let's say, a lang being widely pop and used, but don't have anything written up about its syntax or semantics.

Is Implementation a Spec?

Now, let's think about, does a existing implementation consitute a spec. Or, what spec means exactly. E.g. Can we give some sorta precise definition, or description, what it means to have a spec.

Ok, first, a lang widely used, for 10 years at least, but no spec, but with a standard implementation. In a sense, the compiler function as a spec. e.g. u simply run the program. If it output syntax error, then, ur input is invalid syntax. In this sense, it has a at least syntax spec. And even a 100% precise one. Since computer no make mistakes. Any syntax question u have, u can simply run it, see if the compiler spit errors.

Now, about semantics, in a similar way, u can just try it out with existing implementation. Remember, the implementation, has been already massively trial and errored, for 10 plus years, in the industry. Any esoteric weird syntactic construct, is probably not of practical concern. Such as, in js, the [] + [] === "" that “Wat” vid made it very popular. Because in real world, few actually tries to do such.

Ok. So, an existing implementation, of a widely popular lang, used in industry for 10plus years, constitute a spec of some sort, perhaps, since we can simply run it to answer questions about syntax and semantics, which is what spec is supposed to do.

But now, “having a spec”, usually isn't in the sense of u run a program to get question answered. “having a spec”,normally means, u have a doc written up, detail the syntax, and on how things are. Ok, so that's the normal sense of spec. So, by now, we should conclude, those massively pop lang, such as c, php, ruby, at least in their first 10 or more years, they do not have a spec.

The Nature of Programing Language Specification

Now, what i want to say is more about the nature of the spec. That is, a written doc about how the lang works. Now, spec can come in many styles. Am no expert of compiler, actually barely understand it, and no actual experience in writting a parser or compiler. But do have some expertise in math, and programing lang issues, design. So, am just offering my opinions and ideas. (have red many specs, btw, since 1998 with r4rs of scheme lisp, and massively red all docs of comp langs cover to cover, foreward to epilog, in fact word for word, punctuation by punctuations, these includes: perl, WolframLang of over thousand pages, php doc entirety word for word, and multi versions of js spec. other spec i've glanced and reference over span of many years includes, elisp manual (1k pages), python spec, golang spec, clojure doc (entirety), racket scheme lisp doc (red almost entire)).

Now, spec has many category of styles. It can be simply descriptive, losely. It can be extremely rigorous, math style. It can be even specified in a meta programing lang. That is, the spec itself is a program. So, i think, these, gives us much varied view, and wide spectrum, on the meaning of, whether a lang has a spec. In the most lose and common sense of spec, as long as any lang has any doc written up about how it works or how it should work, we could say, it has a spec. Even extremely lousy and sloppy one.

Let me try to illustrate this point, about the wide spectrum, of rigor, in spec. Let's say python. Python has a spec, indeed.

python spec 2022-10-02
python spec 2022-10-02

Now, suppose i want to implement python. Can i, by the spec itself, create a implementation of python that is compatible with existing python implementation? Assuming am extremely capable like god. Now, i would claim, one cannot. Therefore, if my claim is corrrect, then, the python spec, isn't much a spec, or, a bad one.

Now, in contrast, java also have a spec.

java spec 2022-10-02
java spec 2022-10-02

Since the very beginning of java, in 1995. Also note the authors, james goslin, bill joy, guy steele, am familiar with their work. They are, extremely accomplished programers and at least in the guy steele case, accomplished computer scientist. (i dunno much about bill joy, except he created vi).

Measure of a Spec

Now, as far as i know, the java spec, is more of a real spec. In its quality, precision, and btw also the tech writing quality. I would imagine, a god, given a spec of java and python, nothing else, he'd create a implementation, that is far more correct, in the java case, than python. This, is the measure, of how much spec is a spec.

I would think, that the java spec, is actual working spec. The python spec, is just some guy writing up a description on how python works. (and perhaps, lacking any experience or knowledge in the area of specification in comp lang in general.). So, this is my sense, and claim, that python, do no have a spec. By the way, in the most extreme similar case, unix tools, and bash, no have spec. Despite their man pages crap.

Is Description of Source Code a Spec

JavaScript has a spec, since 1997, about 2 years after js birth. The bulk of JavaScript spec, is written in a cryptic step-by-step instruction style, e.g.

js spec by algorithm equality 2022-10-02
ECMAScript 2015 §Abstract Operations#sec-strict-equality-comparison

so, is a English translation of a programing language source code, constitute a spec? i wouldn't say so.

Now, let me say something about haskell spec. Haskell, is a lang that is associated with rigor. Rigor, is the soul of haskell. Haskell has a spec. But i recall one of the haskell major implementer/bigshot has said, haskell no have spec, around 2010. Note that haskell was born in 1990. Basically, it means, there's a lot to what it means to have a spec. From sloppy description of how one thinks the lang works by the creator of the lang (python), to something that mathematically describes how it works. It is this latter case, that haskell do not have a spec.

Programing Language Spec