alexcastano
Hello everyone,
I read some Elixir books and I did some small toy projects with Elixir. My mind is still too object oriented programming but I want to start creating “real code”, specifically, I’d like to create shrinerb in Elixir. It is an awesome library that I use in Ruby and I think it could be cool to learn some Elixir.
My question is about the integrated plugin system. The author explained it very well in this blog post Briefly, it consists some base classes with a few methods which do very little. Then the plugins overwrite those methods adding some functionality and calling super, this way they don’t conflict each other. The user can select the plugins he needs and only those plugins are loaded. I think it is very elegant.
I don’t find a way to translate this to Elixir. The only solution I can think it is to create a “middleware engine” for each method of each class, so the plugins can inject their code safely. Two ways to do this are creating something similar to Tesla middleware or using defoverridable. However, I actually see this an overkill task. I don’t have enough experience to determinate if they are Elixir-ish solutions.
What do you think? Are good solutions? Or am I translating OOP to a functional language and it does not fit? In this case, what would be your solution?
Thank you very much for your time ![]()
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 15 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
Mine had priority, they registered based on a given priority, but in general it was used by plugins, not something big.
aseigo
Message bus solutions are indeed truly powerful; but if you need / want predictable order of execution then they are more difficult (or just (d)evolve into multiple points of serialized behavior).
Not sure they are looking for a message bus solution in this case? I would expect there needing to be a predictable order of execution, and coupling steps through unwritable contracts of “when someone somewhere eventually emits message B after message A, then I’ll do something..” isn’t really so workable.
That said, I’ve used message busses in many applications in the past where order of execution wasn’t of concern, and I 100% agree with you that they are absolutely lovely in those cases.
aseigo
In which case I would suggest looking at how plug does this. It’s an elegant approach to these kinds of situations which sidesteps the whole functions-as-API design cascade, and there is no calling of prior or parent functions in any of the plugs.
OvermindDL1
Callbacks.
alexcastano
I didn’t know the library. It seems very nice to decoupling the code. However, I see lack of flow control for my use case, stop the processing for example. I could define several callbacks, before_action and after_action, where the plugins can stop the action but it feels complicated.
Same here, it is perfect to decouple the code but not to control the flow of the code.
alexcastano
If I use the name directly, plugins cannot interact with each other. Maybe the next plugin in the “middleware chain” decides to crypt the file before upload, or decides to stop the upload. This should be agnostic for plugins.
superrepresents this — go on with the middleware — but it can also be namednext_methodoryield. Middleware engines are very nice IMHO.I see I can overwrite methods, but I don’t want the user of the library to compose the logic. I showed simplified examples, but logic can be a little bit more difficult. More plugins more code and more complex.
Definitively at compile time. I don’t see the point of doing it at runtime.
Maybe my solution will be just simplifying to the maximum the API and create middleware for each method, like decorating pattern kind of.
OvermindDL1
Oh thank goodness! It is about time!
>.>
Uh, so basically what mine already is… I wonder if I should just rewrite it in Elixir and publish it so it has an elixirified API… >.>
peerreynders
GenEvent is in the process of being deprecated
Plataformatec: Replacing GenEvent by a Supervisor + GenServer
OvermindDL1
I just do plugins via
gen_event, isn’t that the easiest and most built-in way?Literally I just send an event at whatever hook points I want and let whatever is listening to them do whatever they want at that point.
gen_eventhas it’s share of problems that I fixed in an erlang replacement library long ago, like using monitors instead of links (gen_eventpredates monitors did you know? ;-)). Does Elixir have aGenEventthat uses monitors? I’ve not actually checked, I just use my Erlang library in Elixir thus far… >.>peerreynders
I don’t think this is what you’re after - but just in case - eplugin has a totally different approach to plugins.
There is a dedicated gen_server process that is responsible compiling the plugins and managing their particulars in ETS tables.