in reply to Subroutines versus straight top to bottom scripts

code structured in subroutines is usually much easier to understand, maintain and test:

On a top to botton script high level and low level ideas get "mixed" and even if it is commented, you have to read it fully to understand what it does.

Discovering which data is input and output for a particular step can also be a hard task because variables can be referenced in any place. On the other hand, when using subroutines, seen what is input and output in every step is trivial, you only have to look at the glue code between the subroutine calls.

Other problem that sometimes appear, is naming temporary vars, specially because we always try to use common names like $len, $i, $j. You have to take care to use different ones on every step or to ensure that you can reuse them without trouble or to open new scopes. When using subroutines this problem just go away.

  • Comment on Re: Subroutines versus straight top to bottom scripts