Skip to content

Suggestion: Mixing up behaviours and protocols #26

@Cantido

Description

@Cantido

I'd like to see something about situations where you would prefer to use protocols over behaviors, or vice-versa. This is a hard decision to make, but I think I've developed a preference for protocols.

In general, I've seen behaviours misused more than protocols, where a behaviour will expect a struct of the using module's type, basically re-creating protocols but without some compiler niceness. Passing around a module name and then calling a function on it always feels awkward. I'd rather call a function on a named module so I can make sure the function exists at compile-time. I think it's harder to misuse protocols, especially because I do think they would still work in a lot of situations where behaviours would.

Here are a few things I read about this subject which can make clear that it's a hard choice:

I would welcome a discussion; like I said this is a very nuanced decision where I think some advice would be very useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    suggestion of smellElixir-specific smells suggested by the community

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions