andre1sk

andre1sk

Would it make sense to have some central repository for protocols to make interop between apps/libs easier?
So we would have packages that just define a protocol that could be used by various libs apps?
(So we have protocols decoupled from packages that implement it?)

Showing Posts 1 to 10

ericmj

ericmj

Elixir Core Team

What is the problem you’re trying to solve? What interop problems exist when the protocol is inside the library?

andre1sk

andre1sk OP

multiple libs can implement same common protocol why would I want to depend on a package just to pull in the definition of protocol if I want to use implementation from different package. As example say we had CC processing protocol and a bunch of libs implementing it.

ericmj

ericmj

Elixir Core Team

With CC processing do you mean credit card processing? For that I think it’s wrong to use protocols because the credit card is a single data structure or can you show where the extension points are?

You might have the inversion of control in the wrong direction. It’s usually the library that defines the protocol that is using it, for example with a JSON encoder protocol only the JSON library is calling the protocol.

Can you give a practical example of a current protocol existing inside a library that would be better outside of the library?

andre1sk

andre1sk OP

I agree credit card processing is contrived example but if we extend to say payment processing in general might be more practical example. You might be doing a charge against CC or against bank Account or whatever else payment method etc.

ericmj

ericmj

Elixir Core Team

What is the data structure you are implementing the protocol for in your example and what is the purpose of the protocol? Credit card processing can mean many things, is it validation of the card, making a charge against the card, associating the card with a subscription or customer. Is the data structure the transaction itself, why should the transaction data structure be different for the payment method?

I can’t think of any protocol in the wild where the point of the protocol is that the user should call it. All protocols I can think of it is actually the library that defines the protocol that calls the protocol. I am probably missing some instances, but this makes me feel you are trying to use protocols for something where there are better abstractions.

I think you need to show an example of something existing in the wild that would be improved by your proposed change, it’s hard to discuss around hypotheticals and hypothetical improvements shouldn’t be the basis of a large change to the library ecosystem.

andre1sk

andre1sk OP

I am definitely not suggesting any major change just wanted to get opinions. OK lets use JSON that you brought up
say my app depends on Poison and implemented the relevant protocol for my %domainSpecificThing{} now for the sake of argument @OvermindDL1 created super optimized mega fast JSON lib I want to switch to using it if the protocol was defined in some separate package would not need much changes on my end. Getting back to payment processing operations are generally the same yet data structures would be different e.g. for bank account in US it would ABA number and Bank Account number for cc credit card number and expiration date etc.

michalmuskala

michalmuskala

Hearing about an ultra fast JSON lib, I feel somehow summoned :laughing:

The chance is, that the protocol requirement for that ultra fast lib would be different and it might offer different callbacks or options - maintaining a 100% compatibility for all the features is generally hard. Additionally, usually when implementing protocol for some library you use functions from that library in the implementation (poison is a great example, when you usually delegate the rendering back to poison after building some data structure). There’s a very high chance that switching the consumer of the protocol would require switching the implementation.

OvermindDL1

OvermindDL1

This sounds more like an plugin API rather than a protocol API. Though I’ve thought about building an in-system optimizing plugin API, I’ve not done so yet.

The reason it sounds like a plugin API instead of a protocol API is that the examples you give seem to be:

  • There is an implementation/interface, the users of it do not know what is actually implementing it.
  • There is a single library that fulfills that interface, even though many such libraries exist, you will only be using one such library at a time.

Where Protocols are for dispatch based on the type/shape of a binding’s value to different code.

Although using something like ProtocolEx you could define such a ‘plugin’ interface and even enforce only one thing implementing it pretty easily (the resolve function!), I’d not do so.

The way I would do it is via a method that even Erlang has built-in, behaviours. :slight_smile:

Specifically you have a behaviour. You have the application configuration (in Elixir it is those nice config.exs and so forth files) and one of the options specifies the library name to use for that, then the behaviour definition module just passes calls to that specified module. Now it would not be quite as efficient as doing the same in ProtocolEx (you can get rid of one of the two cross-module calls, though technically if you made macro bouncers in the behaviour it would fix that too) it is the method the BEAM is built for. :slight_smile:

And with behaviours you can even enforce at compile-time if the specific module implements it fully or not. ^.^

Hehe, use Jiffy I think it’s called, it is a C NIF JSON parsing libary that blows Poison away (though no derivations I think). ^.^

andre1sk

andre1sk OP

You are prob. right :slight_smile:

CptnKirk

CptnKirk

I’ve wondered the same thing for stream-based processing. For example, in the JVM world we have Reactive Streams: http://www.reactive-streams.org/. It defines a low-level API for other projects to implement. This low-level API allows each project to interoperate while providing higher-level APIs to their users.

This is how the JVM supports multiple RS projects (Akka Streams, JDK9 Stream, Swave, etc), with the ability of each of these projects to interoperate with each other.

In this case Elixir could have defined a reactive-streams protocol and then implemented GenStage and Flow on top of this protocol. Another project could implement this protocol and support additional DSLs or processing semantics while supporting interop (in theory).

At least I think it could have gone this way. I’m still not quite up to speed on advanced Elixir though.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New
nseaSeb
I’ve just put together a small POC exploring PDF inspection from Elixir/Phoenix: The idea is pretty simple: drag & drop a PDF in a...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews