Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

thinking objectively vs. functionally [closed]

As I try to increase my knowledge of functional programming, I'm finding it quite difficult to re-imagine the solutions to problems I've solved in an OOP language in terms of functions, particularly where widgets are involved. Sites like Project Euler and 4Clojure are great for learning core functions and techniques for manipulating primitive data, but what I'd really like is a resource that discusses how to idiomatically translate OOP constructs into FP, with particular attention to identifying when and how to use state. (To use a concrete example, what is the best way to implement a piano keyboard in Clojure?)

like image 346
planarian Avatar asked Dec 09 '22 13:12

planarian


2 Answers

what I'd really like is a resource that discusses how to idiomatically translate OOP constructs into FP

Don't. That's a classic XY problem.

I hate analogies but an equivalent in engineering might be to say that you've mastered metalwork and want to learn plastics by recreating the same shapes in plastic. In reality, you never want to translate what you know into what you're learning. What you really want to do is learn how to solve familiar problems using new techniques. Going back to engineering, good plastic designs are not the same shape as good metal designs. In terms of programming, solutions build using one paradigm never translate well to another. You should re-solve the problems from scratch.

like image 114
J D Avatar answered Jan 13 '23 00:01

J D


I know two books that might help:

"Functional Programming for the Object-Oriented Programmer" by Brian Marick.

"Clojure Programming" by Chas Emerick, Brian Carper and Chirstophe Grand. Chapter 12 is about how to "translate" Object-Oriented Design Patterns to Clojure.

like image 31
Rodrigo Taboada Avatar answered Jan 13 '23 00:01

Rodrigo Taboada