clojure - Should I use protocols when polymorphy is not (yet) an issue? -


i used protocols yet haven't quite got feeling using them properly. me seem pretty java interfaces advantage of having types , operations nicely separated.

besides solving expression problem understand protocols way group functionality in meaningful way.

so if have record , group of related functions operate on record define protocol. if don't have other data types participating in protocol somehow feels misusing pattern. besides, isn't adding unnecessary complexity?

is there reasoning question or @ least convention on when use protocols , when stick plain old functions?

my short , opinionated answer have no.

in opinion if aren't going have other types participating in protocol not worth minor inconvenience of using protocols. instances of protocols not automatically reload when reload file defining protocol gets little confusing. if going have code elsewhere participate in protocol, or reasonably believe might worth it, though in case have no.

my convention/rule-of-thumb:
stick plain old functions until think can spot beginnings of expression problem, use protocols.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -