Thread: modularization

  1. #1
    Registered User
    Join Date
    Sep 2004


    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:

    if record is desirable, sets bool variable print_record = true

    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.

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    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.
    Last edited by LuckY; 08-09-2005 at 08:45 AM.

  3. #3
    Registered User
    Join Date
    Sep 2004
    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function pointer modularization
    By mingerso in forum C Programming
    Replies: 15
    Last Post: 03-13-2008, 07:00 PM
  2. Modularization question...
    By Chaplin27 in forum C++ Programming
    Replies: 4
    Last Post: 08-05-2005, 07:59 AM
  3. Modularization
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 04-19-2002, 08:10 PM