3 ms·
I say "global mutable variable" to introduce the problem, followed by "global mutable state" in the summary of the first solution. The evil isn't a variable, it
by ashton314 2y ago
I say "global mutable variable" to introduce the problem, followed by "global mutable state" in the summary of the first solution. The evil isn't a variable, it's just global mutable state in general. In cases where you need state, ETS and GenServers are good solutions—we agree there. But are you suggesting that the right way to solve this problem would be to spin up a GenServer every time you need to run what should be a pure function? I'd almost rather use the process dictionary!
What I'm saying is, this problem shouldn't need state to solve it, therefore any introduction of state is a hack that will be a headache to maintain, test, and reason about.
> In the case of business logic and Elixir, this is where you may need to write your own DSL to model domain logic (DDD). It makes it makes things more flexible and more maintainable than piling together mud and hoping it won't fall over and that someone else in the future will be able to reason about it and maintain it.
I don't know what you're referring to here. What problem would a DSL solve (and how?), and what do you consider to be the mud that's being piled on?
- hi-v-rocknroll 2y agoHow else are you going to get global atomic, possibly highly-available share nothing mutable state? Magic? GenServers aren't difficult. Use the patterns rather than wincing or complaining about the lack of nonexistent wishes if you're not going to build a simpler solution. Business rules are often represented as an ordering of constraints and triggers in models when using DDD & MVC. One example in another language would be trailblazer.[0] Mud is when gobs of fragile, low-level of code is slapped together just to solve today's problem where everything is a special case without testability, architecture, standardization, or concern for maintenance or extensibility. See also: [1] 0. https://github.com/trailblazer/trailblazer https://github.com/trailblazer/trailblazer 1. https://en.wikipedia.org/wiki/Business_rules_engine https://en.wikipedia.org/wiki/Business_rules_engine
- ashton314 2y ago> GenServers aren't difficult. You're right. GenServers are wonderful and simple. I'm just saying this problem doesn't need them. > Use the patterns… I am. Monads are just another pattern. You know the `with {:ok, ...} <- ... else ... end` pattern in Elixir? That's another monad! I show one concrete example here in my post that monads cover well. I've come across other scenarios in industry where monads can cut down on boilerplate better than anything else. Would another solution work? Sure—it's a Turing-complete language. Would it be as clean? Sometimes not. > Business rules, mud I don't need definitions—I understand those concepts just fine. I'm just trying to understand why you think it's relevant to my post. What's the specific "mud" here?
- hi-v-rocknroll 2y ago> That's another monad! If you like monads, maybe you should look into Haskell or Idris. Please let me know when you write an interesting post that solves a class of problems rather than getting excited over something so trivial. Perhaps I'm jaded. Good luck to you.
- mrkeen 2y ago> How else are you going to get global atomic, possibly highly-available share nothing mutable state? This is a contradiction, unless I'm misunderstanding 'global', 'highly-available' and 'share-nothing'.