Presentation is loading. Please wait.

Presentation is loading. Please wait.

Libraries of Code Notes from Wilson, Software Design and Development Preliminary Course pp137-140.

Similar presentations


Presentation on theme: "Libraries of Code Notes from Wilson, Software Design and Development Preliminary Course pp137-140."— Presentation transcript:

1 Libraries of Code Notes from Wilson, Software Design and Development Preliminary Course pp

2 What is a Library of Code?
A set of routines or modules stored for future use Module should work independently Module should contain Local variables Identifiers Assignment statements that assign values to variables used only within that module

3 Why have a Library of Code
Can copy from Library into a program If truly independent will need little or no modification Will reduce time needed to code a program Will reduce time needed to test the program (because the library code should already have been tested)

4 Reusable Code Reusable code are standard routines
Reusable code often is used to Data validation Checking format of data entered is valid for e.g. checking the user entered a valid date Date conversion Put date entered into format you need for your code. For e.g. 25th August > Converting words to numbers Once coded and tested reusable code can be stored in a library and reused in many programs

5 Using Libraries of Code
Copy and Paste Calling Modules As a subprogram The main program calls the module, follows the module’s instructions, then returns control to main program As a function Works similar to a subprogram, but always returns a value to the main program code Subprograms and functions are often passed variables from the main program

6 Sharing Variables between Main Program and Modules
Variables can be defined as Global or Local GLOBAL variables can be seen from anywhere in the main program or modules LOCAL variables are used within modules and cannot be recognised by the main program or other modules

7 Pseudocode Example of main program and modules
begin declare globalvariable1 as number globalvariable2 as date localvariable1 as number localvariable2 as date localvariable3 as number do subprogram1 localvariable3 = function1(localvariable1,localvariable2) subprogram1 statement1 statement2 statement3 end function1 (localvariable 4 as number, localvariable 5 as date) localvariable6 as number localvariable4 = localvariable6 Example subprogram, follows steps passes no variable Example function, follows steps does pass variable


Download ppt "Libraries of Code Notes from Wilson, Software Design and Development Preliminary Course pp137-140."

Similar presentations


Ads by Google