Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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.
MainModule:
Most code is here.
ModuleThree:
Has code called by MainModule.
Uses variables from UserInput that are never used in MainModule.

Question:
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?

Comment on Data flow vs logic flow?
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://85145]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-12-28 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls