3 ms·
Component Simplicity
- tantalor 2y ago> Imperative code often devolves into writing things that exponentially expand the state space of your program and hoping you can find a happy path through your newly-expanded space without wrecking up too many of the other happy paths There's a good reason for this: it is the only way to run a business where the needs of customers and management changes on a constant basis. > Functional programming generally involves slicing away the state space until it is just what you need. This may be great idea for academics, but this approach is contraindicated in the field of software engineering, where the preferred solution is not the one with the "smallest state space", but the one that can deliver the most business impact with the least amount of effort. If I have to re-architect the entire program every Monday, that's not going to make leadership very happy.
- monooso 2y ago> There's a good reason for this: _it is the only way_ to run a business where the needs of customers and management changes on a constant basis. (Emphasis mine) And yet there are businesses which run on Haskell.
- HPsquared 2y agoThe most widely-used functional programming environment in the world - Excel - is very adaptable and used in business. FP lets you add things freely without worrying about side effects.
- account-5 2y agoAnd likely the cause of a lot of business errors too. But at least it's not like parts of the human genome needed renamed because of it... Wait...
- deleted 2y ago[deleted]
- naasking 2y ago> If I have to re-architect the entire program every Monday, that's not going to make leadership very happy. Good thing FP doesn't require that then.
- eyelidlessness 2y agoI think a more objective analysis would admit that it does require this, albeit sometimes not every Monday. And the article makes exactly this concession toward the end, to which I suspect GP’s comment was a glib reference. The objective counterpoint to this glib interpretation IS NOT that, in FP, one never has to rearchitect the logic narrowing a program’s state space. Instead, an objective counterpoint might be more along the lines of this: Yes, sometimes business rules evolve in a way that diverges from business logic. Yes, in a codebase that narrows its state space according to the prior business rules, that evolution may require revision to how state space is narrowed. But once that’s done, it is done. It doesn’t require adjusting dozens of special cases incidental to the previous business rules’ implementation: it only requires adjusting the special cases inherent to the business rules. That’s objective. And it’s also objective to say that whether it’s compelling will depend on the business’s tolerance for that objectivity (or in lucky cases: its embrace of same).
- prerok 2y agoI mean, isn't the problem you are mentioning because of the functionality that is assuming too much? In the sense of functions that are behemots of assumptions? It's actually easier if those functions are broken down into smaller pieces so when requirements change, you don't have to rearchitect: you just recombine them differently. And I am not speaking academically but practically: have learned the hard way to not produce the behemots but to combine functions to the desired effect in business setting(s).
- zackmorris 2y agoAn insight that might help tie functional programming (FP) and imperative programming (IP) together is that FP is spreadsheets and IP is macros (edit: recordings of human interaction and shell scripts). Ideally all business logic should be FP and event-driven interfaces are usually IP. I think of these as clusters of similar concepts: FP synchronous blocking immutable process isolation auto optimization auto parallelization higher-order methods scatter-gather, fork-join deterministic/repeatable (sometimes) reversable execution models and views in MVC ugly prefix/postfix syntax that doesn't look like algebra (not always) IP asynchronous nonblocking mutable shared state manual optimization manual parallelization generators/iterators threads, locks/mutexes nondeterministic promises/futures requiring snapshots to reverse execution controllers in MVC pretty infix syntax that looks like algebra (not always) I believe that ideally we'd write everything in FP with no IP whatsoever. So no mutable variables, no pass by reference, no iteration. Just higher-order methods and copy-on-write, with static analysis simplifying intermediate code into its fastest and/or most concise representation to run in parallel as fast as possible on multicore CPUs. Each component runs single-shot using analogs of STDIN/STDOUT/STDERR. These can fully represent models and views functionally and even declaratively. Then IP would be used to wire up components, similarly to controllers in MVP. For example when a UNIX executable blocks waiting for more data on an input stream, or more room in an output stream. The runtime/filesystem/network/OS between isolated executables is imperative. FP and IP can be unified by enforcing immutability everywhere in an IP language, then transpiling the code to reshape it between prefix/infix/postfix notation. Unfortunately I/O still can't be implemented without monads, making this psuedo-FP language impure. So there may be no way to build an entirely pure FP runtime that can respond to dynamic input/output and exceptional behavior. It would be like having a spreadsheet with no connection to the outside world, where the values of cells can't be edited, so formulas could run but they never have reason to do so. Attempts can also be made to eliminate IP altogether by providing impure functionality in FP languages by introducing monads for I/O and exceptional behavior, allowing mutation by isolating it in blocks, etc. I believe that makes impure FP languages equivalent to IP, corrupting them and defeating the point of using FP. Sometimes that makes sense though if/when we can live with the tradeoffs, or if we're porting code from IP languages that's too difficult to refactor to pure FP. Unfortunately most impure FP languages are also difficult to read by humans, limiting their adoption. Without the basic understanding listed here, the world seems to naturally head towards IP, since it most closely mimicks how humans navigate the world. IP languages tend to borrow FP concepts like monads to implement async behavior like generators, futures and promises. This sacrifices determinism and expands shared state to such a degree that IP programs can only grow to a certain size before they are intractable. This can sort of be avoided with reducers like Redux or writelog databases, usually at a cost in having to maintain boilerplate. The world also tends to double down on static types, categories, templates/generics, formal contracts/interfaces, etc, borrowed from FP without a clear understanding of when or why they're necessary. When often programs can be written much more concisely and clearly by avoiding custom types altogether and focusing on data-driven standard types like numbers, strings and JSON run through transformation functions. An obvious example being how Java programs are often bloated and overengineered because they are object-oriented instead of functional. It's amazing to see how so much boilerplate often contains so little actual business logic. And how languages inspired by Java, like C#, often seem to repeat its shortcomings. I think of all of this as analogous to how beginners tend to implement a game's main loop with state machines for each sprite. Whereas in Unity they can use coroutines. Once we see how straightforward it is to write business logic in a one-shot fashion, it's hard to imagine going back to juggling the complexities of state machines. Especially since state machines and coroutines can be made equivalent via generators. Another example is that digital electronic circuits are equivalent to a spreadsheet and can be represented and analyzed by FP, but it's hard to convert an IP program description into a circuit or analyze its behavior formally using techniques from logic. Once we have these kinds of insights, it's difficult to unsee them. And to look at best practices without asking ourselves why we're doing things the hard way. As far as I know, the only language that approximates pure FP with IP glue handled by the runtime to avoid monads is ClojureScript. Admittedly, I'm probably misunderstanding how it works.