- Always use strict
'use strict' instructs the perl interpreter to disallow what it considers unsafe constructs. The main use of this is to prevent the use of variables that haven't been declared. This simple step prevents obvious errors caused by typos in the code. It is important to stress that it is much easier to pick up errors at the 'Syntax Check' stage than once a script is running and this statement facilitates this. - Use meaningful variable names and comment code appropriately
This aids understanding by yourself and others when looking at your code. Remember, you might think it's easy to understand now but what about in a month or three months time! - Limit repeated filtering calls
Each time a filter is used a new collection is created containing references to the appropriate objects. It is wasteful and slow, to repeatedly ask for the same thing. Perl is a garbage collected language and unfortunately the collection is not very good. In cases with lots of loops and filtering we have found that memory usage increases unexpectedly. - Minimise variable visibility
A variable is visible to all of the region of your script from the point where it is declared. It always a good idea to first declare variables near to where they are first used as it improves the clarity of the code. You should also limit the extent of code that is aware of a variable existence. This is especially important for loops where the variable's value is only meaningful within the loop. For example:my \\\$atom; foreach \\\$atom (@\\\$atoms) { .... } # \\\$atom is still valid here and contains the last 'value' assigned to it
The visibility of \\\$atom should be limited to only the loop block:foreach my \\\$atom (@\\\$atoms) { .... } # \\\$atom is no longer visible and any use of it will create an error
Similarly, variables only used within the loop should be declared inside the loop and NOT outside. This is another case of trying to find errors at the 'Syntax Check' stage. Needless to say, variables should also be used for one thing and one thing only. - Use Translate and Rotate methods when working with symmetry rather than via modifying XYZ coordinates.
The Translate and Rotate functions understand symmetry and using them will prevent any surprising results. It is also faster to use these methods as well. - Follow perl style (http://www.perl.com/doc/manual/html/pod/perlstyle.html)
