-
modularization
Hello,
I was writing some code that reads a record and selects speific files from that record. Now, I have a function set up to select certain records and then a function within that function that checks if record should be printed and prints it. Is this poor modularization practice? Should I just do the check and print inside the first function? Better visualization:
select_certain_record()
if record is desirable, sets bool variable print_record = true
print_certain_record(print_record)
if print_record = true, prints details of file
Is that unnecessary? Can one function do it all, or does that go against the whole point of modularization?
Also...Is it a wise idea to send a control variable from one function to another...seeing as how this makes the logic of the receiving function able to be manipulated by another function?
Thanks for any help.
-
It's all a matter of style and it always depends on the specific code you're writing. I don't see a problem with having the print function separate, especially if later you decide to print records outside of the select function. Of course if that's the only place you will ever, ever do the print, it wouldn't hurt to just leave the code inline with the body of the select function. The one thing that does irk me is that you pass a boolean print_record argument to the print function. I mean, it's a print function. If you don't want to print, then don't call the function. It doesn't make sense to call the print function but ask it not to print. Just say, if record is desirable, call print_certain_record(), but, to reiterate, in this case you might not want to use a separate function. It's up to you.
Module-based programming is useful primarily for keeping specific operations in a program separate so 1) it is easily readible and modifiable and 2) you don't have to duplicate the code in multiple places.
-
awesome advice lucky...I can always expect some real help when you reply. Thanks (yet again)...what you say about passing the boolean makes perfect sense...I can't believe it made sense to do that in the first place...excuse me while I find my brain *whistles and snaps fingers* :) Thanks again!