Ruby Method Size
drbrain |
On ruby-talk Pistos started a thread on Method Size – Best Practices based on a previous post by me where he asks what a good method size is.
Ara responded with:
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
Which I agree with:
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.
commentComments are disabled


