Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Preferred method of documentation? (One comment)

by BrowserUk (Pope)
on Oct 05, 2004 at 21:35 UTC ( #396774=note: print w/replies, xml ) Need Help??


in reply to Preferred method of documentation?

...is a module about 1200 lines long....

If it's perl, and that is 1200 executable lines...

It's too damn big :)

Humour (hopefully) with a point. It's hard to believe that it takes 1200 lines to do any one thing in Perl, and a module ideally should do only one thing.

Breaking out a few sub-modules from the main, allows whatever documentation is included to concentrate on describing the function of that code, and not mix stuff up.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
  • Comment on Re: Preferred method of documentation? (One comment)

Replies are listed 'Best First'.
Re^2: Preferred method of documentation? (One comment)
by dragonchild (Archbishop) on Oct 05, 2004 at 21:49 UTC
    PDF::Template is about 2500 lines. Excel::Template is around 1800 lines. Both are unfinished, meaning they're going to grow. They arguably do only one thing and (I hope!) do them well.

    Heck, DBI is a helluva lot more than 1200 lines, and so is CGI.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Without looking, I'd bet that there are one or more subsection of each that are not used by every use of the main module and that these could be factored out into sub module(s) and required when required rather than loading everything always.

      CGI.pm certainly could do this, even allowing for the fact that it generates a lot of it's function on demand. I fully understand the motivations and temptations for people that want to "just parse the options string and print a header or two". If the major :xxx load options to CGI.pm effectively turned into

      require 'CGI::HTML4' if %opts{ html4 }; require 'CGI::download' if $opts{ download };

      I don't think it would do any harm at all.

      The only downside of that is that Perl doesn't support a use Foo::*; syntax, though writing a use wild 'Foo::*'; pragma would be possible I think.

      I have a general preference for lots of small files, rather than 1 or 2 huge ones. With editors that can hold multiple files and provide search/replace/index across all workspaces, I find the ability to be working in several places at once in different files very useful. My editor also supports having multiple views of a single file, but I very rarely use it. Years ago I used a very excellent folding editor which encouraged you to put lots of stuff in a single file and use a collapsed view to navigate. It worked great, but then compiling became a chore.

      I like to keep as much as possible to do with one unit of code in the same file as I can. Code. Interface (user) docs. Breif modification history. Unit tests. This becomes unweildy where the units are too all encompassing.

      For a very large OO module, I would seriously consider putting the class definition, initialisation, constructors and destructors into one file and moving the methods into one or more separate files and loading them as procedures.

      Anyway, it's just a preference, not an edict. The OP will doubtless make up there own mind on the matter.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
        I'll grant that CGI is not the best example of 'doing one and only one thing'.

        That's a very interesting take on code organization. I'd love to see a Meditation on that topic, if you wouldn't mind.

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

        I liked the idea of wild.pm so much, that I wrote one:
        package wild; $VERSION = 0.01; use strict; use Carp; use Module::Find; sub import { shift; foreach my $module (@_) { # at the moment we only support '...::*' if ($module =~ /(.+)::\*$/) { usesub $1; } else { croak "'$module' not supported, only '...::*'"; } } } 1;
        Currently it uses Module::Find.
        And here is a little test script.
        #!/usr/bin/perl -w use strict; use Data::Dumper; BEGIN { print Dumper(\%INC); } use wild 'HTML::*'; print Dumper(\%INC);
        Have fun,
        Uwe
      I wouldn't give CGI.pm as an example of "doing one thing"...
Re^2: Preferred method of documentation? (One comment)
by kappa (Chaplain) on Oct 06, 2004 at 12:13 UTC
    What do you think of all those nice ::Util modules? :) Not that I disagree with your opinion on big chunks of code in one file.

      It depends upon how you look at them. From the procedural point of view List::Util is a loosely related collection of disparete functions.

      If you take the OO view, then Perl's array's are a generic, ordered container class, and List::Util provides a set of extra methods.

      If only it were so easy to add a whole raft of new methods to every ordered collection type in the STL's of most other OO languages.

      I have to say that List::Util is my all-time, number-one, most used module. The only things it lacks from my perspective are mapn (also known as mapcar) and mapNbyM (to be known as zip in p6).


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://396774]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2020-11-26 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?