CMP202 Lecture 2 - Structured Programming Concepts
CMP202 Lecture 2 - Structured Programming Concepts
II
LECTURE SERIES
OVERVIEW OF THE COURSE OUTLINE
Principles of Good programming
Structured programming concepts
Errors and Debugging
Testing
Text Files and IO
Structured Programming Concepts
• The concept of structured programming started in the late 1960’s
with an article by Edsger Dijkstra.
• He proposed a “go to less” method of planning programming logic
that eliminated the need for the branching category of control
structures.
• The topic was debated for about 20 years.
• But ultimately – “By the end of the 20th century nearly all computer
scientists were convinced that it is useful to learn and apply the
concepts of structured programming.”
What is Structured Programming?
• Structured programming is a programming paradigm aimed at
improving the clarity, quality, and development time of a computer
program
• By making extensive use of the structured control flow constructs of
• The other control structures are the case, do-until, do-while, and for
are not needed. However, they are sometimes convenient and are
usually regarded as part of structured programming. In assembly
language, they add little convenience.
Steps in a Programming Project
• In CMP201, the importance of a clear, structured programming style
has been emphasized. Because of the importance of these principles,
we will dive much into this concepts as it is worth reviewing them
here before we continue with the main part of CMP202.
• Any programming project, no matter how simple, should be divided
into several main sections:
1. Make sure you understand the problem you are trying to solve. This
may seem obvious, but many later problems in coding can be traced
back to your lack of a complete understanding of just what it is the
program is supposed to do
Steps in a Programming Project
• 2. Once you have a clear picture in your mind of the problem, you should
write out the specifications that the program is to satisfy.
• As a simple example, suppose you wish to write a program that sorts a list
of numbers into ascending order. Even for such a simple program, you
need to consider the specifications before you put finger to keyboard.
• For example, how are the numbers to be input into the program?
• Will they be typed in from the keyboard or read from a file?
• Will the quantity of numbers be known in advance, or should this quantity be
requested from the user before the numbers are read, or should the program
count the numbers as they are read in?
• Where is the sorted list to be output (on screen or in a file)?
• If files are used for input and/or output, are the filenames to be constant,
or should the program request the filenames from the user?
• Should the program be able to sort integers or real numbers as well?
Steps in a Programming Project
• You should have made up your mind on all these points before you
even sit down in front of the computer.
• Failing to think things through at this stage can mean a lot of
chopping and changing in the program later, which leads to jumbled
code that is full of errors, and difficult to debug, as well as a lot of
wasted time.