Dimensionality of program code

Jeff Nowakowski jeff at dilacero.org
Fri Jan 18 13:50:49 PST 2013


On 01/17/2013 03:13 PM, Stewart Gordon wrote:
>
> Mathematically, a curve is considered a one-dimensional object,
> regardless of whether the space in which it is embedded has two, three
> or more dimensions. (I'm ignoring fractals here for simplicity.) If you
> consider the shape of the indented block structure to be a curve, then
> it's still one-dimensional in this respect.

I think you dismiss the embedded space too easily. We call a plot laid 
out in 2D is a 2D-plot. You use both dimensions to specify it.

> And in most languages, a program/module is essentially just a sequence
> of tokens, and as such is one-dimensional. We might look at it in a
> two-dimensional form, but this two-dimensional layout means nothing as
> far as the program structure and semantics are concerned.

Even a 2D picture can (and often is) represented as a series of ones and 
zeroes. That doesn't mean the essential 2D aspects of it don't exist. To 
say that the 2D layout of block structures "means nothing" is misguided. 
It's fundamentally there, just like the 2D picture that's been serialized.

> OTOH, because we tend to view code in a two-dimensional form, and even
> rely on line breaks and block indentation to make code readable, I can
> understand people thinking of code as 2D.

We can rely on it because the 2D aspect is there in structured code, 
even if the compiler doesn't force this layout.

> And there are languages in which the code structure is inherently
> two-dimensional, e.g. Befunge.

Even Befunge can be translated to a universal Turing machine, which is a 
linear tape.


More information about the Digitalmars-d mailing list