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

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.
  • There isn't actually a problem in the interaction of methods and pod, when you consider that the "problem" is based on false assumptions.

    One false assumption is that methods have to be indented when you have a block class in order to be pretty; I disagree, and methods can be flush left just like their pod, so all pretty so far.

    Another false assumption is that you can't have block classes in Perl 5, and so what worked for Perl 5 can't work for Perl 6; in fact you *can* have block classes in Perl 5, and I have been doing so for years in my newer CPAN modules.

    Awhile ago I figured out a style that works well for both Perl 5 and Perl 6, that uses both block classes and flush-left methods. See http://cpansearch.perl.org/src/DUNCAND/Muldis-Rosetta-0.13.3/lib/Muldis/Rosetta/ Engine/Example.pm [perl.org] for an example.

    You write a block class in Perl 5 like this:

    { package Austria; # class

    #####

    sub foo { ...
    }

    #####

    } # class Austria

    In Perl 6, it is exactly the same format:

    class Austria {

    #####

    method foo (...) { ...
    }

    #####

    } # class Austria

    Like Perl 6, in Perl 5, surrounding the package declaration and following code with a brace pair makes it easy and elegant to have multiple package declarations in the same file, which I often exploit.

    And if one follows a practice of putting visual lines between routine declarations to make them easier to read by deliniating where routines begin and end, one can also put them before the first and after the last method. This break removes any unpleasantness of the methods not being indented relative to the class block; this also gives us another indent-level of horizontal space to use within the routine.

    -- Darren Duncan

    • There isn't actually a problem in the interaction of methods and pod, when you consider that the "problem" is based on false assumptions.

      One false assumption is that methods have to be indented when you have a block class in order to be pretty; I disagree, and methods can be flush left just like their pod, so all pretty so far.

      I had this discussion with Tene yesterday after writing the blog post. He said the same thing [perlgeek.de].

      I think I started to value indenting everything many years ago, when I wrote my first medium-sized application (in BASIC) without indentation, and got into a situation when I had to find a missing 'END' somewhere. Everything I've been doing since then has reinforced the idea that consistently indenting things is a really, really good thing.

      But you're right: making an exception in this case would solve the whole thi

    • One false assumption is that methods have to be indented when you have a block class in order to be pretty; I disagree, and methods can be flush left just like their pod, so all pretty so far.

      This is an interesting issue in Perl because now TIMTOWTDI makes a real mess of things. Frankly, I don't want my methods to be flush left because if I scan down the code, I like my indentation to instantly give me a hint of scope. If the method is indented, that gives me information that left justification won't. So let's say I have two classes in one package. The structure can look like this:

      class
          method
          method
          method
      end
      class
          method
          metho

      • Thank you, Ovid. You put words to what was only an indistinct feeling for me. I agree fully, I also don't want to sacrifice indentation within classes.

        But I also want my Pod. Maybe I'll end up putting the Pod at the end of each file, and then writing some tests to make sure the Pod doesn't drift away from the methods themselves.

      • I agree that indenting methods relative to classes does look better, and I even do that myself some times.

        Mainly I find that the indenting works best when individual classes are fairly small in the amount of code department, and similarly in those cases I generally don't use the dividing lines I mention.

        Where I don't find indenting necessary is when classes are large or there are a number of large methods (ones that fill a screen or more), so that say you've got hundreds to thousands or more of code lines i