http://qs321.pair.com?node_id=655999


in reply to Re: Perl best practices fanatism
in thread Perl best practices fanatism

The linux kernel coding standards says (amongst other good advice, some of which applies as well to Perl as C:

Functions should be short and sweet, and do just one thing. They should fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24, as we all know), and do one thing and do that well.

I think it's generally right, if you go on to read the next two paragraphs:

The maximum length of a function is inversely proportional to the complexity and indentation level of that function. So, if you have a conceptually simple function that is just one long (but simple) case-statement, where you have to do lots of small things for a lot of different cases, it's OK to have a longer function.

However, if you have a complex function, and you suspect that a less-than-gifted first-year high-school student might not even understand what the function is all about, you should adhere to the maximum limits all the more closely. Use helper functions with descriptive names (you can ask the compiler to in-line them if you think it's performance-critical, and it will probably do a better job of it than you would have done).

Replies are listed 'Best First'.
Re^3: Perl best practices fanatism
by Joost (Canon) on Dec 14, 2007 at 01:17 UTC