I am writing some lesson materials for a course that starts in a couple of weeks. I chose Clojure as a new language for students to learn. I would like to dedicate one chapter to refactoring imperative code to functional code. For this I would like to have a set of practical problems that are not far fetched by which I could show how imperative and functional solutions compare. Preferably the problems do NOT have an emphasis on math, like project Euler, but are problems that an average programmer needs to deal with on a regular basis. Who has got some good sources for this?
Partial answer: one such source is http://langref.org/. More wanted!
While not really practical (because practical problems short enough to be presented in a class tend to be a little boring), programming the Game of Life is one of my favorite ways to learn a new language. As a bonus, the functional approach is quite different (and more elegant) than imperative solutions. Additionally, any sort of problem where you're manipulating sequences of data (say, analyzing a sequence of tweets for word frequency, or something) makes for cool examples.
It's an old chestnut, but just implementing a factorial function in various different ways is quite illuminating. Another common example is a prime number generator, which can be a bit larger.
I realise both of these are maths examples, but they only require basic knowledge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With