Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jplindstrom (594)

jplindstrom
  (email not shown publicly)

Journal of jplindstrom (594)

Tuesday June 24, 2003
01:34 PM

Great habits II

[ #13042 ]
Things that belong together should go together

Minimize scope. Declare variables the closest they can be to the first place they are used.

  • The code is easier to understand, since you can see everything it does in one screen.
  • The piece of code is more cohesive and easy to extract to a method.

Document things near where they are implemented. Document the API next to the method. Document the design decision next to where it is implemented.

  • You are more likely to keep code and comment in sync if you see both. Out of sight, out of mind.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Agreed. I'm a big fan of keeping the POD right next to the method call:

    =head1 NAME

    Coffee - Virtual coffee (better, faster and stronger than Java)

    =head1 METHODS

    =head2 new()

    new() will return a Coffee object. It uses only the finest beans straight out of the sack, just in from a Brazilian coffee commune.

    =cut

    sub new {
         my $class = shift;
         my $self = bless { }, ref( $class ), $class;
         $self->_getBeans();
         $self->_grind();
     

    • Could you comment this line?

      my $self = bless { }, ref( $class ), $class;
      • ## error ## my $self = bless { }, ref( $class ), $class; my $self = bless { }, ref( $class ) || $class;
        • rather:

          ...

          ## this is an error
          ## my $self = bless {}, ref( $class ), $class

          ## this allows new() to be called as an object method ( $obj->new() )
          ## as well as class method ( Coffee->new() )
          my $self = bless{}, ref( $class ) || $class;

          ...