Functional Languages 101: What’s All the Fuss About?
infoq.com
infoq.com
I wonder, though, whether there is a tradeoff that is going unmentioned, and I suspect that it is that it makes it more difficult to reason about costs. I feel trapped when I'm writing in a language like Java, but at least the cost model is obvious to me. Am I off base here? Is there some way to develop a similar intuition about costs in an FP language?
Going purely functional (Haskell) has its own benefits but also a lot of drawbacks.
If you don't go purely functional, it doesn't make sense to avoid imperative or OO features where they make sense.
In that sense, I think languages which fuse and unify functional and OO approaches are a good strategy. There is a bit of negativity towards them, because they manage to piss off both OO evangelists as well as functional preachers, but that doesn't detract from the technical benefits of such an approach.
The name "pure FP" is a bit of a misnomer, because what people really mean by it is that instead of "side effects" we have "typed effects". The effects always appear in the types of our computations, so they're not really "side" effects anymore, they're a central part of the computation.
Lazy evaluation seriously complicates the cost model, but few languages are lazy.
It's not harder to reason about time complexity with strict evaluation. I think it's a bit harder with lazy evaluation, though. Okasaki uses both strict and lazy evaluation to achieve fast data structures.
"Ironically, pattern matching — one of the most popular features in functional programming languages — is also one of the biggest obstacles to the widespread use of efficient functional data structures. The problem is that pattern matching can only be performed on data structures whose representation is known, yet the basic software-engineering principle of abstraction tells us that the representation of non-trivial data structures should be hidden. The seductive allure of pattern matching leads many functional programmers to abandon sophisticated data structures in favor of simple, known representations such as lists, even when doing so causes an otherwise linear algorithm to explode to quadratic or even exponential time."
So far, I do not get the impression the I'm learning functional programming. Sure, I learn all about map, fold and filter. Sure I've picked this up these concept and apply them almost exclusively to my "regular job" programming in Python. But I'm not learning about functional programming.
What I mean is that assignments are simply never mentioned (so far). Everything is acting as if FP is the only natural way to program (I'm a professional programmer, but keep in mind that this book is geared towards beginners with little-to-no prior exposure to programming).
Anw, my point is that SICP will have you program a lot in FP style, but won't spend time explaining what FP is, or how is it different from your 'standard' procedural paradigms. I hear that you can write in various paradigms with Scheme, I wouldn't be surprised that they'd be mention in this book.
In short, SICP is a wonderful book that will teach you how to build (well "structure") your programs, focusing on mastering complexity to manage large systems. It's not an absolute reference about FP.
Seriously, if you're only 200 pages in, you haven't read chapter 3 yet, which delves deeply into the implications of introducing mutable state, and spends quite a lot of time exploring those implications, especially for concurrent programs. There is also some exploration into object oriented programming and alternative semantics and paradigms, including logic programming and laziness (chapter 4, iirc)
In short, I definitely don't think of SICP as an absolute reference to functional programming, especially since there are newer languages and approaches to these problems (STM in Clojure and Haskell, actor based concurrency etc) but SICP is an absolutely brilliant introduction, albeit a long one.
Based on what? I can't find a single article that would back that up.
Although I do agree that doing anything with Flash is just shooting yourself in the foot.
In my mind, functional languages and Lisp are two separate things.
Lisps can be functional, but most of them are not.
Functional programming for me has a feeling of a mathematically sound foundation: This means a statically typed language with a powerful type-system and type inference. Immutability/effect system are a big plus. Broad range of data-structures and a decent object system are nice, too.
Mathematical soundness does not require type inference. It's unclear whether it requires static typing.
And, it can easily get by with almost no type-system.