...
Proper indentation is very important. Just because the code lines up properly in your editor of choice, does not mean it will line up properly for someone else working on the project. This can be very annoying. These requirements will prevent this.
Tabs should be used to indent all code blocks. Spaces should never be used to indent code blocks. Mixing tabs and spaces results in misaligned code blocks for other developers who prefer different indentation settings. Consider the following code block which is indented with all tabs (shown with and without whitespaces):
|
|
|
Indented properly with tabs. | Code is lined up properlproperly. | Indentation width set changed to 8. |
...
|
|
The editor's indentation with is changed to 8. | The code remains lined up properly and easy to read. |
Comment as much as sanely possible
...
!
There should always be at least 1 space between the # character and the beginning of the comment. This makes it a little easier to read multi-line comments:
No |
---|
...
Yes | |
---|---|
#Comments are your friend, they help |
...
# Comments are your friend, they help |
...
No |
---|
...
Yes | OK | OK | |
---|---|---|---|
my $m = '00:50:56:12:88:99'; |
...
my $mac_address = '00:50:56:12:88:99'; |
...
for (my $loop = 0; $loop<=10; $loop++) { |
...
for (my $i = 0; $i<=10; $i++) { |
No | Yes | No |
---|
...
Yes | ||
---|---|---|
my $ip_addr; | my $ip_address; | sub get_comp_name { |
...
sub get_computer_name { |
...
No |
---|
...
Yes | No | Yes | |
---|---|---|---|
sub getcomputername { |
...
sub get_computer_name { |
...
my $endtime; |
...
my $end_time; |
No |
---|
...
Yes | |
---|---|
sub updateRequestState { |
...
sub update_request_state { |
No |
---|
...
Yes | |
---|---|
my $requestState; |
...
my $request_state; |
Yes |
---|
...
our $SOURCE_CONFIGURATION_DIRECTORY = "$TOOLS/Windows"; |
No |
---|
...
Yes | |
---|---|
my $ipAddress; |
...
my $ip_ |
...
address; |
All modules and subroutines must contain a POD documentation block describing what it does. POD is "Plain Old Documentation". For more information, see:
...
There should be a space between every control/loop keyword and the opening parenthesis:
No | Yes | No |
---|
...
Yes | |
---|---|
if($loop_count <= 10) { |
...
if ($loop_count <= 10) { |
...
while($loop_count <= 10) { |
...
while ($loop_count <= 10) { |
There should be a space between every closing parenthesis and the opening curly bracket:
No |
---|
...
Yes | No | Yes | |
---|---|---|---|
if ($loop_count <= 10){ |
...
if ($loop_count <= 10) { |
...
while ($loop_count <= 10){ |
...
while ($loop_count <= 10) { |
'else' & 'elsif' statements should be on a separate line after the previous closing curly brace:
No |
---|
...
Yes | |
---|---|
if ($end_time < $now) { |
...
} |
...
if ($end_time < $now) { |