4 ms·
One thing I've found super helpful on my current project (which happens to be node) is using OSS concepts and npm as a unit of modularity. Eg, everything is ju
by nailer 10y ago
One thing I've found super helpful on my current project (which happens to be node) is using OSS concepts and npm as a unit of modularity.
Eg, everything is just a grab bag of functions in an npm module (sometimes with a closure holding some state - I either reject or don't understand FP people when they claim FP doesn't have state).
Each module has tests, dependencies, a README, and if it is reusable by other projects, is even OSSd and published. Writing software as if it's going to be published makes me be more modular. Being modular makes things easier to reason about and therefore has stopped by codebase from becoming complex to work with.
- chowells 10y agoFP people have never claimed they don't have state. That's a straw man used to argue against something no one is saying. The claim is that there is no hidden state - everything is made explicit.
- nailer 10y agoI have no argument against FP, not am I making one here. But plenty of FP advocates claim FP "avoids state". It's not a straw man, it's just experience from asking people to explain FP.
- steinuil 10y ago> I either reject or don't understand FP people when they claim FP doesn't have state). But that's not what state is, closures are just an easier way to define lots of functions with similar parts. EDIT: Sure, you can call "whether or not f() or x are defined at the moment of calling (y) => f(x, y);" a form of "state", but this is called late binding and is simply not a thing in purely functional languages like Haskell; the existence of f() and x is checked at compile time.
- mdgart 10y ago"I either reject or don't understand FP people when they claim FP doesn't have state" FP has state, but it makes it explicit avoiding side effects inside functions and using persistent data structures, that means, instead of mutating the state you create a new state. Without state basically any program is totally useless.
- kazagistar 10y agoI think you might be confusing state and values. Pure functional programming has plenty of values. If you need a new value, you just return the new value, instead of reaching into an existing data structure and messing with it. If a function closes over immutable values, then the resulting closure is an immutable value. If a function closes over mutable state, then its mutable state, often even uglier then mutable objects or structs which actually make the exact contents easier to identify at least.