by pixelmonkey · 12y ago · 0 comments
Pendulum now swinging back the other way. Functional, data structure oriented programming has many benefits above old-school procedural programming e.g. C, Fortran. But it also doesn't have the baggage of mainstream OO languages. Thus, this feels like an appealing -- and new -- ecosystems.
This -- along with a rediscovery of some functional concepts that seem have more importance in a distributed setting, like immutable data, purity, higher-order functions -- have led to some renewed interest.
A pure function has a very portable interface that makes it suitable for the distributed and social nature of the way we create software together.
These kinds of problems were not envisioned by the creators of the original Object Oriented systems like Smalltalk. Objects were designed for personal computers and building and using software designed for personal computers.
While shared workspace environments were explored in systems like Self, they were always designed around the objects being these visual instances running in a GUI.
Objects detached from a system like Self or Smalltalk lose a lot of their powers of abstraction. They are not and have never been portable, even if they were designed to be reusable.
Citation needed. I personally don't talk to other programmers in terms of functions, but I use plenty of metaphors and analogies that come with my evolutionary capabilities to use natural language (math, on the other hand, was something I had to learn).
Programmers talk to other programmers in terms of functions all the time. Every API you use exposes functionality. If that API assumes some sort of state, that can cause issues for the consumer of the API. It also forces whatever entity is maintaining state be tightly coupled to the consumer and leads to centralized systems.
If the API does NOT have state and instead uses a token based system for authentication and access permissions it is operating in a functional manner. State is maintained outside of the function.
The less coupled that two modules are the more portable that they are. You can bundle up something like the "express" npm package and ship that off to whomever. You can easily build modules on top of an express application by passing the entire app to another module. This pattern has been used to build an entire ecosystem of loosely coupled middleware.
These are not Object Oriented designs. They aren't entities that communicate by sending messages to one another while floating around in some global workspace. They are interfaces that pass state around as arguments to function calls.
Global state is very nicely demonstrated in how modules can be shared between Node and Browser Javascript. What is global? All of the I/O. Files, XHR, mouse clicks, sockets... all of these are the inputs and outputs and all are handled by "window" or "process" or other global state.
Modules can be easily be reused between the server and client if they do not interface at all with any sort of global state.
I seriously doubt it. In order to talk in terms of only functions, you would need to give up identity...because what is identity but not a key for encapsulated state? Without identity, you really are talking with just values, but you have problems describing things with handles. There is no single Bob, just a new Bob who is reconstituted each time you talk about him. Naming anything is weird, and the pure lambda calculus of course avoids it. Most APIs are not purely functional, but somewhat object-oriented (oriented around identity) if only in a few key aspects that are needed to do anything at all.
I predict that there will eventually be a FP backlash that reverses the situation again (hey, look how easy objects are to use vs. this crazy FP stuff!?).
But that's besides the point. I'd like to find out what gaps can be filled so you no longer find FP difficult to understand or use. What material have you tried so far?