Hi all, after being tired of telling Perl newcomers about the same problems with their code times and times again, I've decided to create this page detailing "Perl Elements to avoid":
http://perl-begin.org/tutorials/bad-elements/ I've already mentioned it several times here in replies, but thought I'll create a top-level thread for discussion. Here's my to-do list for that page. More ideas are welcome: [quote] * Add to the page about best practices: - discuss commenting. - refactoring: - magic numbers. - duplicate code. - long functions and methods. - accessing object slots directly - use accessors. - EEK - pass items from one subroutine to another. - use objects. - assign them to slots. - ^ and $ in regexes. - ambiguous. - better use \A and \z to mean start-of-string and end-of-string. - with /m can be used for start-of-line / end-of-line. - Law of Demeter - Mixing tabs and spaces. - Always add an explicit return from the subroutine. - leading underscores ("_") for non-API methods and functions. - print {$fh} @args instead of "print $fh @args" which is too easy to miss. - varvarname - using a variable as a different variable's name. - http://www.stonehenge.com/merlyn/UnixReview/col52.html - $object->new() to create a new instance. - avoid using perlform - use Perl6::Form instead (also see the text generation page). - don't overuse $_ - it's prune to errors. - C-style for loops. - Always label your loops. - Accessing the last element using $array[$#array] - use $array[-1] instead. - Array element: @array[$idx] instead of $array[$idx]. - modifying an array/hash while iterating over it. [/quote] Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ List of Portability Libraries - http://shlom.in/port-libs <rindolf> She's a hot chick. But she smokes. <go|dfish> She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/