Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: where do you put your subs

by George_Sherston (Vicar)
on Mar 08, 2002 at 13:05 UTC ( [id://150299]=note: print w/replies, xml ) Need Help??


in reply to where do you put your subs

My practice is, if I'm writing a script called foo.pl, to write a module called foo.pm. Then all I have in foo.pl is the flow control, which is either a dispatch table or an if / else tree, made up of calls to subroutines in foo.pm. The subs in foo.pm are arranged "by order of appearance" in foo.pl.

I don't claim this is either original or perfect, but it works for me for the following reasons:
  • makes my subs immediately available for re-use elsewhere - which is a good thing in itself, but also subliminally gets me thinking about code re-use
  • enforces loose coupling - each sub has to be passed and to return all its inputs and outputs - so I am forced to think about minimising inputs and maximising usefulness of outputs
  • I'm a bit unusual in that I do all my development on a remote server. Given that, I find it useful to write each new sub in a module which I call dev.pm, which has nothing in it except (a) the sub I'm working on now and (b) some useful de-bugging shortcuts (eg print out the contents of a data structure using Data::Dumper). Then when the sub is ok, I cut and paste it into foo.pm (or whatever). So the module with the subs in it grows and grows, but I rarely look at it, whilst the files I'm working with stay slim. Saves seconds that I can use for staring blankly into space
  • foo.pl acts as an "index" of my subs

    § George Sherston

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found