After reading @ray vernagus post about using ArcObjects with F#, I have been wondering ... what types of GIS problems are better handled by Functional Programming, as opposed to more traditional forms of programming?
Perhaps more specifically, when would I be better off using F# as opposed to C# with ArcObjects?
3 Answers 3
The single biggest reason why functional programming has come back into vogue lately is concurrency. Being able to do processing in parallel for performance reasons is becoming massively important in computing overall and GIS is no exception. Functional programming has some serious benefits in the context of creating parallel systems because of how much it emphasizes immutability and recursion. Because of these properties most functional languages tend to simply sidestep issues like locking that make parallel programming in imperative languages a massive headache.
That being said, I think the GIS field has a long way to go before you will really be able to take advantage of a lot of what functional programming has to offer. Existing technologies and libraries are simply too fixated on Object Orientation and a generally imperative approach. Sadly, just because you can use ArcObjects from F# doesn't necessarily mean the underlying libraries will actually play nice with a functional style of programming.
Not strictly programming, but ArcToolbox follows a more functional design paradigm.
- Most tools are designed to accept a set of inputs, run a function, and return the outputs without the influence of external state.
- Most tools do not edit existing layers, but create new ones (immutability).
- Many tools are similar in operation to a map function. They operate on sets of objects (feature set) rather than use iteration to process lower level objects (geometry).
- Basic tools such as union, intersect, and dissolve can solve numerous problems that would be difficult to express in a declarative language such as SQL.
The functional approach of ArcToolbox lets us do spatial analysis without needing to write code. The user can work with a simple set of elements such as layers, and not worry about iteration, maintaining state, or complicated side effects.
I am new to functional programming myself so these are just a few thoughts.
There's an interesting example of a Ray Tracer in F# that illustrates some of the strengths of functional programming, namely higher-order functions, recursion, parallelism, and pattern matching. Extending some of those concepts it would seem that raster math is one key area in GIS that functional programming might be particularly suited for.
enter image description here
edit: Here's another example from the same site: Rule 30 Cellular Automata
Another thought is that you don't have to write your entire program in F#. You can have the main program written in C# and create projects/assemblies in F# that solve specific functional programming problems. I've read you can also use ILMerge to merge C# and F# into one executable/assembly.
Lastly, there are a lot of functional programming things you can do in C# with LINQ, through its use of lambda expressions, higher order functions (Select
, Where
, etc), sequence pattern matching, etc.
-
Thanks for the link to the ray tracer. Took liberty of adding image to your answer.Kirk Kuykendall– Kirk Kuykendall2013年05月12日 15:06:19 +00:00Commented May 12, 2013 at 15:06
R
and Mathematica, which provide many GIS-related examples.