Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
90 views

Structured Programming - Lecture 1

This document outlines a course on structured programming. It discusses how structured programming emerged as a new paradigm in the 1960s to organize code into blocks with single entry and exit points linked by control flow statements. This structure improves readability, debuggability and maintainability over earlier "spaghetti code". The document covers concepts like stepwise refinement, functions, and how the three structures of sequence, selection and iteration allow expressing any computation according to the structured program theorem.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Structured Programming - Lecture 1

This document outlines a course on structured programming. It discusses how structured programming emerged as a new paradigm in the 1960s to organize code into blocks with single entry and exit points linked by control flow statements. This structure improves readability, debuggability and maintainability over earlier "spaghetti code". The document covers concepts like stepwise refinement, functions, and how the three structures of sequence, selection and iteration allow expressing any computation according to the structured program theorem.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

SWE4205 – STRUCTURED

PROGRAMMING
A. A. Datti
COURSE OUTLINE
•Introduction to Structured Programming
•What is functional programming?
•Benefits of functional programming
•Functional vs. Object-oriented programming
•Functions, Closures and scopes
•Understanding your application’s control flow
•Method chaining and Function chaining
•Reasoning about your code
•Learning to think recursively
SWE4205 - STRUCTURED PROGRAMMING 2
INTRODUCTION TO
STRUCTURED Lecture1

PROGRAMMING SWE4205 - STRUCTURED PROGRAMMING 3


IN THE BEGINNING…
•Before IBM released FORTRAN in 1957, almost all programming was done
in assembly language.

•Part of the reason for this is that nobody knew how to design a good high-
level language, nor did they know how to write a compiler to generate
efficient code.

•Early attempts at high-level languages resulted in languages that were not


well structured, difficult to read, and difficult to debug

SWE4205 - STRUCTURED PROGRAMMING 4


A NEW DAWN
•In the 1960s, a new paradigm for designing high-level languages emerged.
This new paradigm emphasized grouping program statements into blocks of
code that execute from beginning to end.

•These basic blocks have only one entry point and one exit point. Control of
which basic blocks are executed, and in what order, is accomplished with
highly structured flow control statements.

•The structured program theorem, also called the Böhm–Jacopini theorem,


provides the theoretical basis of structured programming.
SWE4205 - STRUCTURED PROGRAMMING 5
STRUCTURED PROGRAMMING
ELEMENTS
•It states that “the three basic blocks: sequencing, selection, and iteration are
sufficient to express any computable function”.

•Although most high level languages provide additional flow control


statements for the convenience of the programmer, they are just “syntactical
sugar.”

• Other structured programming concepts include well-formed functions,


procedures & subroutines, abstraction and stepwise refinement

SWE4205 - STRUCTURED PROGRAMMING 6


STEPWISE REFINEMENT
Stepwise refinement refers to the progressive refinement in small steps of a program
specification into a program. Sometimes, it is called top-down design.

For example, consider a function for translating time of day from 24-hour format
into conventional AM-PM format. This can be done by implementing the task as a
sequence of 3 subtasks.

See attached PDF

SWE4205 - STRUCTURED PROGRAMMING 7


WHY STRUCTURED
PROGRAMMING?
•These structured programming languages enabled programmers to
become much more productive.

•Well-written programs that adhere to structured programming


principles are much easier to write, understand, debug, and maintain.

•Most successful high-level languages are designed to enforce, or at


least facilitate, good programming techniques

SWE4205 - STRUCTURED PROGRAMMING 8


“SPAGHETTI CODE”
•This is not generally true for assembly language. The burden of writing well-
structured code lies with the programmer, and not the language.

•The best assembly programmers rely heavily on structured programming concepts.


Failure to do so results in code that contains unnecessary branch instructions and, in
the worst cases, results in something called spaghetti code.

•If a program is spaghetti code, then the flow of control is difficult to follow, much
more likely to have bugs, and is extremely difficult to debug. If the flow of control
is too complex for the programmer to follow, then it cannot be adequately
debugged.
SWE4205 - STRUCTURED PROGRAMMING 9
“SPAGHETTI CODE”

SWE4205 - STRUCTURED PROGRAMMING 10


“SPAGHETTI CODE”

SWE4205 - STRUCTURED PROGRAMMING 11


“GO-TO CONSIDERED
HARMFUL”
oIn simple terms, the failure to properly document the jumps created by the
GOTO statement led to overly complex and tangled code. This confusion had
begun to negatively impact the understandability, maintainability, and
effectiveness of commercial programs.

oThat problem led Edsger Djikstra to speculate that the GOTO statement in
the procedural languages of the time led to poor programming practice. In
essence, the overuse of jumps as a means of altering sequence had led many
commercial programs into a “rat’s nest” of unmaintainable applications and
dead-end processing.
SWE4205 - STRUCTURED PROGRAMMING 12
STRUCTURED PROGRAMMING
AS A SOLUTION
oDjikstra’s idea led to the evolution of the concept that the structured
programming theorem was a solution to the “spaghetti code” problem.

oThe control structures posited by the structured programming theorem


allowed programmers to write and execute subroutines much more
easily and effectively and create block programming constructions.

SWE4205 - STRUCTURED PROGRAMMING 13


STRUCTURED PROGRAMMING
AS A SOLUTION
oThe goal of structured programming was to improve understanding of
the code structure by normalizing the actual programming into standard
subroutines.

oThe contention was that structured programming would both improve


quality and cut down on the cost of development by simplifying
program execution into subroutines that execute within three types of
control structures: sequence, selection, and iteration.

SWE4205 - STRUCTURED PROGRAMMING 14


END
SWE4205 - STRUCTURED PROGRAMMING 15

You might also like