Reddit reviews Refactoring: Ruby Edition: Ruby Edition (Addison-Wesley Professional Ruby Series)
We found 5 Reddit comments about Refactoring: Ruby Edition: Ruby Edition (Addison-Wesley Professional Ruby Series). Here are the top ones, ranked by their Reddit score.
Practical Object-Oriented Design by Sandi Metz and Refactoring: Ruby Edition by Jay Fields, Shane Harvie, and Martin Fowler with Kent Beck were both invaluable for me. They’re more Ruby focused than Rails, but these will help with Rails and so much more.
I apply what I learned in these books in Python, PHP, Ruby, and any other object oriented language I happen to be using.
Extract properties into a class, so if you have a class like
User
and it has a series of address properties, create anAddress
class and extract those properties out into your new class and make sure itbelongs_to :user
. Then, if other types of classes need something similar (such as aBilling
object), you can use the same class and have that belong to that object as well.As far as naming, feel free to use whatever you want, though it might be best to use
province
instead ofstate
since the word "state" in programming means something different, not to mention a province generally covers that same kind of location as a US state does (in fact I'm pretty sure under the hood Google Maps API handles it this way as well). Also make sure you store zip codes as a string since many countries use letters in their zips and US zip codes use a dash to include localized neighborhoods or PO boxes.I'd pick up a book like Refactoring (Ruby ed.) which covers this pattern and a whole lot more.
I enjoyed this one: http://www.amazon.com/Refactoring-Edition-Addison-Wesley-Professional-Series/dp/0321984137 and http://www.amazon.com/Eloquent-Ruby-Addison-Wesley-Professional-Series/dp/0321584104/ref=pd_bxgy_b_text_z
It can be hard at first, but it's really worth it. If you surpass the 100 lines limit for a class it's surely doing too much, try splitting it into several smaller classes, or at least some concerns.
Something which can help with that is Refactoring: Ruby Edition, it's more of a senior-level book than POODR, and you can't read it from cover to cover, you have to stop at each pattern, see if you can apply it, then repeat, but it's definitely a great resource, and it helps you "develop an eye" for bad code.
Reek seems to use some smells from the Refactoring book. Not sure if all of them can be analyzed statically though.
EDIT: I didn't know Sandi was updating POODR, I think she's just working on 99 Bottles of OOP, her new book.
I second the comment to learn SQL really well. Also regular expressions come up frequently enough to be worth learning a bit about. Some familiarity with data structures is worth picking up, and getting a grasp on some common design patterns is well worth the time.
On the last point, I’d recommend Design Patterns in Ruby and Refactoring Ruby
Hope that helps.