Hacker News new | ask | show | jobs
by erichocean 4824 days ago
Excel is not functional. It is declarative.

Alan Kay (yes, that Alan Kay[1] -- the guy that's won a Turing award) formalized spreadsheets as a limited form of first-order functional programming.[0]

[0] http://en.wikipedia.org/wiki/Spreadsheet#Values

[1] http://en.wikipedia.org/wiki/Alan_Kay

2 comments

I'm afraid you've misunderstood that Wikipedia page. It attributes the phrase "first-order functional programming" to authors other than Kay. All it attributes to Kay is the phrase "value rule".

Kay's interest in spreadsheets wasn't about functional programming, it was about interactive and dynamic computation. I have a pdf of the 1984 Scientific American article that Wikipedia is quoting from. It does include the phrase "value rule"—by which he simply meant what we would call a spreadsheet formula—but I'm pretty sure it makes no argument about functional programming (it's all images so I can't search to be sure). If you'd like a copy, email me. It's a pretty neat article, ahead of its time as one would expect from Alan Kay.

I've already read the Alan Kay article you mentioned (recently, in fact), and that's not what I took away from it.

I guess we'll agree to disagree, I don't think someone needs to use the phrase "first-order functional programming" when they give the very definition of it, which is what Wikipedia does: summarize Kay's argument.

I do agree the article itself was quite interesting, and certainly ahead of its time.

What's Kay's argument, then? And how does it relate to FP? I'm curious.

I was making a textual point about the Wikipedia article. Its use of the phrase "first-order functional programming" is hyperlinked to http://journals.cambridge.org/action/displayAbstract?aid=727.... It's not citing Alan Kay.

I guess I wasn't clear, sorry. What Alan Kay meant by the "spreadsheet value rule" and what the phrase "a limited form of first-order functional progamming" means are semantically equivalent; they are the same thing.

I have no idea if Alan Kay ever used the latter phrase, but it was easier to use that phrase here on HN than Alan Kay's made up phrase, which would have be difficult to understand without the content of the article explaining it.

Ah, gotcha. I agree with you that spreadsheet formulas are a limited form of first-order functional programming. But the memory model with which they are coupled is just as important (I have in mind the grid addressing system and dataflow semantics) and this does not fit as nicely into the FP paradigm. But I'm repeating what I said in other comments.
But the memory model with which they are coupled is just as important (I have in mind the grid addressing system and dataflow semantics)

Totally agree. My startup is using hierarchical grids as our core datatypes for just that reason (we also support Function cells that are used as values).

"Naming" is one of the core problems in computer science, and grids/spreadsheets elegantly solve that problem for many ad hoc use cases, where functional programming (in all its forms) does not.

With all due respect to Alan Kay, I don't know what he meant by "first order functional programming." If we are talking in relation to high order functions, a high order function is one that can take other functions as parameters or produces functions in return, i.e. a high order function maps functions to functions. All other functions are first order function, i.e. they are ordinary functions mapping values to values.

In that case any languages supporting function is "first-order functional programming." It's kind of meaningless when we are talking about real functional languages. PHP can define a function that takes a value and returns a value, and thus it can do "first-order functional programming." But no one claims PHP is a functional language. (Not to degrade PHP, it's a good language doing what it does best.)

All these twisting the definition of functional programming just produce more confusion.

What most C derivative programming languages call a "function" is not actually a "function" in the sense meant in "functional programming". It is more accurately called a "procedure". While you can write a "functional function" in php, there's nothing inherent about php's "functions" that makes them "functional". it's up to the programmer to make them so.

On the other hand, a "formula" in excel is inherently a "functional" function or "first order function". Why? two things: No side effects, and statelessness- that is, the order of the computation is theoretically implicit: a value can be computed in a number of different arbitrary orders without effecting the final result.-- not explicit- like in php, where you are specifying an exact order of operations by the order of statements in a procedure ("function").

Another thing about statelessness is that given the same input, a "first order function" must always return the same output.

The fact that order is not explicit in excel, that there is no user controlled "state" means that there's certain associative, commutative and compositional properties available to "first order" functions that are not possible with a procedure that is not guaranteed to be a first order function.

it's the difference between deciding to do functional programming in an imperative language, and having functional programming structurally enforced by the language.

The "pure" functions are just a subset of "procedure" functions. One can always restrict to use the "pure" function in PHP and yes, that's "first-order functional programming" in PHP. The question is: do we call PHP a functional language?

Likewise, Excel can do stateful update with side effect. The cell formula function happens to be a subset of all it can do. Sure, we can claim it's "first-order functional programming." But do we want to call it a functional language?

My point is that "first-order functional programming" is a really weak qualifier to call a language functional.

You can do "Object Oriented programming" in C++. you can also do "OOP" in plain C, but why do we call C++ an "OO Language" but not C? because the design of the language itself encourages and enforces a particular style of "OOP".

In this case, I believe the "Excel is a functional language" meme is using "Excel" not to include ALL the things that excel does, which includes things like VB and Javascript scripting, but as shorthand for the spreadsheet model of application, and more specifically aimed at Excel's formula language, which enforces the creation of first order functions by excluding the possibility of state-fulness and side-effects from the language's design. It is the fact that this is inherent in its design that merits calling it a functional language, while in php there are no such design choices which enforce or even encourage a functional way of writing code.

Another point to make is that the "Excel is functional" meme is so useful is because, as soon as you tell most programmers that "functional programming" has no variables, no state, and no side-effects, they can't imagine how it's possible to actually do anything useful in a functional language. On the other hand, most programmers do know how to do useful things in a spreadsheet program- which happens to be effectively equivalent to a stateless side-effect free "pure" functional programming language.
That's kind of false advertisement. Excel (or spreadsheet in general) is great and easy to use because of declarative programming, not because of functional programming. The functional programming aspect of it is minimal. No variables, no state, and no side-effects are mainly attribute of declarative programming.

The most important aspect of being functional, high order function, is completely missing.