Coding Constructs considered Violations of Structured Programming

Slides:



Advertisements
Similar presentations
Chapter 13 Control Structures in C. BYU CS/ECEn 124Variables and Operators2 Topics to Cover… Control Structures if Statement if-else Statement switch.
Advertisements

Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
CSCI 330: Programming Language Concepts Instructor: Pranava K. Jha Control Flow-II: Execution Order.
(8.1) COEN Control Structures  Control structure general issues  Compound statements  Selectors (conditional structures) – single – two-way –
1 Control Statements Lecture 6 from Chapter 5. 2 Three principles of OOP- Encapsulation Encapsulation allows changes to code to be more easily made. It.
Chapter 8 Statement-Level Control Structure. Introduction Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements.
ISBN Chapter 8 Statement-Level Control Structures.
ISBN Chapter 8 Statement-Level Control Structures.
ISBN Chapter 8 Statement-Level Control Structures.
1 MATERI PENDUKUNG JUMP Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Statement-Level Control Structures Sections 1-4
ISBN Chapter 8 Statement-Level Control Structures.
ISBN Lecture 08 Statement-Level Control Structures.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
COMP4730/2002/lec8/H.Melikian Statement-Level Control Structures Introduction Compound Statements Selection Statements Iterative Statements Unconditional.
Statement Level Flow of Control Selection Structures Copyright © by Curt Hill.
1 Statement-Level Control Structures Levels of flow control Control Statements 1. Sequence 2. Selection 3. Iteration Unconditional branching Guarded commands.
CONTROL FLOW IN C++ Satish Mishra PGT CS KV Trimulgherry.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
GOTO CONSIDERED HARMFUL Tarana Yar. The publishing of the paper entitled “Go To Statement Considered Harmful”, written by Edsger W. Dijkstra in 1968,
The C# language fundamentals ( II ) Po Feng, Tsai.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
ISBN Chapter 8 Statement-Level Control Structures.
1 CS Programming Languages Class 11 September 26, 2000.
Procedural programming in Java Methods, parameters and return values.
8-1 Statement-Level Control Structures Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
April 16, ICE 1341 – Programming Languages (Lecture #14) In-Young Ko Programming Languages (ICE 1341) Lecture #14 Programming Languages (ICE 1341)
Statement Level Flow of Control Iteration Structures Copyright © by Curt Hill.
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 7 Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements.
CS 161 Introduction to Programming and Problem Solving Chapter 18 Control Flow Through C++ Program Herbert G. Mayer, PSU Status 10/8/2014 Initial content.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Chapter 8 © 2002 by Addison Wesley Longman, Inc Introduction - Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 8 Java Fundamentals Control Structures Fri.
W E E K F I V E Statement-Level Control Structures.
W E E K F I V E Control Flow. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 8 Topics Introduction Selection Statements Iterative Statements.
Week 4 - Monday.  What did we talk about last time?  Precedence  Selection statements  Loops  Lab 3.
CSE 220 – C Programming Loops.
Def: A control structure is a control statement and
Compound Condition Break , Continue Switch Statements in Java
Unit-1 Introduction to Java
8.1 Introduction - Levels of Control Flow: 1. Within expressions
Statement-Level Control Structures
Control Statements Lecture 6 from Chapter 5.
White-Box Testing.
Chapter 8: Control Structures
Week 4 - Monday CS222.
Flow of Control.
Flow of Control.
Switch Statements, Do While, Break, Continue, Goto, Comma Operator
User Defined Functions
Program Flow CSCE 121 J. Michael Moore.
The structured programming theorem
Control statements Simple statements Basic structured statements
Control Structures In Text: Chapter 8.
Break statements.
Flow of Control.
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
Statement-Level Control Structures
Homework Any Questions?.
Program Flow.
ECE 103 Engineering Programming Chapter 20 Change in Flow of Control
Structured Programming
Department of Computer Science
CSC215 Lecture Control Flow.
Controlling Program Flow
Enum.
The structured programming theorem
CSE 3302 Programming Languages
Presentation transcript:

Coding Constructs considered Violations of Structured Programming Black Magic Coding Constructs considered Violations of Structured Programming

Background Programming Languages before the 1980’s allowed program flow to “bounce around” anywhere the programmer wanted.

RESULT: “Spaghetti Code” Background RESULT: “Spaghetti Code”

Background “Spaghetti Code” very difficult to Debug almost impossible to Maintain not Reusable

Solution: Structured Programming Background Solution: Structured Programming Organize and encapsulate code into clear, maintainable segments, each with one Entry and Exit point.

Structured Programming: Example 1 Background Structured Programming: Example 1

Structured Programming: Example 2 Background Structured Programming: Example 2

Many battles were fought in the 1960’s-80’s Background Many battles were fought in the 1960’s-80’s

Background Structured Programming Won. A major result: the standard use of the Pascal language to teach new programmers. Pascal enforces concepts of Structured Prog.

C++ There are statements in C (and so C++) that violate Structured Programming to some degree

return from anywhere in a function: Actually a major violation of SS, but commonly used by C++ programmers.

return from anywhere in a function: int main() { ... if (something) return 1; return 0; }

continue jump to the end of a loop somewhat common in C++

while (something) { //loop control continue while (something) { //loop control ... if (something) // jump to beginning of loop continue; }

a little more common in C++ break exit a control block (loop, switch, if, etc.) a little more common in C++

C++ break; while (something) { //loop control ... if (something) break; // exit the loop } // jump to here

C++ “The word that SHALL NOT be uttered” banned by most C++ programmers unrestricted use in C major restrictions in C++

The word that SHALL NOT be uttered: GOTO C++ The word that SHALL NOT be uttered: GOTO

CS 215 The following should NOT be used in any CS 215 programs (labs, projects, tests) continue break (except in a switch) goto

The following is allowed: return in the middle of a function CS 215 The following is allowed: return in the middle of a function

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

Test Nothing from this set of slides will be on the tests... except NOT using the “banned” statements.