REQ: Help from the programming types
I could post this to a programming discussion list. However, I’d rather not look like an idiot to anyone who doesn’t already know me to be one, at least at first.
I’m teaching myself PERL and revisiting LISP (although I may veer into Scheme instead). The former has some potential for practical application, the latter, well…
I’ve been developing software professionally for over nine years, off (school) and on (vacations and after graduation). I’m predominantly a C++ programmer, with a smattering of C#, VB, VB.Net, Java, and who knows what else. However, I’ve never really visited the realm of functional programming, outside a brief course in Scheme in… sophomore year? I can’t recall, honestly.
I’ve been reading a series of postings by Paul Graham, and he makes numerous compelling arguments for functional programming languages, particularly LISP. From a purist perspective I like the idea of a function doing exactly what it says. From a practical perspective, I like the idea of a function being directly and succintly testable.
However, I’m missing the conceptual leap of how one would go about structuring large scale applications in such a manner. I may just need some time off to think about it, but that isn’t coming anytime soon, so perhaps one of the (few) people who read this who happen to be computer types has already made the functional-programming-architectural leap might be able to push me off the cliff of ignorance?
I typically write object-oriented code. I tend to find myself spending a great deal of time in the COM interface-based world, where a strange hybrid of functional evaluation (“What’s the answer to this query?”) and state-based behavioral changes (“Activate, and start accepting input”) exist. The rest of the time I’m writing managed components, that serve as framework to components on both sides, caller and callee. Imperative programming can, to a certain extent, serve as a functional system — continuations and the ilk are far more clumsy — but I’m missing how a large application could be created in a purely functional form.
A textual description would be okay, a source sample would be ideal. Anyone know how to build purely-functional programming applications?
August 28th, 2007 at 10:11 pm
The reason that functional programming languages are rarely used as the primary language for large applications is manifold:
a. Lack of side effects. One of the fundamental principles behind functional programming languages is that your program relies on the evaluation state of functions rather than a set of nested global and local states that are modified *by* functions. Unfortunately, most of the interactions programs have with the outside world is by necessity stateful (writing to an output device, etc.) and therefore awkward to represent in a functional language.
b. Lack of a good runtime library and other interop bits. C++ and Perl, for example, enjoy native support for tremendous amounts of 3rd-party software.
c. Lack of a compiled representation. While you can describe problems better with functional languages, it is generally the case that they have to be interpreted at runtime, which is slow no matter which way you slice it. As in many cases, when you add a layer of abstraction, you incur a performance cost, and going from a functionally-oriented language to a procedurally-oriented hardware processor is expensive.
A large, modern application often glues together code from user interface libraries, operating and file system libraries, etc. And functional programming languages make crappy glue code.
Most folks just use functional languages for what they were designed for: expressing complicated algorithms and data structures simply and powerfully. Write the actual user-facing crap in a language designed for that, then call your functional language to do the hard work.
August 29th, 2007 at 7:51 am
And yet! Apparently, Erlang is used to provide 100% uptime communications infrastructure.
Apparently between monads and continuations sequential behavior is enforceable where needed, and yet the language remains lazy-evaluated. So the pieces “are” there to provide actual applications with everything they need, but, particularly the lack of side effects you noted, I’m not certain how such a thing would be done.
To a certain extent I can see how portions of the program could be structured — instead of side effects, change which function will be called via the same mechanism that specialization of function templates would. Calling a function can return a function (Yay higher order functions!), which then can control where the next function goes. For a certain portion of the universe, that could mimic the behavior of what happens when a method invocation changes a flag within an object.
However, I know I must be missing a piece; that would simply result in writing “object-oriented” functional code, which certainly misses the point of a functional language…