UMBC CS 201, Fall 05
UMBC CMSC 201 Fall '05
CSEE | 201 | 201 F'05 | lectures | news | help

Hiding Details

Functions can also be used 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("*Hello.                             *\n");
    printf("*This program finds the surface area*\n");
    printf("*and volume of a sphere.            *\n");

Information hiding promotes modularity

The functional approach

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

We'll see more of these ideas later

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

Tuesday, 20-Sep-2005 14:04:13 EDT