Download presentation
Presentation is loading. Please wait.
Published byLeona Oliver Modified over 6 years ago
1
Coding Constructs considered Violations of Structured Programming
Black Magic Coding Constructs considered Violations of Structured Programming
2
Background Programming Languages before the 1980’s allowed program flow to “bounce around” anywhere the programmer wanted.
3
RESULT: “Spaghetti Code”
Background RESULT: “Spaghetti Code”
4
Background “Spaghetti Code” very difficult to Debug
almost impossible to Maintain not Reusable
5
Solution: Structured Programming
Background Solution: Structured Programming Organize and encapsulate code into clear, maintainable segments, each with one Entry and Exit point.
6
Structured Programming: Example 1
Background Structured Programming: Example 1
7
Structured Programming: Example 2
Background Structured Programming: Example 2
8
Many battles were fought in the 1960’s-80’s
Background Many battles were fought in the 1960’s-80’s
9
Background Structured Programming Won.
A major result: the standard use of the Pascal language to teach new programmers. Pascal enforces concepts of Structured Prog.
10
C++ There are statements in C (and so C++) that violate
Structured Programming to some degree
11
return from anywhere in a function:
Actually a major violation of SS, but commonly used by C++ programmers.
12
return from anywhere in a function:
int main() { ... if (something) return 1; return 0; }
13
continue jump to the end of a loop somewhat common in C++
14
while (something) { //loop control
continue while (something) { //loop control ... if (something) // jump to beginning of loop continue; }
15
a little more common in C++
break exit a control block (loop, switch, if, etc.) a little more common in C++
16
C++ break; while (something) { //loop control ... if (something)
break; // exit the loop } // jump to here
17
C++ “The word that SHALL NOT be uttered”
banned by most C++ programmers unrestricted use in C major restrictions in C++
18
The word that SHALL NOT be uttered: GOTO
C++ The word that SHALL NOT be uttered: GOTO
19
CS 215 The following should NOT be used in any CS 215 programs (labs, projects, tests) continue break (except in a switch) goto
20
The following is allowed: return in the middle of a function
CS 215 The following is allowed: return in the middle of a function
21
After 215 Once you’ve finished CS 215 and “Earned Your Stripes”
you may be allowed to use these statements, but... Best to ask the Instructor
22
Test Nothing from this set of slides will be on the tests...
except NOT using the “banned” statements.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.