On Sat, Apr 3, 2010 at 11:51 AM, cd34 <[email protected]> wrote: > I think IBM once stated that 23 lines of code was the limit > for bugfree code which sort of corresponds to a single screen and I've > used that as a guideline.
I've heard something similar, that a function should be no longer than a screenful, and a module no longer than a few printed pages. I'm not strict about it, some of my functions go up to two or three screens, but 20ish lines is where I start to think about extracting part of it to another function. It all depends on the local variables. If there's a chunk that uses several of its own variables, it goes into a function. But if it has lots of interactions with local variables from the surrounding code, I don't split it. Because you can't take the whole context with you unless you pass a lot of arguments or wrap them in an object. (I did create a context object for an import routine yesterday, so that I could pass several values as a unit between functions.) Another factor is how complex the code is. Somebody (Linus Torvalds?) said that if it's a long if-elif chain that just sets simple flags, there's no reason to split it. But if it's complex nested loops, that's a good reason to factor out the inner loops. -- Mike Orr <[email protected]> -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
