3 ms·
The quest for modularity (2022)
- shoo 3y ago> I think that the most important part of a system design is the logical decomposition initially, and secondarily the topology (servers and pods, networks, etc). If the aspects of the logical design (domain?) are correct we should be able to arrange things in different topologies as we grow. That sounds reasonable, but defining a good decomposition initially is perhaps very hard! One concrete rule of thumb to define a decomposition is to apply Parnas' criteria: > We have tried to demonstrate by these examples that it is almost always incorrect to begin the decomposition of a system into modules on the basis of a flowchart. We propose instead that one begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision from the others. [...] -- Parnas, 1972 But, for a new domain, it's still going to be challenging to be able to identify an a effective decomposition up front. Maybe once you've built 2 or 3 instances of a similar application in a similar problem domain, it starts to be easier to figure out what an effective decomposition is likely to be up front. Another approach is to embrace the fact that you're not going to be able to decompose the system correctly up front, and figure out how to structure development to accomodate that. I.e., how do you set things up to create the flexibility to change the decomposition mid way through delivery taking into account what you've learned. E.g. if you're tossing up between a mess in 1 git repo owned by one team vs carving up the problem and handing out the spoils chunk by chunk to teams scattered across a fixed org chart, prefer the thing that makes it easier to rapidly and flexibly adapt and cheaply change decomposition: e.g. everything in a big mess owned by 1 team in 1 repo where it's possible to adjust decompositions without handoffs or external dependencies. see also > one thing grug come to believe: not factor your application too early! > early on in project everything very abstract and like water: very little solid holds for grug's struggling brain to hang on to. take time to develop "shape" of system and learn what even doing. grug try not to factor in early part of project and then, at some point, good cut-points emerge from code base -- https://grugbrain.dev/ https://grugbrain.dev/
- corethree 3y agoI think he's getting lost in the complexity of infrastructure. Not realizing the true key of what modularity is. The truth is we don't fully have a theory around all of it yet but we have a good idea about parts of it and how to maximize modularity of certain aspects of your program. The segregation of state away from pure functions is the "state" of the art right now in terms of modularity. By doing this you are maximizing modularity of your program to the greatest extent that we know of in theory. The segregation of computer logic into containers, servers, files, folders and all that other stuff are just illusions and arbitrary boxes that serve only to confuse. The most modular abstraction is the pure combinator. Once your program is in itself a combinator composed from other combinators, then and you can arbitrarily choose where you want to put them. Put one set of combinators in a container on one server or another set in a folder split among arbitrary files. Put em in libraries or don't... up to you. Again it doesn't matter... because your combinators flexible enough that you can move your combinators anywhere. The infrastructure is irrelevant and an arbitrary choice in terms of the initial design. You must choose your code abstractions such that you have the flexibility to make ANY arbitrary infra choice and the pure combinator is the one such abstraction that maximizes the amount of choices you have. The flaw with this pattern is that it doesn't include state. Hence why you need to segregate it away using a pattern called: functional core, imperative shell. The IO monad in haskell actually forces you to program with the pattern. We don't fully know how to maximize modularity when we have state and functions working together so what we do is we just try to segregate the two concepts as much as possible. By doing this we have large sections of the program that are extremely modular and small singularities of the program where we have to combine state and function. This is the front line in the quest for modularity. All the infra stuff is just fluff. What the author talks about is largely inline with what I'm saying here but he's getting a bit lost and not driving home to the key insight here that's been formalized by languages like haskell.
- lioeters 3y ago> The segregation of state away from pure functions is the "state" of the art right now in terms of modularity. I've heard pure functions described as "having no side effects". So "being pure" means having no state of its own, as well as not having an effect, changing the state of anything anywhere else. > We don't fully know how to maximize modularity when we have state and functions working together.. Doesn't that describe Object-Oriented Programming, at least some aspect of it, like classes which bind state and methods together? The difficulty, in my experience, is that there can be many, many objects with their own state, affecting each other's state in a complicated web/graph of effects. > functional core, imperative shell This approach of "pushing state up" to the surface, I think is the way to keep all states in one place, with every change under control. Better yet, to have immutable state, with every effect/change producing a new state. > Once your program is in itself a combinator composed from other combinators In this context, does a combinator mean something similar to a pure function? I see on Wikipedia: > Combinatory logic can be viewed as a variant of the lambda calculus, in which lambda expressions (representing functional abstraction) are replaced by a limited set of combinators, primitive functions without free variables. And the meaning of "free variables": > In computer programming, the term free variable refers to variables used in a function that are neither local variables nor parameters of that function. The term non-local variable is often a synonym in this context. Aha, non-local variables. That smells like global or external state. Right, I think years of programming have taught me to intuitively notice mutable state, especially when a function is trying to reach out and make an effect on some state outside itself. That goes against modularity, unless it's managed intentionally.