This post originated from an RSS feed registered with Ruby Buzz
by Eric Hodel.
Original Post: Ruby Method Size
Feed Title: Segment7
Feed URL: http://blog.segment7.net/articles.rss
Feed Description: Posts about and around Ruby, MetaRuby, ruby2c, ZenTest and work at The Robot Co-op.
i think this is a bit silly really, i have several image processing programs that are 5000 lines of code. the longest method is around 100 lines and alreadys calls 20 other methods. breaking it down further would simply obfusicate the code. the size of methods it going to be related to the complexity of the task at hand. rather that thinking in arbitrarily limited terms like ‘10 lines’ or ‘20’ i think it’s best to always strive to write less code and the make is clear first and fast second
A good and acceptable method size should be almost entirely based on
comfort. Trying to artificially constrain yourself is only going to
lead to bad code (and stress).
My coding style (with TDD) leads to 10 to 25 line methods because
those are most comfortable.
I want to enjoy what I do as much as possible, so my “proper coding practices” come from listening to my code. My code tells me when it is too complex, too long, poorly factored or just plain ugly. If my code is telling me these things I’m not having fun, so I listen and adjust so I don’t write code the wrong way in the future.