Article/Code Review

I wrote an article about refactoring roles in Ruby and was hoping some folks from the community can give it a read and provide some feedback.

http://www.joshklina.com/posts/modules-roles-mixins-and-ables-in-ruby

Thanks for looking =)

Nice article, well-written and the code is clearly presented.

One thing I’d be wary of is being overly DRY. For example, even though BookReview and Post belong to an author, I would say this isn’t true duplication (in terms of domain knowledge), but duplication by co-incidence.

It’s tempting to extract the commonality because it results in less code, but it may cause pain at a later stage, for example if you decided that anonymous users could write book reviews (but not posts).

I agree with extracting sluggable as that seems like behaviour that we’d want to be consistent across models.

The balance can be difficult to get right.

Thanks much for the read @andyw8. I really appreciate the critical feedback and your point on sharing purpose. I actually added your points to the warning section of the article to be on the lookout for code duplicated purely by coincidence as opposed actually sharing the same role or purpose (in terms of domain knowledge).