Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Data flow vs logic flow?

by tenya (Beadle)
on Jun 02, 2001 at 06:51 UTC ( #85145=perlquestion: print w/replies, xml ) Need Help??
tenya has asked for the wisdom of the Perl Monks concerning the following question:

Should my data follow the logic between modules, or should it take shortcuts?
I have three modules:

UserInput Module:
Default values in a BEGIN block that can be modified by the user.
Getter subs that can export these variables to other modules.
Most code is here.
Has code called by MainModule.
Uses variables from UserInput that are never used in MainModule.

Should ModuleThree get the variables directly from UserInput when it needs them,
or should MainModule get them from UserInput and pass them to ModuleThree
when it calls the ModuleThree code?

Replies are listed 'Best First'.
Re: Data flow vs logic flow?
by princepawn (Parson) on Jun 02, 2001 at 07:11 UTC
    Well, the idea of to make ModuleThree as independent and ignorant as possible about where it's input is coming from, so that even though right now you know that it's being used with UserInput, one day it could be used with data from a CGI webpage, or from a database or whatever, so I would suggest that MainModule pass them to ModuleThree.

    ModuleThree will also be easier to test since you will be able to feed it input from anywhere.

      Right. A good rule of thumb i use to keep my module interfaces clean is to make them selectively ignorant of the world around them. They can know where to send data to, but not where data is coming from.

      When i say where a module sends data to, I am referring to files/databases, functions that module calls, not the return values on its own functions.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://85145]
Approved by root
[Discipulus]: good morning nuns and monks!

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2018-06-20 06:48 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.