UMBC CS 201, Fall 06
UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

Hiding Details

Functions can also be used to take the details out of main(), or to hide details from other programmers who use them.

What is the point?

Improve program readability

To make our main program simpler and easier to read. For instance, we could call a function named PrintGreeting( ) and assume that it will do just that. We have now managed to remove many lines of code that just clutter the main program. Here is an example

/*******************************************************************
* PrintGreeting( ) 
* prints an initial message when the program starts.
*
* INPUTS: none
* OUTPUT: none
* SIDE EFFECTS: prints to stdout
*******************************************************************/

void PrintGreeting( void )
{
    printf("\n\n");
    printf("*************************************\n");
    printf("*Hello.                             *\n");
    printf("*This program finds the surface area*\n");
    printf("*and volume of a sphere.            *\n");
    printf("*************************************\n\n");
}

Information hiding promotes modularity

The functional approach

This only works if we are careful to avoid (as much as possible)

We'll see more of these ideas later


CSEE | 201 | 201 F'06 | lectures | news | help

Thursday, 21-Sep-2006 13:19:33 EDT