scottstef has asked for the wisdom of the Perl Monks concerning the following question:
I didn't even know where to look for this one. I am trying to learn good programming habits as well as learning pearl.
For example:
if i was writing a progam to test for a file, if it was there to append it, if it wasn't create it. If i had to do it say 100 times for different files,what is the best way to use subroutines?
Do I create a lot of small 3-4 line very specific ones and then repeatedly call them numerous times?ie sub OpenFileOfFilenames, sub CheckToSeeIfFileExists, sub AppendFile/CreateFile.
Do I create a single large function that does all of this in one fell swoop?
Do I write a function that just calls all of the small functions and gets passed the list of arguments?
if i was writing a progam to test for a file, if it was there to append it, if it wasn't create it. If i had to do it say 100 times for different files,what is the best way to use subroutines?
Do I create a lot of small 3-4 line very specific ones and then repeatedly call them numerous times?ie sub OpenFileOfFilenames, sub CheckToSeeIfFileExists, sub AppendFile/CreateFile.
Do I create a single large function that does all of this in one fell swoop?
Do I write a function that just calls all of the small functions and gets passed the list of arguments?
What is the preferred method of writing code? How do most people do it? Create a small very specific function, and then reuse it or create a larger more powerful function. Personally I prefer a lot of tiny specific functions.
|
---|
Replies are listed 'Best First'. | |
---|---|
(Ovid) Re: A question about the best way to use subroutines
by Ovid (Cardinal) on Mar 25, 2001 at 15:43 UTC | |
Re (tilly) 1: A question about the best way to use subroutines
by tilly (Archbishop) on Mar 25, 2001 at 18:14 UTC | |
Re: A question about the best way to use subroutines
by indapa (Monk) on Mar 25, 2001 at 08:35 UTC | |
Re: A question about the best way to use subroutines
by MeowChow (Vicar) on Mar 25, 2001 at 12:30 UTC | |
Re: A question about the best way to use subroutines
by tune (Curate) on Mar 25, 2001 at 10:53 UTC | |
Re: A question about the best way to use subroutines
by arhuman (Vicar) on Mar 25, 2001 at 14:21 UTC | |
Re: A question about the best way to use subroutines
by larsen (Parson) on Mar 25, 2001 at 15:26 UTC | |
Re: A question about the best way to use subroutines
by Desdinova (Friar) on Mar 27, 2001 at 03:09 UTC | |
Re: A question about the best way to use subroutines
by petral (Curate) on Mar 27, 2001 at 08:48 UTC |
Back to
Seekers of Perl Wisdom