/
Black Magic Coding Constructs considered Black Magic Coding Constructs considered

Black Magic Coding Constructs considered - PowerPoint Presentation

blastoracle
blastoracle . @blastoracle
Follow
342 views
Uploaded On 2020-06-30

Black Magic Coding Constructs considered - PPT Presentation

Violations of Structured Programming Background Programming Languages before the 1980s allowed program flow to bounce around anywhere the programmer wanted Background RESULT Spaghetti Code ID: 789630

structured background return loop background structured loop return programming 215 break continue programmers exit allowed statements control major function

Share:

Link:

Embed:

Download Presentation from below link

Download The PPT/PDF document "Black Magic Coding Constructs considered" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Black Magic

Coding Constructs consideredViolations of Structured Programming

Slide2

Background

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

Slide3

Background

RESULT: “Spaghetti Code”

Slide4

Background

“Spaghetti Code”very difficult to Debug

almost impossible to Maintain

not Reusable

Slide5

Background

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

Slide6

Background

Structured Programming: Example 1

Slide7

Background

Structured Programming: Example 2

Slide8

Background

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

Slide9

Background

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

Pascal enforces concepts of Structured

Prog

.

Slide10

C++

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

Slide11

C++

return from anywhere in a function:

Actually a major violation of SS, but commonly used by C++ programmers.

Slide12

C++

return from anywhere in a function:

int

main() {

...

if (

something

)

return 1;

...

return 0;

}

Slide13

C++

continue

jump to the end of a loop

somewhat common in C++

Slide14

C++

continue

while (

something

) { //loop control

...

if (

something)

// jump to beginning of loop

continue;

...

}

Slide15

C++

break

exit a control block

(loop, switch, if, etc.)

a little more common in C++

Slide16

C++

break;

while (

something

) { //loop control

...

if (

something)

break; // exit the loop

...

}

// jump to here

Slide17

C++

“The word that SHALL NOT be uttered”

banned by most C++ programmers

unrestricted use in C

major restrictions in C++

Slide18

C++

The word that SHALL NOT be uttered:GOTO

Slide19

CS 215

The following should NOT be used in any CS 215 programs (labs, projects, tests)continue

break

(except in a

switch

)

goto

Slide20

CS 215

The following is allowed:

return

in the middle of a function

Slide21

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

Slide22

Test

Nothing from this set of slides will be on the tests...

except NOT using the “banned” statements.