Objectives


• Understand what is Scoping • Able to implement the LEGB rule • Understand what is module • Understand the implementation of access control in programming language

Summary


• Scope refers to the visibility of variables, parameters and functions in one part of a program to another part of the same program. • The process of binding a variable name with an object is called mapping. : = (colon and equal to sign) is used in programming languages to map the variable and object. • Namespaces are containers for mapping names of variables to objects. • The scope of a variable is that part of the code where it is visible. • The LEGB rule is used to decide the order in which the scopes are to be searched for scope resolution. • Local scope refers to variables defined in current function. • A variable which is declared outside of all the functions in a program is known as global variable. • A function (method) with in another function is called nested function. • A variable which is declared inside a function which contains another function definition with in it, the inner function can also access the variable of the outer function. This scope is called enclosed scope. • Built-in scope has all the names that are pre-loaded into program scope when we start the compiler or interpreter. • A module is a part of a program. Programs are composed of one or more independently developed modules. • The process of subdividing a computer program into separate sub-programs is called Modular programming. • Access control is a security technique that regulates who or what can view or use resources in a computing environment. It is a fundamental concept in security that minimizes risk to the object. • Public members (generally methods declared in a class) are accessible from outside the class. • Protected members of a class are accessible from within the class and are also available to its sub-classes • Private members of a class are denied access from the outside the class. They can be handled only from within the class. • Python prescribes a convention of prefixing the name of the variable/method with single or double underscore to emulate the behaviour of protected and private access specifiers. • C++ and Java, control the access to class members by public, private and protected keywords • All members in a Python class are public by default whereas by default in C++ and java all members are private.