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

I think the distinction may blurry a bit, if you consider classes as a fancy way of writing higher order functions.

i.e:

You can think of a class as a higher order function, that takes in a list of arguments (constructor), and returns a list of functions, that are defined within the closure of those arguments

--

Hence, to me, the essence of these things are the same -- thought you are right that when people talk about dependency injection, they are also implying a specific way that these dependencies are provided (by the framework, usually magically)



> You can think of a class as a higher order function, that takes in a list of arguments (constructor), and returns a list of functions, that are defined within the closure of those arguments

That's a really great definition of a class (when used as a "service" class, rather than a data class or an enum class, for example). And to me, shows that FP and OOP are really two sides of the same coin. Limit OOP to immutable data structures, and you get something extremely close to FP.




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

Search: