http://www.perlmonks.org?node_id=989115

Let's meditate for a while...

Latest Update: Monks, I created a follow-up thread to this one: 20 tips to avoid pitfalls while Programming Perl

Update: Monks, thank you very much for your responses. Every one of you contributed valuable thoughts. Even if I didn't reply to your post, I have read it and I'm considering what you said. I have decided to rethink my strategy and I will let you know when I am ready with something new. You may still contribute if you like, I will keep following this thread. Thanks again!

Untouched original post here:

For my work, I am trying to compile a list of the 20 most important Perl Best Practices. I don't want to have too many, because I don't want to scare people, but I want to have enough to improve the quality of the code developed by less experienced co-workers (or some careless ones). So far, I came up with 13, so I am missing 7 to complete my list. If you wish to contribute to the list, I would really appreciate it! Plus, I hope it could benefit people who read this thread.

I have read Perl Best Practices from Damian Conway (O'Reilly), I think it is a great book but I really want to limit myself to 20 best practices. Certainly, there are practices more important than others. In my opinion, there is three goals to following a set of best practices while developing Perl code:

Here is my list:

1) Place a semicolon after every statement.

Yes, the last statement inside a block can be written without a semicolon. Put one anyway. Even if there is only one statement in the block.

2) Never place two statements on the same line.

Yes, it works. But don't do it.

3) Always start your elsif or else block on a new line.

Don't put elsif or else on the same line as the closing bracket of the previous if or elsif block.

4) Always use a label on loops when using next, last and redo.

This way, if you later add another embedded loop around your next, last or redo statement, your code will not break, it will still act on the outer loop, not the new inner loop. Also, it helps readability.

5) Use lowercase characters and underscore to separate words in an identifier.

Don't use CamelCase. This is true for variables and subroutines.

6) Use CamelCase or uppercase for package names.

CamelCase is preferable over uppercase, unless it is an acronym. Never use all lowercase. Never use underscore.

7) Use uppercase characters and underscore to separate words in a constant.

Don't use CamelCase. Never use lowercase.

8) In classes, prefix subroutines with an underscore to identify an "internal use only" method.

In Perl it is not possible to create a private function like in Java or C++. Still, you should identify your methods accordingly.

9) Never use $_ or the invisible equivalent.

Always define your own variable in a foreach loop. Never use print or /regex/ with the invisible $_.

10) Never use @_ in subroutines.

Always copy it's content to your own array or list of scalar variables.

11) Always use if blocks, never postfix if statements as a one-liner.

There is an exception to this rule: when using flow of control commands.

12) Use postfix if statements when using flow of control commands.

Flow of control commands are : next, last, redo, return, goto, die, croak and throw.

13) Use unless and until as little as possible.

Unless and until could be very confusing. It is preferable to use if and while with a negative statement. Use unless and until only with positive statements so you don't create a double negative logic, which would be twice as confusing! Never follow an unless block with an else block.

Monks, what do you think? This thread is opened to debate, if you don't like what I have put in the list, please let me know, and most importantly, explain why.

Thank you!

Take my advice. I don't use it anyway.