From: Josh Cheek Date: 2011-05-02T13:38:50+09:00 Subject: Re: update variables based on own value - critique please? --90e6ba53ac2e6debbf04a2439939 Content-Type: text/plain; charset=ISO-8859-1 On Sun, May 1, 2011 at 10:17 PM, Peter Ehrlich wrote: > Yes the code I add is not insignificant, and yes its a new way of doing > things when an old way would have done just as well. But this is what > made rails great! Without this thinking, we would have no capitalize > method or the other numerous rails helpers. I'm trying to imitate THAT > style. > > Well, Capitalize is part of the Ruby String class ( http://ruby-doc.org/core/classes/String.html#M001157), but even if Rails had added it, it is not added on Object. Capitalize makes sense on Strings, not on arrays or floats or sessions. In your case, you appear to always expecting self to be a hash, so at the very least, isn't it more appropriate in Hash than. And while that is one school of thought, there are plenty of other respected people in the community who think it is problematic when done too haphazardly, and a number of them who would argue that Rails fits this category. I'd be interested if someone more familiar with Rails could comment about whether the number of methods they added to core / stdlib has increased, decreased, or stayed the same. Here's a talk that presents the other perspective, you might appreciate http://rubymanor.org/videos/unobtrusive_metaprogramming/ You need to be especially concerned about this if you are writing library code. If you are writing your own code for your own app, that is one thing. But if you are writing a gem or something, then your code may find its way into thousands of different environments, where your changes to the way Ruby works could break other people's code (or theirs could break yours). Sure, if you count the changes, that is more. But that is simple > minded. Lines should be counted not as what was written but as what > must be maintained in the future. My hope is that the Object extension > remains simple and never must be touched again, which makes this code > shorter. > > Okay. How about put a comment in there that says something like "every time you edit this method, increment this count: 0" and then at some point in the future, go back and see what the count is. I suspect that any time you make an edit that would have required changing the original method, you will also be required to change one of your refactored methods. --90e6ba53ac2e6debbf04a2439939--