Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Say I want to migrate from OOP to Functional and avoid doing things the wrong way the first time, like we supposedly did with OOP and it's too late to fix. What book/code/etc is a good reference for high-quality, practical proven Functional programming best practices?


It's not an introduction, but this page collects a lot of nice info for Haskell:

http://dev.stephendiehl.com/hask/

As for "best practices", there are some interesting answers on http://stackoverflow.com/questions/842026/principles-best-pr...

There certainly aren't as many 'design patterns' style things in functional programming as there are in OO. In general, it seems to be because:

- FP systems are much smaller than OO systems (due to conciseness and not as much large-scale use)

- FP favours immutability over encapsulation, so you can re-use existing map/fold/filter/etc. functions rather than having to rewrite them in small pieces spread throughout your app. Hence you don't need to decide how they're implemented.

- Pure functions take everything in via arguments and give everything out via return values. There aren't many ways to get that wrong. In OO any method can affect the application in all kinds of ways, so there are all kinds of ways to get it wrong, requiring best-practices to avoid them.

- In FP, we're generally turning some input into some output. If we're writing code that doesn't seem to get anything from our input closer to something in our output, we should stop and think for a minute. In OO we're encouraged not to think in terms of solving a problem: instead we try to define ontologies and hierarchies, implement models of the domain, etc. only then, once we've bootstrapped a simulation of our business entities and their interactions, do we write the actual code for the problem we have: `Order::newFromFile('input.csv').ship()`


A few books that helped me:

* Real-World Functional Programming - With Examples in F# and C# by Thomas Petricek

This helped me a lot because I'd been working solidly with C# for 8 years leading up to it (C++ before, and C before that), so I was very much in C mode. It presents reasons for the functional approach and shows side-by-side C# and F# examples of the various topics covered. It also takes a more practical approach, rather than 'yet another fibonacci example' which you'll see on lots of functional programming tutorials.

* Programming in Haskell by Graham Hutton

Basically a text-book on learning Haskell, but covers a lot of fundamentalist functional thinking.

* Pearls of Functional Algorithm Design

Once you have the basics of functional programming knocked then go for this. It teaches you how to think about reducing problems.


It might be easier for those in the know to make a recommendation if they have an example of the kind of book/code/etc you're looking for on the OO side. What do you recommend for high-quality, practical proven OO programming best practices?


I have no idea. Programming is not my main area and thus I look for advice from other people to avoid doing stupid mistakes by following best practices. That being said, OO people will often point me to the design patterns book, etc. Is something similar needed for FP?

I've got the Haskell Craft book but haven't practiced enough. It seems good enough for me but, as people are learning more and more about using OO and FP in the real world (thus such criticism), I would like to keep current.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: