KISS Programming

advertisement
KISS Programming
What’s so great about
computers?



They are fast (so they can accomplish
much in a short time… spell check a
thesis)
They don’t make mistakes (speaking
about the computers themselves and
not the software that runs them)
They do only what they are told to do
What’s not so great about
computers?



They are fast (so they can get into
trouble quickly)
They don’t think or understand
They aren’t capable of independent
thought (you must tell them EXACTLY
what to do)
What’s so great about
humans?




We
We
We
We
can
can
can
can
think and reason
be logical (or illogical)
be emotional (or unemotional)
be creative
What’s not so great about
humans


We make mistakes
We don’t understand how we do what
we do (putting things in writing
demonstrates this)
What’s not so great about
programming?


It seems difficult
We MUST think from the computer’s
POV
What’s so great about
programming?




We get a very quick and very dimwitted entity to be our slave
We can save ourselves (or our
companies) time, money, resources
We can accomplish things we can
otherwise not accomplish.
It’s not difficult, it’s different
What is the “definitive
element” of programming?

Process: A process is a set of
sequential instructions or “operations”
to accomplish a task.
How many kinds of process
operations are there?
There are just three operations necessary
to develop program algorithms:
 Input
 Output
 Calculation
Input
Getting data from an “external location”
associated with an “internal location”
(an area of RAM that can be addressed
or be made easily accessible).


Read x
x = Cells(5,2).Value
Output
Putting data associated with an “internal
location” to an “external location”.


Print y
Cells(3,3).Value = y
Computation
Performing operations (mathematical) on
data stored at “internal locations” and
storing the result at an “internal
location”.


z = x+y
zAnswer = erfc(x)+exp(erfc(y))

So all processes are composed of a
series of input, computation and output
steps.
What is structured programming?

Structured programming is an efficient
way to design programs to control the
flow of processes to accomplish
complicated and sophisticated tasks.
What are the structures in
structured programming?




All programs can be generated from
just three structures.
Sequence – a linear arrangement of
process steps
Decision – a branching arrangement
involving one or more processes
Repetition – a controlled looping of a
process
What is invocation?

Invoking is simply the naming of a
collection of structures. This powerful
concept allows us to hide or expose the
details of complex programs
(processes).
What is a NS Diagram?


Nassi-Shneiderman (NS) diagrams
(developed by Ike Nassi and Ben
Shneiderman) illustrate programming
structures and operations graphically.
An alternative to the overly flexible
traditional flow chart, NS charts enforce
structure and modularity in the
programming process.
What is a NS Diagram?


The first key to building a well-structured system is
to design the system before building it. Can you
imagine hiring an architect who directs a contractor
to build the kitchen and living room of your new
home only to find out there is no wall space left for a
door to the bedroom? Yet novice programmers
attempt to build software systems in this piecemeal
fashion.
One often hears the excuse “I don’t have time to
design my program.” In truth, a program will be up
and running properly faster if it is designed properly
in the first place. If you don’t have time to design,
then you certainly don’t have time not to design.
What is a NS Diagram?
What is required of a good design tool? A
good design tool should:
 Enforce structured design.
 Enforce program modularity.
 Be easy to use.
 Generate documents easily understood
by others.
What is a NS Diagram?


The classical flow chart used for program design has
many shortcomings, the greatest being its extreme
flexibility. Any imaginable structure can be
represented by a flow chart (including bad ones);
hence, desirable structures cannot be enforced.
Furthermore, traditional flowsheet symbols attempt
to show the most detailed level of code (individual
operations). Hence most programmers manage to
write the program first (without proper design) and
then make a diagram to explain the programs “flow”.
This defeats any attempt at modularity.
What is a NS Diagram?

The N/S chart starts with the basic
characterization of modern day languages as
being block-structured languages. In these
languages, procedures are represented as
rectangular blocks. A block has a beginning
and an end. When the procedure is called
(when the process is entered) instruction
execution begins at the top and proceeds to
the bottom of the block. This is called a
“sequential operation” or stepwise execution.
NS Diagram for Sequential
Operations
NS Diagram for Decision
IF Form

The conditional IF structure is shown in the
next slide. At the top of the block is a
conditional test. Depending upon the
outcome of the test, one of two paths are
taken through the block. If the test result is
“T” (true) steps 1a, 2a, 3a, etc. are executed.
If the test result is “F” (false) steps 1b, 2b,
3b, etc. are executed. In either case, control
is passed to the top of the block and falls to
the bottom of the block.
NS Diagram for Decision
IF Form
NS Diagram for Decision
CASE Form

The CASE structure is shown in the next
slide. A case is used when there are
more than two “branches” in the
decision. A variable or expression is
evaluated. Depending on its value, the
proper group of operations are
executed. There is also a possibility of
“no match” in which case one can
provide for a “none” case.
NS Diagram for Decision
CASE Form
NS Diagram for Loop
FOR Form

The FOR structure shown in the next slide
executes the operations repetitively over a
specified range of the control variable (say
“i”). Entering the block from the top causes
the first value of “i” to be chosen, and the
operations are evaluated relative to that
value. Arriving at the bootom, control is
returned to the top of the block where the
next value of “i” is chosen. When all values of
“i” have been exhausted, control passes from
the block.
NS Diagram for Loop
FOR Form
NS Diagram for Loop
WHILE Form
NS Diagram for Loop
UNTIL Form
Download