Saturday, December 25, 2010

Perl Best practices - Coding

Perl Best practices - Coding
Ten Essential Coding Practices by Damien conway in PBP book

1. Always use strict and use warnings.

2. Use grammatical templates when forming identifiers.

3. Use lexical variables, not package variables.

4. Label every loop that is exited explicitly, and every next, last, or redo.

5. Don’t use bareword filehandles; use indirect filehandles.

6. In a subroutine, always unpack @_ first, using a hash of named arguments if
there are more than three parameters.

7. Always return via an explicit return.

8. Always use the /x ,/m , and /s flags, and the \A and \z anchors.

9. Use capturing parentheses in regexes only when deliberately capturing, then give
the captured substrings proper names.

10. Never make variables part of a module’s interface.



Perl Best practices - Development
Ten Essential Development Practices


1. Design the module’s interface first.

2. Write the test cases before the code.

3. Create standard POD templates for modules and applications.

4. Use a revision control system.

5. Create consistent command-line and configuration interfaces.

6. Agree upon a coherent layout style and automate it with perltidy.

7. Code in commented paragraphs.

8. Throw exceptions instead of returning special values or setting flags.

9. Add new test cases before you start debugging.

10. Don’t optimize code—benchmark it.

No comments: