Programing Language Spec, What-Is vs How-To

By Xah Lee. Date: . Last updated: .

is english description of compiler source code constitute a programing language spec?

i've read most of the JavaScript spec. let's take a look at this:

js spec by algorithm 2017 02 01
ECMAScript 2015 §Indexed Collections#sec-array.from

you see js spec use algorithms as description. lots steps with abstract operations. To understand them, see ECMAScript 2015 §Abstract Operations#sec-abstract-operations

using algorithm to describe thing is hard to understand. Like, reading code, and you have to figure out what it's doing, and all side effects.

here's example of description by how-to: gcd(a,b)=a, gcd(a,b)=gcd(b, mod(a,b)), mod(a,b)=a-b*floor(a/b). what's gcd?

example of description by what-is: gcd(a,b):=n. n := max(S), S ⊂ ℕ, mod(a,n)=0 ∧ mod(b,n)=0

the what-is form is much easier to understand than the how-to. Because, reading doc IS to know what-is. Like reading API vs implementation.

the what-is is math (including computer science), and how-to is programing.

the JavaScript spec takes the approach of how-to (It specify by step-by-step instruction in English). That's unfortunate.

using algorithm as a spec is unfortunate. But using English to do that is worse. JS sec is verbosity multiplied by complexity.

No human can implement JavaScript by reading the spec alone. I surmise such result would be full of errors.

if we stick with algorithmic approach to spec, might it possible to replace the English by a program? say #haskell, #ocaml #coq?

if JavaScript spec is done via say formal proof system program, we might actually find all the loopholes in spec of English.

Programing Language Spec