4

Either I am being a total n00b or just not with it today but I have been reading a few blogs lately and they talk about language specs. What actually is a language spec? Is php.net a language spec? The best article so far I have read is Grokbase on the PHP Language Specification.

5

A specification is a document in human language describing how a system is supposed to work. In the case of a programming language, it describes how the compiler or interpreter is to react to various inputs - which are valid/invalid, and what happens when they are executed.

A reference implementation such as "this specific compiler" is not a specification. It also defines a function from inputs to outputs, but it cannot be read by humans, you can only experiment with it. Of course you can write a trivial doc saying "everything that implementation XY does is by definition expected", but that goes completely against the point of having a spec in the first place - the implementation almost certainly contains errors, does undefined things on certain inputs that you can't distinguish from defined but complex things, conversely it behaves consistently in some way where there is really no reason to prescribe one way over the other, etc.

When you need reassurance what a program is supposed to do, when you need to stay correct even across upgrades of a runtime system, when you have to formally prove that a solution is correct, when you want to write code that must run on alternate implementations - in other words, whenever a basic "It works for me" test isn't good enough - then you need a specification, not just a running program.

  • 5
    A specification can be, at least partly, formalized: BNF for the syntax, and e.g. typing rules or denotational semantics. So it could be not entirely in "human natural language" – Basile Starynkevitch Jul 25 '14 at 11:13
  • 1
    Most specifications use, at least in part, more formalized notations, because human language is often too ambiguous for a specification – Bart van Ingen Schenau Jul 25 '14 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.