in reply to when to use subroutine
If it makes sense to give a chunk of code a name that describes what the code does in a succinct fashion then the code should probably be in a sub.
If the same sequence of steps is performed in multiple places, they should be in a sub.
Breaking code up into subs does a few things for you. It:
There is a rule of thumb that says "a sub should fix on a page (of whatever media you use)" which is a slightly useful guide in that anything much bigger than a page you probably can't understand easily as a unit, so should break up in to smaller pieces (subs). It's ok as a guide, but the more important driver is that it makes sense for the code in the sub to be treated as an entity. It's a little like breaking a web page into a number of nested pages where you don't have to follow all the links to make sense of the top page, but if you want the detail, follow the links.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: when to use subroutine
by doom (Deacon) on Oct 29, 2007 at 06:54 UTC |