I am trying to maintain a legacy application. Already the number of lines in a particular method is over 10000 lines. 10418 to be precise.
We ended up with this many lines after a code merge activity from Parent branch.
So what is the maximum number of lines that Java can accommodate in a method and fro my information in a class.
There is a limit on the size of a method, but it isn't measured by the number of lines. It's something more like the number of bytes in the compiled version. Or something like that... why do you ask? Were you planning on making the method even larger? I would suggest that your goal should actually be to reduce the size of the method.
Jesper de Jong wrote:At the place where I'm currently working, we are striving to have no methods longer than 20 lines, and no classes longer than 200 lines.
I don't want to deraill the discussion but, while I can certainly see the point of the first target, I'm not so sure about the second. Indeed, I think you might be very hard-pressed to implement a List in only 200 lines - especially if you intend to document it properly - simply because of the number of methods you're obliged to implement.
@Selvakumar - Just to give you another yardstick: My usual rule of thumb for a method is one "page", or screenful, of code (ie, not including docs) - or, if you prefer, as much as your eye can scan without scrolling - which generally means an upper limit of 40-50 lines.
A couple more for you:
1. No more than two major levels of indentation.
2. No more than 3 parameters.
None of the above is hard and fast, but if you find yourself exceeding them, it's probably worth looking to see if you can break the logic up further.
And finally, I'd say that Tim's "Uncle Bob" quote is the most important one of all to keep in mind.
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
some times it cannot be helped, but if i find one of my methods exceeding 50 lines or so i take a closer look at it. same thing if a class gets over about 300 lines. 10000 in one method! there must be a way to refactor that.