1 / 22

Black Magic

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. Background. RESULT: “Spaghetti Code”. Background. “Spaghetti Code”

cedricc
Télécharger la présentation

Black Magic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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. Background RESULT: “Spaghetti Code”

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

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

  6. Background Structured Programming: Example 1

  7. Background Structured Programming: Example 2

  8. 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. C++ return from anywhere in a function: Actually a major violation of SS, but commonly used by C++ programmers.

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

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

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

  15. 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. 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. 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.

More Related