Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • 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:
      #Comments #Comments are your friend, they help
      #other #other developers understand your brilliance.
    • Yes:
      # Comments Comments are your friend, they help
      # other other developers understand your brilliance.

Subroutine & Variable Names

  • All subroutine & variable names should be meaningful.  Don't be stingy or lazy.
  • Single letter variable names should never be used unless for a loop iterator:
    • No: my $m = '00:50:56:12:88:99';
    • Yes: my $mac_address = '00:50:56:12:88:99';
    • OK: for (my $loop = 0; $loop<=10; $loop++) {
    • OK: for (my $i = 0; $i<=10; $i++) {
  • Avoid abbreviations:
    • No: sub get_comp_name {
    • Yes: sub get_computer_name {
    • No: my $ip_addr;
    • Yes: my $ip_address;
  • Use underscores to separate words:
    • No: sub get_comp_name getcomputername {
    • Yes: sub get_computer_name {
    • No: my $endtime$endtime;
    • Yes: my $end$end_time;
  • All subroutine names should be entirely lowercase:
    • No: sub updateRequestState {
    • Yes: sub update_requestrequest_state state {
  • All variable names defined in subroutines should entirely lowercase:
    • No: my $requestState;
    • Yes: my $request_state = $self->data->get_request_state_name()state;
  • All class variables defined at the top of a .pm file should be entirely uppercase:
    • Yes: our $SOURCE_CONFIGURATION_DIRECTORY = "$TOOLS/Windows";
  • Never mix upper and lowercase:
    • No: my $ipAddress;
    • Yes: my $ip_address;

...

Curly Brackets, Parenthesis

  • There should be a space between every control/loop keyword and the opening parenthesis:
    • No:
      if($loop_count <= 10) {
    • Yes:
      if

...

    • ($loop_count <= 10) {
    • No:
      while($loop_count <= 10) {
    • Yes:
      while ($loop_count <= 10) {
  • There should be a space between every closing parenthesis and the opening curly bracket:
    • No:
      if ($loop_count <= 10){
    • Yes:
      if ($loop_count <= 10) {
    • No:
      while ($loop_count <= 10){
    • Yes:
      while ($loop_count <= 10) {

If/Else Statements

...

  • 'else' & 'elsif' statements should be on a separate line after the previous closing curly brace:
    • No:
      if ($end_time < $now) {
         ...
      } else {
         ...
      {color:#000000}}** Yes:
      if ($end_time < $now) {
         ...
      }
      else {
         ...
      }