TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Pattern vision

43 pointsby fogusover 12 years ago

3 comments

pelleover 12 years ago
I see a lot of current libraries in the Ruby world taking this Patterns are law approach.<p>Particularly the Law of Demeter and the Single Responsibility Principle are frequent offenders.<p>You end up with something that could have been handled in one or two small classes and/or Concerns split up over 30 or so files neatly organized in a module hierarchy.<p>End result is that every single file has a single responsibility yet it's extremely difficult to see whats going on.<p>Rails 3 I think unintentionally started this. Through it's use of Concerns. This is good in a very large framework such as Rails and when the Concerns like in Rails contain a decent chunk of related code grouped together in one readable chunk.<p>I use Concerns within my own apps as well to maintain readable re useable code that can be used in multiple models.<p>If you have 20 Concerns each containing one or two methods split all over the file system it's difficult to maintain, but even harder to understand.<p>The Law of Demeter has also brought us ActiveModel wrapper classes that wrap all of this code together and when you add a column to the underlying table you can't use it with the wrapper class since it's not a real AR model. So you now have to fork the library or write your own models.<p>(edited to use the word Concern instead of the more generic Mixins)
评论 #4843104 未加载
raganwaldover 12 years ago
I saw a tweet that sums it up: "Refactoring to patterns is far more important than designing with patterns."
评论 #4843068 未加载
mcgwizover 12 years ago
tl;dr - patterns are seductive, and without understanding yagni, they strongly tend to be counterproductive.