<?xml version="1.0" encoding="windows-1252"?>
<node id="989508" title="Yet another set of Perl best practices" created="2012-08-24 08:14:12" updated="2012-08-24 08:14:12">
<type id="120">
perlmeditation</type>
<author id="446266">
salva</author>
<data>
<field name="doctext">
These are mine:

&lt;ol&gt;

&lt;li&gt;&lt;b&gt;Keep things simple.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Layering/encapsulation and good API design are the keys to good programming.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Too much abstraction is as bad as too little.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Minimize code dependencies and specially temporal dependencies:&lt;/b&gt; I specially hate the case when you have an object that requires its methods to be called in a particular order and that is manipulated from different layers. Impossible to follow code!

&lt;li&gt;&lt;b&gt;If you have to write some complicated piece of code, try to hide it behind and easy to use API.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Code flow must be easy to follow.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Perl is a powerful and expressive language, don't be afraid to use it to its maximum.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Avoid code duplication. Don't copy&amp;paste. Boilerplate is OK to a certain degree.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Make your subs/methods meaningful.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Try to avoid helper subs/methods with long lists of arguments.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Don't use an object when a simple hash or array will do.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Speed matters, scalability matters, memory usage matters, IO matters. Keep that in your mind while programming.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;When breaking some of the previous rules, document it.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Check the validity of your input (specially when dealing with external input), refuse anything you don't know how to handle&lt;/b&gt;: Note that this does not go against the [http://en.wikipedia.org/wiki/Robustness_principle|robutness principle], they are orthogonal concepts.

&lt;li&gt;&lt;b&gt;Write regular expressions as strict as possible.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Check for errors extensively&lt;/b&gt;. Don't ignore them.

&lt;li&gt;&lt;b&gt;Include internal consistence checks.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Add lots of debugging code&lt;/b&gt; so that you may be able to debug problems reported by others even when you are not able to reproduce them.

&lt;li&gt;&lt;b&gt;Depending on an external module needs a good justification.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;use strict, use warnings&lt;/b&gt;, selectively disable them when required.

&lt;li&gt;&lt;b&gt;No TDD&lt;/b&gt;, it gets on the way of my iterative design/programming thinking process (but if it works for you I am OK with it).

&lt;li&gt;&lt;b&gt;Otherwise, testing is a very good thing.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;Be consistent in your coding style.&lt;/b&gt;

&lt;li&gt;&lt;b&gt;And use a good editor that takes care of it for you:&lt;/b&gt; actually I don't care too much about cosmetics, as far as blocks are indented it is OK for me.

&lt;li&gt;Finally, paraphrasing the great Salvor Hardin, &lt;b&gt;"Never let your sense of best practices prevent you from doing what is right!"&lt;/b&gt;

&lt;/ol&gt;</field>
</data>
</node>
