For my current Ruby project, that number is now 10. The number is slowly decreasing as I refactor. One of my goals is to get it down to about 4-5 (with most methods being 1-2 lines) which I hear is the Ruby way.
"Ruby way"? Sounds like what Pythonic is for Python.
Anyways, are you sane? 1-2 lines of method may sound like a good idea to somebody writing a book on OO and wanking to it, but in practice, methods this short do nothing, so you need hundreds of them to do shit, which means you create a huge, blOOated interface anybody trying to work with your shit has to read through to get going. I disagree with the trend to make so many tiny methods because it leads to interface complication and bloat. This doesn't mean I agree with huge ones either. Just use common sense.
Name:
Anonymous2006-04-29 14:30
It just goes to show that you aren't doing anything really useful.
Name:
Anonymous2006-04-29 20:39
>>2
Are you kidding? Super tiny methods are awesome! We must have methods so short it takes more lines to define them and string them all together! All hail the useless methods!
Name:
Anonymous2006-04-30 0:28
I'm working on a Java project right now, and due to the requirements for logging and exception handling, the average method is around 100 lines. Is this considered too big?
Name:
Anonymous2006-04-30 4:02
If a method is one or two screens long, or max three levels of indentation, that's fine. It's a matter of opinion though.
Also, "Ruby way" sounds fagtastic. Everyone hates "Pythonic", so let's not bring similar stupidity to Ruby.
Name:
Anonymous2006-04-30 6:38
>>6
Two screens? Get out, tard. I hope I never have to work on any projects with you.
Name:
Anonymous2006-04-30 7:05 (sage)
>>5
If you don't have to scroll all over the damn place or keep bouncing between files (ala spring, hibernate, ibatis, just about nearly every java framework), it's all good. If you're using one of those said frameworks, now is a good time to stop abusing XML and stop wasting time producing goop. In fact, it's a good time to just stop using Java in general.
If someone tells you you're not following best practices, throw them out the window.
Name:
Anonymous2006-04-30 9:58
>>5
100 lines is too big. Just look at your methods and I'm sure you'll find that you can cut them in 3 or 4 smaller functions, it's always been like that for me.
Name:
Anonymous2006-04-30 18:37
I agree that two screens or 100 lines is too big 99% of the times. I try them to be 10 to 50 lines, with an average of 15.
>>8
Every second is a good time to stop fapping to XML and using Java.
Name:
Anonymous2006-04-30 19:35
try them to be 10 to 50 lines,
24 * 2 = 48
Uh, that is two screens, at least by the traditional definiton.
Name:
Anonymous2006-05-01 12:28
The ruby way is the way that doesn't gracefully handle errors.
>>14
I really like Ruby but you have to write the tests yourself and they can't cover all the situations. Ruby code does not generate errors because it's highly-dynamic, but it's really TOO dynamic for some projects. And errors are called "duck-typing" in Ruby, that's why it crashes in your face without warning because you've misspelt something.
>>19
Duck-typing has nothing to do with default variable values or typos. Typos can happen in any language, and if you misspell a variable into another of the same type the same will happen even in strictly typed languages. And I don't know how's Ruby, but Python will raise an exception if you try to use a variable before setting it to something first. Perl and PHP will provide default values though.
Name:
Anonymous2006-05-04 11:25
>>20
Objects default to nil in Ruby. In most cases when I misspell a variable, I invoke a method on it, such as +, and then a NoMethodError is thrown because nil has no + method. If the nil is on the RHS, a conversion error is raised.
Name:
Anonymous2006-05-04 12:27
>>20
with Ruby, duck-typing and default values sometimes hide errors, that's why it can be dangerous
Name:
Anonymous2006-05-04 21:39
I'd like Ruby to implement something like Perl's strict mode with my().
Name:
Anonymous2006-05-05 11:49 (sage)
ruby doesn't have a strict mode?
Name:
Anonymous2006-05-06 9:33 (sage)
>>23
great idea, I was thinking something like that