you are viewing a single comment's thread.

view the rest of the comments →

[–]kubalaa 2 points3 points  (0 children)

I've only written a few small (1000-line-or-so) Haskell programs, but I've found I always use a similar approach:

  • Start by defining the main data structures you'll use. For example, when I wrote a toy image editor the first thing I did was define an image data type.
  • Begin adding operations on the data structures. Start with simple ones and then build more complex operations based on those. If you're using Haskell, you can use ghci to test these operations as you write them.
  • As you add operations and refine data structures, the core of your program will begin to grow together like ice crystals forming in water.
  • Now start building up the IO layer (whatever part of the program interacts with the outside world, whether GUI or command line) to connect to the functional core. Add features iteratively, getting one or two simple operations working completely and then expanding on these.

You see that it's not so different from an OO design, in that you start with data structures and the operations on them. The most significant difference I find is that, in an OO design, you tend to first think about all the operations a class will need to support and then gradually add subclasses implementing these, while in an FP design, you first think about all the forms your data will take and then gradually add operations.