47
Module 1 Objectives By the end of this module, you should be able to: Identify the components of a computer system. Identify input and output devices. Explain the importance of the computer's processor. Explain how high level programming languages work. Explain why software portability is desirable. Distinguish between main and secondary memory. Distinguish between system software and application software. Components of a Computer System The term computer refers to a system that is made up of many components, or parts. Computer systems are made up of: Hardware components the hardware components are made up of the electronic and mechanical parts. Software components the software components are made up of the computer programs and the data. The software components are stored on the computer's hardware components. Hardware Components The major hardware components of a computer system are: Processor Main memory Secondary memory Input devices Output devices The processor, main memory and secondary memory are inside the system unit. The system unit is the metal box that we refer to as the computer.

Module 1 Objectives - Mr. Gaunce Assignments Pagemrgaunce2.weebly.com/uploads/5/9/3/7/59379599/modules_1-4_notes... · Every component of your computer system that is outside the

Embed Size (px)

Citation preview

Module 1 Objectives

By the end of this module, you should be able to:

Identify the components of a computer system.

Identify input and output devices.

Explain the importance of the computer's processor.

Explain how high level programming languages work.

Explain why software portability is desirable.

Distinguish between main and secondary memory.

Distinguish between system software and application software.

Components of a Computer System

The term computer refers to a system that is made up of many components, or parts.

Computer systems are made up of:

Hardware components —the hardware components are made up of the electronic and mechanical parts.

Software components —the software components are made up of the computer programs and the data.

The software components are stored on the computer's hardware components.

Hardware Components

The major hardware components of a computer system are:

Processor

Main memory

Secondary memory

Input devices

Output devices

The processor, main memory and secondary memory are inside the system unit. The system

unit is the metal box that we refer to as the computer.

Your monitor, keyboard and mouse are outside the system unit. The monitor is considered an

output device and the keyboard and mouse are considered input devices.

Input and Output

Input and output operations are so common that an abbreviation has been created for them: I/O

(pronounced eye-oh). I/O operations are very complicated at both the hardware and software

levels. The reason they are so complicated is because the way in which data is organized

outside the computer is different from the way it is organized inside the computer.

In the picture, each red dot represents a piece of data waiting its turn to be input. Each blue

square is the processed information leaving as output. Inputting data is usually referred to as

reading data and outputting data is referred to as writing data. The information that comes out

as output is not usually the same as the data that was input. It has been processed inside the

computer system.

Input and Output Devices

Every component of your computer system that is outside the processor is either an input

device or and output device.

Input Device —an input device is used to bring data into the computer system.

Input devices include:

Keyboard

Mouse

Microphone

Output Device —an output device is used to send information out of the computer system.

Output devices include:

Monitor, Printer, Speakers

Input and output devices are usually called I/O devices. Each device is directly connected to a

device controller inside the system unit. For example, your computer's speakers are directly

connected to an audio card such as Sound Blaster. The audio card is connected to the rest of

your system.

The Computer's Processor

Inside the computer box you will find the processor, sometimes

called the CPU or central processing unit. The processor is a

small, electronic device that is about 2.5 cm square.

The processor is the brain of the computer system. All basic

computing is carried out by the CPU. The CPU also directly or

indirectly controls all the other parts of the computer system.

Different types of computers have different types of processors.

At the Processor's Electronic Level

As a computer program runs, the processor constantly performs many tiny electronic

operations. These operations might include reading a byte of data from main memory into the

processor or testing one of the bits in a byte to see if it is a 1bit. Today's processors can perform

several hundred types of small operations.

These types of operations are the only things that a processor can do. Also, everything that a

processor does is built out of tiny operations like those described above. The operations are

performed one at a time.

Fortunately for us, with today's high-level languages, we do not need to know the details of

these operations to write programs.

Executable Programs

The processor performs machine operations, one after the other. Several thousands of

operations can occur every second.

Machine instructions tell the processor which operations to perform and when to perform

them.

The processor can only understand machine language instructions. A machine language

program, more commonly referred to as an executable program, is a collection of machine

instructions. These instructions are held in main memory and executed, one at a time, by the

processor as the program runs, or executes.

To summarize:

A machine language program is a sequence of instructions held in main memory.

A machine instruction is a single instruction in a machine language program.

The processor runs a program one machine instruction at a time, performing one operation at a time.

All the machine instructions together make an executable program that does something useful.

High Level Programming Languages

Most programmers do not write programs in machine language. Most programs are created

using high-level programming languages such as Visual Basic, C, C++ and Java. With a high-

level language, the programmer creates a program in plain, human-readable text that contains

very large and powerful operations. The operations will later be converted into many little

machine operations.

For example, here is a line from a program in the Java language:

int sum = 10;

The machine operations for this line of Java code will:

Set up a small part of main memory to hold a number.

Store the number 10 in that section of memory.

Assign a name to that space in memory so that other parts of the program can find and use the number that is stored there.

It might take a hundred or more machine operations to do all of this. Luckily, the Java

programmer can ask for the processor to do all of these hundreds of operations just by writing

the Java statement shown above.

Do You Know the Difference Between Hardware and Software Components?

Decide how each of the five images shown below should be categorized.

How High Level Programming Languages Work

High-level languages work as follows. They are:

Written in plain text in a text editor

Saved in a source file

Translated (and sometimes interpreted) before executing

Executed as a useful program

Source code:

The programmer writes lines of text created with a text editor such as Notepad.

The lines of text are saved in a file on the hard drive.

These lines of text are called the source code.

The file in which the source code is saved is the source file.

The text in the source file can be edited with a text editor and printed on a printer.

The source code does not contain any machine instructions so it cannot be executed (made to run) by the processor at this stage.

Translator:

Source code is usually translated into a machine language program.

An application program, called a translator or compiler, uses the source file as input and translates it into machine language instructions to produce an executable program as its output.

At this stage, the executable version of the program can be copied into main memory and made to run.

The word compile means the same thing as translate.

Interpreter:

Some high-level languages, such as Java, add additional steps before the program can be executed.

The extra steps involve an interpreter.

The interpreter is located in the computer's main memory along with the program's compiled source code.

There are different interpreters for different processors, such as Intel, Unix, Linux, Solaris, etc.

The interpreter acts like the computer's processor, making it look like the computer's processor is executing the Java code.

You might wonder why this extra step involving an interpreter would be added. This extra step

with the Java language adds a very desirable characteristic to the language that other popular

languages, like C++, do not have. This characteristic is portability. This means that all Java

programs can be run on any platform, unlike C++, as long as the Java interpreter for that

platform is installed. When you compile a C++ program on your Intel Pentium computer, it will

only run on the Intel platform. If you compile it on a UNIX platform, it will only run on the UNIX,

etc. We will look at this term portability in the next lesson.

Portability

In an ideal situation, a program only has to be written once in a high-level language. The source

file can then be translated into multiple executable files with each file containing the correct

machine instructions for the processor on which it will run. For example, a source file is created

and translated into an executable file for Pentium processors. Then, the same source file is

translated into an executable file for Macintosh processors.

This idea of using one source file for executable programs that run on different processors is

called software portability. Basically, software portability means the ability to write a program

once in a high-level language and then being able to run it on any computer system regardless

of the type of processor that system has.

Programs that are written in the Java programming language are portable. Programs written in

C++ are not portable.

Memory

As we have already seen, the processor is the computer's brain, where all basic computing

takes place. The processor has very little memory. It relies on the memory capacity of other

components in the system to hold data and programs and to save results once data is

processed.

There are two fundamental types of memory, main memory and secondary memory.

Characteristics of main memory:

Closely connected to the processor

Its contents can be quickly and easily changed

Holds the programs and data that the processor is working with at the time

Interacts with the processor millions of times per second

Characteristics of secondary memory (hard disks/removable storage):

Connected to main memory through the bus and a controller

Contents can be easily changed but the change is slow compared to main memory

Used for long-term storage of programs and data

Only occasionally interacts with the processor

Main Memory

Main memory is where programs and data are kept when the

processor is actively using them. Once a program and data

becomes active, they are copied into main memory from

secondary memory. Once in main memory, the processor can

interact with them. A copy of the program and data still remains

in secondary memory. Moving instructions and data from main

memory into and out of the processor is very fast.

Nothing permanent is kept in main memory. Sometimes data is placed in main memory for a

few seconds but the data stays there only for as long as it is needed.

Main memory is often referred to as RAM or Random Access Memory. Random means that the

memory cells can be accessed in any order. When you hear someone say that their computer

has "128 megabytes of RAM," they are talking about how big their computer's main memory is.

Secondary Memory

Secondary memory is where programs and data are stored on a long-term basis. Hard disks

and removable storage devices such as CDs and USB drives are the most common secondary

memory storage devices.

Characteristics of hard disks:

Large storage capacity, compared to main memory

Usually found inside the computer system

Used for long-term storage of programs and data

Programs and data on the hard disk are organized into files.

Characteristics of removable storage:

Used mostly for transferring software and data between computer systems or for back-up of software and data

Very slow compared to other storage devices

The table below compares main memory and secondary memory:

Main Memory Secondary Memory

Fast Slow

Expensive Cheap

Low storage capacity Large storage capacity

Connects directly to processor Not connected directly to processor

Programs and Memory

When a program is running, a section of main memory is allocated for the data the program is

using. Memory allocations can change as many times as the program needs. For example, if a

program is adding a list of numbers, the sum will be kept in main memory at a certain location.

As new numbers are added to the sum, the sum will change and therefore, the memory location

will have to be changed also.

Other sections of main memory might not change at all while a program is running. For

example, the memory allocation for the instructions that make up a program does not usually

change as the program runs.

When you write a computer program in most languages, you do not need to keep track of

memory allocations or the contents of these locations. Part of the purpose of a programming

language is to do these things automatically.

Files and Operating Systems

Secondary memory devices such as hard disks and USB flash drives are used for long-term

storage of information such as programs and data. Disk memory is usually organized into files.

A file is a collection of information that has been given a name and stored in secondary

memory.

Files can be quite large. Their size is measured in kilobytes or megabytes. One of the jobs of

your computer's operating system is to keep track of file names and where they are located on

the hard disk or USB flash drive.

When a user calls for a program to execute, the operating system must find the program files

that are needed and copy them into main memory. As the program runs, it asks for additional

information stored in files on the hard disk. The operating system must locate these files and

copy them into main memory.

When an application program is running, it is constantly asking the operating system to perform

file manipulation tasks and then waits for these tasks to be completed.

We will study files in more detail in upcoming lessons.

Software

Software is the collection of programs and data that a computer uses. Software is stored on a

hardware device such as a hard disk or CD-ROM.

Software consists of both programs and data. Programs are a list of instructions for the

processor. Data include any information that the program needs. The data could be character

data, numerical data, image data, audio data, etc.

Types of Software

There are two categories of software programs:

1. Application programs

2. Systems programs

Application Programs

Application programs, or applications, are the programs

that people use to do their work. MS Word and MS Excel

are examples of applications.

Systems Programs

Systems programs keep all the hardware and software

running smoothly. The most important systems program is

the operating system. Modern operating systems such as Windows come with a user interface.

The user uses the interface to interact with application programs through windows, buttons,

menus, icons, the mouse and keyboard. Other examples of operating systems besides

Windows include Unix, Linux and Solaris.

Let's Review!

Module Assignment

Once you are ready, you may proceed to the assignment for Module 1. Assignment 1 can be

found on the webpage.

Module Test

You must also write the quiz for Module 1.

Module 2 Objectives

By the end of this module, you should be able to:

Explain how programs and data are stored inside a computer.

List and describe five generations of programming languages.

Identify the significant events in the evolution of programming.

Identify influences and trends in programming.

Identify the best programming language.

Storage of Programs and Data

Have you ever wondered what happens inside the computer when you press one of the keys on

the keyboard—the letter D, for example? In what format is the letter D stored inside the

computer's memory?

When the letter D goes into memory, it does not look like the letter D on your keyboard. It, like

all other characters, is represented by a combination of on and off electrical switches.

Programmers generally refer to an on switch as a one (1) and an off switch as a zero (0). Since

these switches have only two values, the zeros and ones are called binary digits, or bits, for

short. Therefore, characters are represented inside the computer as bits.

Every character input to your computer is represented by a different combination of eight ones

and zeros, or bits. These eight bits are known as a byte. If there were less than eight, there

would not be enough combinations of on and off switches to represent all the possible

characters, including uppercase, lowercase, digits and special characters such as *, % and ^.

Storage of Programs and Data (Continued)

To develop a system of representing characters, all the possible combinations of eight ones and

zeros from 00000000 to 11111111 were recorded in a table. Then, one character was assigned

to each combination. This table of characters has since been adopted and standardized in the

computer industry and is now known as the ASCII table, the American Standard Code for

Information Interchange.

The following table shows a partial listing of the ASCII characters:

Character ASCII code Decimal Equivalent

Space 00100000 32

0 00110000 48

1 00110001 49

2 00110010 50

3 00110011 51

9 00111001 57

? 00111111 63

A 01000001 65

B 01000010 66

C 01000011 67

a 01100001 97

b 01100010 98

Each of the ASCII values also has a corresponding decimal number associated with it. The

ASCII code is what the computer uses to distinguish one character from another.

Imagine, as a programmer, if you had to write all of your code in ASCII instead of plain text!

Fortunately, one of the advantages of today's high-level programming languages is that they let

you use the more human-friendly characters entered from the keyboard. The programming

language then converts the characters to the eight-bit binary ASCII values used inside the

computer.

So, in answer to our initial questions at the beginning of the last lesson, the keyboard D is not a

D once it leaves the keyboard. Once it leaves the keyboard, it goes into the computer's memory

as the ASCII value 01000100. In order to output the letter D to the printer, the computer must

send the ASCII value to the printer. The printer must make the output readable to people, so the

printer references the 01000100 value in its own ASCII table and prints the D to the paper.

Generations of Languages

In this lesson, we will categorize programming languages into categories known as

generations. The characteristics of each generation loosely parallels the evolution of computer

hardware architecture.

First Generation Languages (1GLs)

A first generation language is machine language.

Machine language is the only language that a processor understands and is the only language that can be directly executed without the need for a translator.

Only use the binary symbols 0 and 1

Every computer program, regardless of the programming language in which it is written, must be converted to machine language either by a compiler or an interpreter.

Machine language is not portable.

Second Generation Languages (2GLs)

Second generation languages are called assembler languages.

Use symbols that an assembler then translates into machine language.

Assembler language is not portable.

Third Generation Languages (3GLs)

Third generation languages are high-level languages that use English-like instructions.

Have strict syntax or "grammar" rules that must be followed

Use interpreters or compilers to translate instructions into machine language

May be procedural (follows a specified sequence of steps) or non-procedural (specifies what to do without describing the sequence of steps to do it)

Many are portable

Include well-known languages such as FORTRAN, BASIC, C++, Java and Visual Basic

Fourth Generation Languages (4GLs)

Fourth generation languages are non-procedural (specify what to do without describing the sequence of steps to do it.)

Use simple, English-like statements

Their most important features include databases and the ability to query databases as well as the ability to generate code and graphics.

Most commonly used for accessing databases

Three categories: query languages such as SQL, report generators and application generators

Fifth Generation Languages (5GLs)

Used to create programs employing artificial intelligence and expert system technology

They are natural languages that allow end users to access stored data and interact with the computer using ordinary words.

Commonly used to query databases

These languages are in the early stages of development and only a few are available for commercial use.

Examples are Lisp and Snobol

The Early Years

This lesson traces the most significant advances in the development of programming languages

in the early years of computer programming. These advances have been broken down into six

categories.

Programmers as Hardware Experts

The earliest computers were not programmed in the same way as today's computers.

The earliest computers' memories held only data. Their memories did not hold programs.

The programs had to be physically wired into the machine by the programmer.

Programming these computers was very difficult. If a change was needed, the programmer had to reroute wires to make the changes.

The first computer programmers were hardware experts, not software experts.

The Stored Program Concept

John von Neumann is credited with devising the stored program concept.

With this idea, von Neumann demonstrated that a program could be stored in a computer's memory along with the program's data.

His concept was instrumental in moving programs out of wired hardware and into the computer's memory and was one of the most important and lasting advances in the entire history of computers. It changed the face of programming forever.

Enter the Keyboard

As computer architecture evolved and the keyboard was added, it became possible for the programmer to type program statements as words rather than as the ones and zeros of machine language instructions.

These words, called mnemonics, are associated with the ones and zeros of machine language and were easy-to-remember abbreviations for the instructions.

Assembler Languages

Of course, the computer could not understand the mnemonics, so a translator called an assembler had to be written to act as the go-between for the programmer's mnemonics and the 1s and 0s to which they were translated.

The assembler produced a program in assembler language.

The first two programming languages—machine language and assembler language—are called low-level programming languages.

Low-level languages are rarely used today.

High-Level Programming Languages

Once low-level assembler languages became available, more companies began using computers.

With the increased use of computers came the need for more complex software applications.

Low-level assembler languages were not efficient enough to meet the increased needs so the earliest high level languages—FORTRAN and COBOL—were born.

After FORTRAN and COBOL, different languages began appearing all over the place.

FORTRAN stands for FORmula TRANslator. It was used for the mathematical and scientific side of

computing. FORTRAN worked very well with high-precision numbers and had an excellent library of

built-in trigonometric routines for the developer of scientific applications.

COBOL stands for COmmon Business Oriented Language. It was a language designed for the business

side of computing. It was designed to be a language that could process a large amount of business data

such as inventory and personnel records.

Structured Programming

During the 1960s, expensive computer systems sat idle while programmers struggled to write the increasingly more complex programs that users were demanding.

New ways to program, not necessarily new languages, were needed.

Out of this demand for programs that would work better and faster and that were more maintainable, came the implementation of structured programming techniques.

Structured programs were procedural rather than non-procedural.

Structured programming techniques improved the programmer's ability to program productively.

Do You Remember?

Earlier in this lesson you learned how programming languages changed and evolved with time.

Can you identify the different generations of programming languages?

Modern Day

Programming languages have come a long way since the original COBOL compiler. Techniques

and tools have been created to allow the programmer to deal with increasingly larger and more

complex problems. Each new language that appears on the market brings the promise of a

faster learning curve and more maintainable code.

Pascal

A general purpose programming language that supported both scientific and business concepts.

At the time of its development, Pascal's biggest advantage was that it was the first major language to support structured programming concepts. It also offered more maintainable code and free-form use (white spaces to make the code more readable.)

C

The fundamental structures of both the C and C++ languages are based on Pascal.

The C language grew out of the need for an efficient, maintainable high-level language.

C is referred to as a high low-level language, meaning that it supports all the programming constructs of a high-level language but also compiles into an efficient code that runs almost as fast as assembler language.

C became an important language in the 1980s and even though its use has declined over the years, it is the foundation language for the popular C++, Java and C# languages in use today.

The BASICs

BASIC, which stands for Beginner's All-purpose Symbolic Instruction Code, was originally developed for teaching beginners how to program.

Over the years, BASIC has been distributed in many different forms.

The original BASIC language had very little structure but had a strict set of coding rules.

Although BASIC began as a language for beginners, today's versions of BASIC provide a large assortment of advanced programming elements.

The following are some of the names that BASIC has had as it evolved through the years:

BASICA (for BASIC Advanced)

GWBASIC (for Gee Whiz BASIC)

Power BASIC

Turbo BASIC

QuickBASIC (a compiled version)

QBASIC (which was included with MS-DOS, beginning with version 5.0)

Visual Basic (a Windows programming environment)

QBASIC was the language of choice for most beginning programmers in the 1980s and 1990s.

Windows-based Programs

In Windows-based programming, programmers use a graphical programming environment that provides a collection of graphical controls, such as menus and buttons, to build the interfaces of our popular window-based programs.

Windows-based programs are event-driven, a concept we will look at in great depth in upcoming lessons.

Visual Basic is currently the most impressive language for building Windows-based programs.

Visual Basic uses a powerful but relatively simple programming language.

Visual Basic is not, in the true sense of the word, an object-oriented programming language.

Object-Oriented Languages

Structured programming was the method encouraged by Pascal and C to allow programmers to write increasingly larger and more complex programs but even these languages reached their limit as projects became increasingly more complex.

Object-oriented programming, or OOP, was the next advance in programming.

Object-oriented programming takes the best ideas of structured programming and combines these ideas with several new concepts resulting in a different way of organizing programs.

In its most general sense, in an object-oriented language, you define both the data and the routines that are permitted to act on that data.

To support the principles of object-oriented programming, all OOP languages have three traits in common: Encapsulation, Polymorphism and Inheritance.

Popular object-oriented languages that you may have heard of are SmallTalk, C++ and Java.

Influences and Trends

The way in which programming languages are evolving and the trends in the way applications

are written have been influenced by several factors, a few of which are discussed in this lesson.

Some significant influences include:

Improvements in computer hardware and its capabilities (faster, cheaper and have more available memory)

Increased use of personal computers, as computers have invaded every area of human life ranging from business and industry to recreational and social

The Internet and the World Wide Web ( better browser technology)

Emergence of e-commerce as a new way to conduct business

Standardization efforts, which are needed to enable portability of languages across different operating platforms and programming environments

Some significant trends in application development include:

Rapid Application Development (RAD)

Rapid Application Development arose in the 1990s from a company's/client's need to have new

applications delivered as quickly as possible. RAD is a programming system that enables

programmers to quickly build working programs. The focus is on the delivery of a final, scalable

product in a short period of time. RAD projects tend to be relatively small-scale and of short

duration, with two to six months being the normal project length.

Integrated Development Environments (IDEs)

Integrated Development Environments are popular tools programmers use to write code,

compile it for execution and debug it, all within one environment. Examples of IDEs include:

Jbuilder, IBM VisualAge and Visual C++.

.NET Technologies

Microsoft's newest technology is DotNet or .NET. This technology involves clients, servers and

developer's tools.

Microsoft .NET technologies consist of:

The .NET framework

Developer's tools such as Visual C++, Visual J# and Visual Basic

Microsoft servers

Client software

From a programming perspective, the .NET framework allows the programmer to use

the programming language of their choice or to combine more than one language within

a single application. The .Net framework currently supports over twenty programming

languages.

.NET Supported Programming Languages

APL Fortran Pascal

C++ Haskell Perl

C# Java Python

COBOL Microsoft Jscript RPG

Component Pascal Mercury Scheme

Curriculum Mondrian SmallTalk

Eiffel Oberon Standard ML

Forth Oz Microsoft Visual Basic

Which Language is Best?

Whether considering one of the older

languages or one that is more fashionable

today, how do we decide which language is

best?

The best programming language depends on

the task you need to perform. On a personal

level, the best language is the language that

you know best.

Other factors that might influence which language you select are:

The type of application you need

How commonly used the language is

From a business or industry perspective, the language that is used to write a particular

application is determined by many factors. Cost would certainly be one of those factors.

How Many Languages Should a Programmer Know?

It is also hard to determine how many programming languages a good programmer should

know. Some highly paid, highly skilled programmers only know a single language. However,

most programmers know several languages. You will probably find that you prefer one language

to the others and will most likely become an expert in only one or two.

Let's Review!

Module Assignment

Once you are ready, you may proceed to the assignment for Module 2. Assignment 2 can be

found on the webpage.

There is also a quiz on this unit.

Module 3 Objectives

By the end of this module, you should be able to:

Explain the importance of detailed instructions when writing computer programs.

List and describe the steps in the program development cycle.

Describe the three stages a computer program goes through when being tested.

Explain the difference between syntax, logic and runtime errors.

Describe the principle of top-down design.

Programs are Directions

We have all been somewhere where we have had to ask for

directions—perhaps in a strange city with only a map and some

verbal directions. Even with these to guide us, one wrong turn

meant we did not get to where we wanted to go.

Likewise, a computer has somewhere it "wants to go." The

programmer must provide the computer with all the directions it will

need to arrive at the correct output, its desired "destination."

When a computer receives directions, it carries out the directions exactly as they are given. The

computer cannot second-guess or ask for explanations. If the programmer tells the computer to

do something incorrectly, it will do it incorrectly, blindly following the programmer's directions.

Remember, by definition, a program is a list of detailed instructions that the computer carries

out. The word detailed is critical. The programmer must write simple and detailed steps, making

sure the steps are in the proper order.

When writing programming steps, you must assume the computer knows absolutely

nothing.

Writing Detailed Instructions

The following example will give you an idea of what is

involved in programming.

Example:

Pretend a caveman is transported by a time machine to

your doorstep. The caveman is anxious to try all the

new things he sees. He buys a new VCR so he can

watch his first movie. Unlike you, everything about

VCRs is new to him.

You are a busy programmer who gives him the

following instructions:

1. Turn on the VCR.

2. Insert the tape.

3. Push Play.

Our poor buddy would not get far because your instructions assume a lot of prior knowledge.

You must remember he knows absolutely nothing about VCRs. He is relying on you to give him

instructions that he can understand. Computers also rely on programmers to give them detailed

instructions that assume no prior knowledge.

These are better instructions but they still lack most of the required details and assume a lot of prior knowledge:

1. The VCR is in the box that came with these instructions.

2. You will use this VCR to watch the movie.

3. Remove the VCR from the box.

4. Place the VCR on a table close to the television.

5. Connect the VCR cable to the connection on the back of the television.

6. Plug the VCR in to a power supply on the wall.

7. Press the Power button on the TV remote control.

8. Press the Power button on the front of the VCR.

9. Insert the tape into the opening on the front of the VCR.

10. Press the Play button on the VCR.

By now, you should be starting to get the idea. The list of ten items in the pop-up window of the

previous screen is much more detailed than the first list. Despite the added detail, however, this

list still assumes a lot of prior knowledge. This list of instructions contains ten items, and it still

has not accurately described how to set up and start the VCR. Of course, we did forget to

remind him to turn it off at the end!

If you think this is an extreme example, think about the instructions you would have to provide to

tell a non-thinking computer to run a program to pay your employees. You cannot just say:

1. Get the payroll data.

2. Calculate the amount.

3. Print the cheques.

To the computer, these instructions are missing thousands of the detailed steps we already

know.

It is the details of the program's instructions that are the key to programming. Writing programs

can be both tedious and frustrating. It is not the programming that is difficult. Breaking down the

problems into the many detailed steps that a computer can understand is the difficult part.

Tools that Help the Programmer

There are many design tools that exist to help the programmer take large problems and break

them down into detailed instructions that can then be translated into a programming language.

The upcoming lessons will explain many of the methods programmers use to get to the detailed

instructions that make up a computer program.

Once we begin programming in Visual Basic, you will find that programming is simple as long as

you approach it systematically, using the techniques that you will learn in this module.

The Need for Structure and Design

When a contractor begins to build a house, the contractor does not just pick up a hammer and

start nailing boards together. First, an architect must design the new house and then the builder

can begin.

Using a similar analogy, a systems analyst must design a computer program before the

programmer can write the code.

Let's look at our house again and examine the steps that would probably take place before the

house is actually built:

1. The buyer needs to meet with an architect to describe what they want in their house and what they want the house to look like.

2. The architect helps the buyer by explaining what is possible and what is not.

3. The architect finishes the house plans.

4. The contractor finds out what the buyer wants.

5. The contractor decides what resources and materials are needed to build the house. The design must be completed, the permits filed, the money to purchase materials must be in place, the materials must be purchased and the labourers must be hired. Once all of this is in place, the actual building can begin. The more effort the contractor puts into these preliminary preparations, the faster the house can be built.

Trying to build the house before the design and initial preparations are made can result in many

unanticipated problems during the actual construction. For example, the buyer may want to

make changes to the design when it is too late to make them. It is more difficult and more costly

to add a room once the house is built or to change to vinyl siding once the brick house has been

constructed!

Similar steps must also be followed when programmers are given the task of writing large

computer applications. A systems analyst must determine what the customer wants and then

put a team in place to achieve this design. The programmer would be one member of the team

that will produce the product that the customer is looking for.

On a smaller scale, you, as a programmer, should always keep the similarities between writing

a program and building a house in mind when writing your computer programs. You should not

go to the keyboard and start typing instructions into your text editor before first designing the

program, any more than the builder should pick up their hammer before the house plans are

finished. The more design work you do ahead of time, the faster you will finish the final program.

Adding something to a program, or fixing something after it is written, is never as easy as

designing the program correctly the first time.

The Program Development Cycle

Effective programmers learn to develop patience early in their

programming careers. They learn that proper design is absolutely critical

to a successful program. The term systems analysis and design is the

name given to the practice of analyzing a problem and then designing a

program from that analysis.

Many programmers develop their programs by following a sequence of

steps, referred to as the program development cycle. To be a

productive, hands-on programmer, you must understand the need for, and

the importance of, following the steps in the program development cycle.

Analyze—define the problem.

Be sure you understand what the program should do. In other words, what should the program's output be?

Have a clear idea of what input data is given or will be needed and the relationship between the input and the desired output

Design—plan the solution to the problem.

Find a logical sequence of precise steps to solve the problem. This sequence of steps is called an algorithm.

Every detail, including obvious steps, should be included in the algorithm. In upcoming lessons, we will look at two popular methods used for developing the algorithm or the logic plan—flow charts and pseudo-code. These tools help the programmer break a problem into a sequence of small tasks the computer can perform to solve the problem.

Planning also involves using representative data to test the logic of the algorithm by hand to make sure that it is correct

Choose the Programming Language or Interface—select the objects that will be used.

Determine how the input will be obtained and how the output will be displayed.

Write the code—translate the algorithm into the programming language.

Coding is the technical word for writing the program. During this stage, the program is written in the chosen language.

The programmer uses the algorithm along with their knowledge of the programming language to write the code.

Test and Debug—locate and remove any errors in the program.

Testing is the process of finding errors in a program.

Some types of errors will be detected when the program is executed. Many errors, due to typing mistakes, flaws in the algorithm (called logic errors) or incorrect use of the programming language rules (called syntax errors), can only be uncovered and corrected by careful testing.

Once the errors are detected, the program must be debugged. Debugging is the process of correcting errors found during the testing process.

Document—organize all the material that describes the program.

Documentation is intended to allow another person, or the programmer at a later date, to understand the program.

Internal documentation consists of statements, called comments or remarks (within the program itself), that are not executed but point out the purpose of various parts of the code.

Documentation might also include a detailed description of what the program does and how to use the program. For commercial programs, the documentation might include instruction manuals and help files.

The flowchart, pseudo-code and program algorithm that were used to construct the program are often included with the documentation.

Although documentation is listed as the last step in the program development cycle, it occurs throughout the program development cycle.

Successful and efficient programmers always follow these steps when writing programs,

regardless of how complex or how simple the program might be.

Testing Your Program

Once you have finished writing your program, you are still not completely finished your task.

You must now look at debugging the program.

You must get as many bugs out of the program as possible. You do not want the user to

encounter all kinds of mistakes. Therefore, the program must be thoroughly tested. During the

testing period, the programmer may have to make several changes to the program. A

programmer rarely writes a program correctly the first time.

Desk Checking

Desk checking is the process of checking the program using as many different scenarios of data as possible to try to find weak spots and errors in the code.

Programmers should try extreme values and type bad or incorrect input. In other words, they try their best to make the program fail!

Every available option, using different combinations of input, should be well tested to see what happens.

Beta Testing

When desk checking has been completed and the programmer is as confident as can be about its correctness and accuracy, beta testing can begin. A group of users should be set up to try the program. This is known as beta testing.

The more beta testers you find to test the program, the better the chance errors will be found.

An advantage of beta testers is that they will often try things the programmer did not think of while testing the program.

More and more software developers are conducting beta testing on a very large scale, openly inviting the public to help beta test products. Many beta versions are available for download over the Internet.

Parallel Testing (when possible)

A user should never abandon an old system and switch to a new program right away without performing a period of parallel testing.

Parallel testing provides an opportunity to use the new program while at the same time continuing to use the old program. The results of the new program can then be compared against those of the old system to see that they match.

Thorough testing does not ensure a perfect program. Some errors might appear only after the

program is used for a while. The more testing you do, the less likely it is that errors will creep up

on you later.

Place the Steps in the Correct Order!

You have learned that proper design is critical to a successfully developed program. In order to

have a successful design, you must correctly follow a set of steps. Match the steps in the

diagram below.

The Need for Accuracy

By now, you should be well aware that the computer is a machine and it cannot deal with ambiguous statements, that is, statements with double meanings. One of the most frustrating things for programmers, especially beginning programmers, is the collection of errors that show up in their code. Although we, as programmers, always strive to write error-free code, this is not as easy as it may seem and bugs can creep in!

There are three categories of computer bugs:

Syntax errors

Logic errors

Runtime errors

Activity

Read the sentence on the computer screen to see if

you can identify any errors. Then check the answer

below to see if you are right!

Answer

The first error is, with any luck, obvious. The word errrors is misspelled. You may have found

the second error a bit more difficult to find. The second problem with the statement is that the

entire premise of the statement is incorrect! There is only one error in the statement and that

error is the misspelled word. Therefore, the logic of the statement itself is an error.

Syntax Errors

A syntax error is much easier to find than a logic error, as

demonstrated in the activity in the previous lesson.

Syntax errors often appear as misspelled programming

language commands and grammatical problems with the way

you use the programming language.

Compilers locate your program's syntax errors when you try to

compile your program. This is another reason why syntax errors

are easier to spot. The computer tells you where they are. When the

computer runs into a syntax error, it stops and refuses to analyze the program

any further until you correct the syntax error.

Logic Errors

Logic errors occur when your program is syntactically or grammatically

correct but you told the program to do something that is not really what

should be done.

For example, suppose you are writing a program to print marks for your

school's report cards. Because of a logic error, the computer prints all the

report cards showing final marks of zero (0) for all students in all courses!

The computer did its job. It carried out the program instructions, which

did not contain any syntax errors because the computer ran the program without stopping.

However, the logic errors kept it from working properly. With errors such as this, the students

would soon complain!

Again, it is important to emphasize that extensive program testing is very important. You must

get all the errors out of your programs before the user finally uses it. The larger the program, the

more difficult it is to do this. Getting rid of program bugs is part of the daily job of a programmer.

Runtime Errors

The third type of error is called a runtime error.

Runtime errors are actually almost always caused by

logic mistakes. The programmer fails to predict a

potential problem and therefore fails to handle it when

it occurs.

The following is an example of a runtime error:

A program calculates the number of days in a year but does not allow for leap years.

The more you program, the more you will learn to

head off potential runtime errors that might occur.

Debugging

As we have learned, programs are easy to write. However, writing correct programs is a

different story. Locating program bugs can sometimes be difficult. The compiler will locate

syntax errors for you but logic errors, or bugs, often take extra time to locate. You will find that

your debugging skills will improve as your programming skills improve.

You can make debugging easier by learning to write programs in a way that makes them easy

to maintain and update. This means:

Thinking a problem through completely before beginning to write the code

Writing clear code without a lot of unnecessary steps

Being neat and using a consistent style

Commenting and documenting your code, especially sections of code that could be confusing

You can also take heart in knowing that most major companies that develop computer

languages supply debugging tools to make the programmer's life easier!

Top-down Design

Before beginning to write a computer program, you should have a clear idea of:

What output the program should produce

What input (data) will be needed to produce that output

Using a top-down design model will help you identify all the details that will be needed to write

your program. Top-down design is the process of taking a problem and breaking it down into

more and more specific details.

Programmers have a tendency to design from the bottom-up. Designing from the bottom up

means you must remember every detail from the very beginning.

If you follow a strict top-down design process, the details will be produced for you as you move

from the general to the specific.

Top-down Design - Examples

The following is the four-step process for top-down design:

1. Determine the overall goal.

2. Break that goal into a maximum of two or three more detailed parts.

3. Repeat step two for each part.

4. Repeat steps two and three until you cannot break the problem down any further.

Top-down design is not just used in computer programming. It can be applied to anything that

requires detailed planning.

We will look at two examples that are frequently used to illustrate how top-down design works:

1. Planning a wedding

2. Writing a payroll program for a company

Top-down Design: Example 1

Planning a Wedding

Perhaps the most detailed event that a person can plan is a wedding. Most people plan a

wedding from the bottom to the top. They immediately start by thinking about the dresses, the

colours, the flowers and the napkins to use at the reception! The biggest problem with trying to

include all these details from the beginning is that some of the details always get forgotten until

it is too late.

The preferred method for planning is to plan from the top down. This is how top-down design

would work in planning a wedding:

1. Determine the overall goal:

What is the overall goal of a wedding? Having the wedding is about as obvious as we

can get!

2. Break the overall goal into two or three parts:

Once the overall goal is established, we can begin breaking down that goal into two or

three details. We might think of the guest list, the colours we will use, how we will pay for

everything….ahh, too many details! Remember, the idea of top-down design is to put off

the details for as long as possible. When we break the current problem into more than

two to three parts at this stage of the design, we are rushing the top-down design.

A better breakdown might be:

3. Repeat step two, breaking each part into more and more specific detail: The next step is to take each of the components established in step two and break them down into even smaller parts. For example, the ceremony can be broken down into the people and the location. The reception can be broken down into the food, the people and the location. Add these new components to the design.

Continue breaking each part down into a smaller, more detailed part—the ceremony's

people include the guests, the wedding party and the workers (such as the minister,

organist, etc.) For example:

The top-down design process produces a triangular shape as shown. There are still a lot

of details that must be added to our wedding design but that is exactly the point. We put

the details off for as long as possible. The details will emerge on their own as we break

each part or task into smaller and smaller parts.

Eventually, we will have several pages of details that cannot be broken down any

further. For example, we will likely end up with the details of the reception food, including

the choice of napkins. If we had started out at the beginning making a list of things like

napkins, we might forget some of the details and may find ourselves without a church on

our wedding day!

Top-down Design: Example 2

A Payroll Program

What if you were asked to write a payroll program for a company? What would such a program

require?

You might begin your list of the program details with the following:

Print the payroll cheques.

Calculate the income tax.

Calculate the overtime.

What is wrong with the above list? If you said the details listed above were too specific, too

soon, you would be correct.

Start at the top and break it down into smaller and smaller components as shown below:

There is a long way to go before we finish with the payroll design. We must continue to break

each component down until all the details are finally shown.

Once you have worked out all the details of the design, you must then move the details into

some type of ordered logic, or algorithm, that your program can follow to produce the details.

Let's Review!

Module Assignment

There is no assignment for this module.

Module Test

You must write the quiz for Module 3.

Module 4 Objectives

By the end of this module, you should be able to:

Explain the concept of structured programming.

Name and explain three structured programming constructs.

Use flowcharts to solve problems.

State the advantages and disadvantages of using flowcharts and pseudo-code.

Explain why commenting your code is important.

Explain why following a language's style conventions is important.

Introduction to Structured Programming

The most important thing you will ever learn about programming is learning to use structured

programming techniques. Using these techniques will help you work through the logic of even

the most complicated programming tasks. If you faithfully use these techniques, you will always

write clean, maintainable code. Structured programming techniques can be used no matter what

programming language or platform you are working with.

The idea of structured programming is to write programs that are organized in an orderly fashion

and that do not jump around. A program that is clearly written and well organized can be

changed and updated more easily in the future.

A construct is a building block of a language and one of a language's fundamental operations.

Structured programming includes the following three constructs:

Sequence

Selection (also called decision)

Repetition (also called looping or iteration)

As long as the programming language you are using supports these three constructs (and most

languages do,) you can write structured programs.

Sequence

Sequence means following two or more instructions in order, one after the other. A program that uses the sequence construct moves in order from one instruction to the next, from the first statement to the last statement within the sequence. Sequenced instructions are the easiest of the three structured programming constructs.

The following is an example of a sequence of

instructions:

1. Ask for the number of hours worked.

2. Multiply the hours worked by the rate of pay.

3. Subtract the taxes to compute the net pay.

4. Print the paycheque.

Many programs that you write require a "decision" between two or more options. Repeating

code statements multiple times is also common in programs. Therefore, not all of the programs

you write can consist solely of the type of straight-line, sequential logic that was illustrated in the

above example.

Selection

Selection means that a decision must be made that will break away from the straight-line,

sequential program flow. The decision construct ensures that the deviation from the straight-line

flow is controlled.

Many programs use the selection construct. Any time a program must make a decision, it must

break off in either one of two directions. By allowing the program to move in one or the other

direction, you keep the code orderly and structured.

The following example shows instructions that involve a decision:

Only one of two outcomes is possible in response to the question, "Did employee sell over $10

000?" If new data are provided, the program might repeat the decision and choose a different

route the second time.

Notice that one path of the decision will not

be executed. For example, if the red line is

followed, it leads to the next statement in

the code line. Everything along the blue

line is skipped. If the blue decision is

followed to the next statement in the

program, everything along the red line is

skipped.

If the program can go in more than two

directions, it must be broken up into multiple two-direction decision statements.

Repetition

Unlike us, a computer can repeat directions millions of times and never get bored or stop! This

makes the repetition construct very important. Repetition is more commonly called looping, or

iterating, lines of program code.

In a program that uses the repetition construct, the computer repeats sections of program code

over and over. A program is very powerful when it can repeat a series of sequential statements

and decisions over and over.

The following example shows the looping construct:

In this example, customer after customer will be processed until, eventually, there will not be

any more customers. The loop will stop and the program will continue with the next instruction

after the loop.

Structured Programming Tools

There are tools that you can use to help you work through the logic to write the algorithms that

make good, sound, structured programs. We will learn about two of the most common logic

development tools used by programmers:

Flowcharts:Provide a picture representation of the steps required to carry out a task.

Pseudo-code: Uses English-like phrases to show the steps required to carry out a task.

Flowcharts

You have probably heard the expression "a picture is worth a thousand words." A flowchart

provides a pictorial representation of a program's logic. If your flowchart is correctly drawn,

writing the actual program is easy. Once the final code for the program is written, the flowchart

can then serve as part of the program documentation.

A flowchart is made up of special symbols connected by arrows. Within each symbol is a

statement indicating what happens at that step. The shape of the symbol itself also indicates the

type of statement that will occur at that point in the program.

For example, the parallelogram indicates that input or output will occur at that step in the

logic.

Arrows connect the flowchart symbols. These arrows are known as flow lines. Each arrow

shows the order in which the steps take place.

Flowcharts should flow from the top of the page to the bottom of the page.

Flowchart Symbols

Flowcharts are made up of standard symbols. With these symbols, you can write any flowchart

that you will ever need. In this lesson, we will look at the most common flowcharting symbols.

Symbol Meaning Description

Process This contains a description of what is being done. Use this symbol to indicate how the data will be processed. For example, use an expression.

Input/Output Use this to indicate input or output. The slanted shape of the I/O symbol gives you a clue to its meaning as the slash in the I/O slants the same way as the sides of the symbol.

Decision Use this when the program must make a decision.

Flow connector Use this when two paths in the flowchart merge. For example, after a decision, the two branches merge and the flow continues.

Off page Use this symbol when the flowchart continues to another page. Put the next page's number inside the symbol.

Flow direction These arrows connect every symbol in the flowchart and indicate the direction of the program flow.

Terminal A terminal symbol with the word Begin or Start written in it begins every flowchart. A terminal symbol with the word End or Finish written in it ends every flowchart.

The Rules of Flowcharting

Every programmer draws flowcharts differently. However, there are some specific rules that

should always be followed. If you follow these rules faithfully, the flowcharts you write will

always be readable by others.

Rule #1: Use standard flowchart symbols. If you stick to the standard symbols, others can understand your flowchart's meaning, and you will be able to understand theirs.

Rule #2: The flowchart's logic should generally flow from the top of the page to the bottom and from the left to the right.

Some flowcharts will have no need to flow to the right because they involve sequential logic but most flowcharts have some kind of flow going left or right.

Sometimes flowcharts, because of repetition in logic, might have areas that go back up and to the left to repeat sections of logic, but eventually, the logic will continue in the preferred top-bottom, left-right directions.

Rule #3: The decision symbol is the only symbol that can have more than one exit point and it always has two exits.

Most flowcharting symbols have one entry point and one exit point. The flow direction arrow indicates the entry point and exit point(s).

The decision symbol always has two exit points because, at that place in the logic, one of two things takes place. The next step in the logic is determined by the result of that decision.

Rule #4: A decision symbol should always ask a yes or no question.

A flowchart's decision should always have two, and only two, outcomes.

Most flowchart symbols have words in them that describe what is taking place at that point in the flowchart.

Clearly label the exits of each decision symbol. The exits are the result of a yes or no question. Label the exits Yes and No, so you know what the exits indicate.

There are times when your program must handle more than two possibilities. Multiple decision symbols will take care of all the possibilities. Ask enough Yes or No questions and you can determine anything!

Rule #5: Instructions inside the symbols should be clear, English descriptions, not programming language statements.

Develop your flowchart before you write your program. Do not include any programming statements inside the symbols.

The flowchart is your own development of the program logic. You will eventually convert the flowchart into programming language instructions. You should not attempt to do this until you are sure that the flowchart performs the logic that you need.

Flowchart Examples

You have now been introduced to basic principles of flowcharting. Now it is time to see the rules

put into practice!

Flowchart Example 1

Postage Stamp Problem

Problem: Decide how much postage to put on the envelope. One rule of thumb is to use one

stamp for every five sheets of paper in the envelope.

Examine the flowchart for the postage stamp problem.

Activity:

1. Label the middle four symbols as input, output or process.

2. Identify the symbols:

a. Flow line

b. Input/Output

c. Processing

d. Terminator

3. Identify the logic as sequence, decision or iteration.

Flowchart Example 2

Streets of Cyberville

There is a simple way to tell the direction of a one-way street in Cyberville. Even-numbered

streets run eastbound.

Problem: Given the street number of a one-way street in Cyberville, decide the direction of the

street, either eastbound or westbound.

Activity:

1. Match these terms to the symbols on the flowchart:

a. Connector

b. Input/Output

c. Terminator

d. Decision

2. Identify the logic as sequence, decision or iteration.

Flowchart Example 3

Class Average

Problem: The average grade equals the sum of all grades divided by the number of

students. Calculate and report the average grade for a computer science test.

Activity:

1. Match the following to the correct step in the flowchart:

a. Add 1 to counter.

b. Find the average.

c. Counter and sum start at zero.

d. Display the answer.

e. Read next grade.

f. Accumulate sum of grades.

2. Identify the logic as sequence, decision or iteration.

Identify the Flowchart Symbols

You have learned that proper flowcharting is an important step in the programming process.

Flowcharts are made up of a standard set of symbols. Do you remember what these symbols

are?

Advantages and Disadvantages of Flowcharts

The main advantage to using a flowchart to work through a problem and arrive at a solution is

that it provides a picture representation of the steps to follow. This makes the logic easier to

follow. We can clearly see every step and how each step is connected to the next.

The major disadvantages of flowcharts are that they are time-consuming to write and, when a

program is very large, the flowcharts may continue for many pages, making them hard to follow.

Note: Pseudo code, which we will look at briefly in upcoming lessons, is a more popular logic

development tool for today's programmers. Flowcharts are, however, still used for illustrating

isolated parts of a program's logic for documentation purposes.

Pseudo-Code

Pseudo-code is an abbreviated version of actual computer code, hence the name pseudo-

code. The symbols that are used in a flowchart are replaced by English-like phrases to outline

the process and logic of the problem.

There are many styles of pseudo-code. Some programmers use an outline form. Others use a

form that looks almost like a programming language. Usually, pseudo-code does not have any

programming language in it but it is not the free-flowing English that we are used to using.

Pseudo-code is a rigid set of words that allow you to show logic. The goal is to eliminate any

words with conflicting meanings. As with flowcharts, you can use pseudo-code for anything, not

just computer programs. Many instruction manuals use a form of pseudo-code to show the

steps that are needed to assemble parts.

Pseudo-code Example 1

Postage Stamp Problem

Pseudo-code:

Determine the proper number of

stamps for a letter.

Read the number of sheets.

Set the number of stamps to:

sheets/5

Round the number of stamps up to

the next whole number.

Display the number of stamps.

Pseudo-code Example 2

Streets of Cyberville

Pseudo-code:

Get street number.

IF street is even,

then

display east-

bound

ELSE

display west-

bound.

End IF.

Pseudo-code Example 3

Class Average

Pseudo-code:

Initialize counter

and sum to zero.

DO WHILE there

are more data

Get the next

grade

Add the

grade to the sum

Increment

the counter

LOOP

Compute Average

= Sum/Counter

Display Average

Advantages and Disadvantages of Pseudo-Code

Pseudo-code looks more like computer code than a flowchart does. Pseudo-code allows the

programmer to focus on the steps required to solve a problem rather than on how to use the

programming language—for example, which constructs to use.

The programmer can describe the steps to solve the problem in programming language-like

form without being restricted by the syntax rules of the language. When the pseudo-code is

completed, it can then be easily translated into programming language.

Commenting Your Code

Examine the following code written in C++ (or in C):

In this example, the line in bold, green text is called a

comment or remark. All languages support comments,

although not all languages use the // characters to

indicate that the statement is a comment.

You will find many comments in programs and you will

put many comments in the programs that you will write.

Comments are not for the computer or the compiler.

Comments are for people!

In the code example shown here, the compiler ignores

all text to the right of the //. The computer knows those

comments are for you and not for it.

Why Comment?

Comments help make the code more readable for programmers. In programming, commenting

your code is one of the most important good programming habits that you can develop.

Two reasons for including comments in your code are:

1. To identify the programmers

If you develop programs with other programmers or write programs for a company, you

should put your name and contact information in the comments at the beginning of your

programs. Later, if someone has a question about the program or wants you to change

the program, they will know who to ask and where to find you.

2. To explain a section of tricky code

Changes in code will be easier to make because reading the comment is much easier

than trying to figure out what the code is trying to do.

Programming Style

When you write programs, always keep future maintenance of the code in mind. Examine the following code written in C.

The program shown here is a valid, legal C program but

what a mess! It is nearly impossible to read because it

is all run together.

Most programming languages are free form. This

means you can indent lines and add as many spaces,

called white spaces, and blank lines as you like. This

makes a program more readable, separating one

section of code from another, making it easier to

understand.

Programming Style (Continued)

By adding white space and extra lines, the program shown in the previous screen automatically becomes easier to read, even for non-C programmers.

Look at the code again, this time with white spaces

and extra lines added to make it more readable. It also

makes it easier to spot syntax errors such as missing

braces and brackets.

There is a certain protocol for inserting lines and white

spaces. Each language has its own protocol or style.

Not following the style rules and conventions does

not prevent your program from compiling and running.

However, the best programmers get into the habit of

following the style conventions of their language. They

realize the importance of being neat and using a consistent style throughout their programs.

Let's Review!

Module Assignment

Once you are ready, you may proceed to the assignment for Module 4. Assignment 3 can be

found on the webpage.

Module Test

You must also write the quiz for Module 4.