Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scope J. Michael Moore.

Similar presentations


Presentation on theme: "Scope J. Michael Moore."— Presentation transcript:

1 Scope J. Michael Moore

2 Scope Scope: Region of code “In Scope”
Name declared in a scope is valid until the end of the scope

3 Types of Scope Global scope: the area of text outside of any other scope Avoid for variables OK for constants Namespace scope: named scope nested in the global scope or in another namespace Class scope: area of text within a class Local scope: between {…} braces of a block or in a function argument list Can be nested Statement Scope: In a for-statement

4 For some Examples:

5 Global Variables Normally considered “evil” Toyota Accelerator Bug
“Other egregious deviations from standard practice were the number of global variables in the system. (A variable is a location in memory that has a number in it. A global variable is any piece of software anywhere in the system can get to that number and read it or write it.) The academic standard is zero. Toyota had more than 10,000 global variables. “And in practice, five, ten, okay, fine. 10,000, no, we're done. It is not safe, and I don't need to see all 10,000 global variables to know that that is a problem,” Koopman testified.” Taken from Toyota Unintended Acceleration and the Big Bowl of “Spaghetti” Code Nothing we do in this course needs more than the academic standard, i.e. zero!


Download ppt "Scope J. Michael Moore."

Similar presentations


Ads by Google