jldupont
jldupont

Reputation: 96716

Erlang: multiple behaviors defined in the same module?

Q: I'd like to have an idea of the pros and cons of defining multiple behaviors in the same module file.

E.g.

 -module(someapp_sup).
 -behavior(supervisor).
 -behavior(application).

Using this sort of layout, I can save a module file whilst not loosing much on the maintainability side (the whole application is started through someapp_sup:start()).

Upvotes: 15

Views: 1597

Answers (1)

rfunduk
rfunduk

Reputation: 30432

As long as the callbacks defined in the behavior don't conflict with a callback of another behavior (say you defined your own behavior, for example) then there's nothing wrong with doing this other than potentially more confusing code. Obviously you can curb that with some well placed comments and laying the code out sensibly in the file.

Upvotes: 19

Related Questions