SlideShare a Scribd company logo
1 of 33
Names, Bindings, and Scopes
CP 111 Lecture No. 3
OUTLINE
● Names,
● Variables,
● Variable declarations,
● The Concept of Binding,
● Scope, Scope and Lifetime,
● Referencing Environments, and Named
Constants.
Names
The term identifier is often used interchangeably
with name.
Names
Design Issues
The following are the primary design issues for names:
● Are names case sensitive?
● Are the special words of the language reserved words or
keywords?
Name….
● A name is a string of characters used to identify some entity in a program.
● Names in most programming languages have the same form: a letter
followed by a string consisting of letters, digits, and underscore characters
( _ ).
● Fortran 95+ allows up to 31 characters in its names.
● Names in Java, C#, and Ada have no length limit, and all characters in them
are significant. C++ does not specify a length limit on names, although
implementors sometimes do.
● Note that the use of underscores and mixed case in names is a
programming style issue, not a language design issue.
Name….
● All variable names in PHP must begin with a dollar sign.
● In Perl, the special character at the beginning of a variable’s name, $,
@, or %, specifies its type (although in a different sense than in other
languages).
● In Ruby, special characters at the beginning of a variable’s name, @
or @@, indicate that the variable is an instance or a class variable,
respectively.
Name….
● In many languages, notably the C-based languages, uppercase and
lowercase letters in names are distinct; that is, names in these languages
are case sensitive.
● For example, the following three names are distinct in C++: rose, ROSE, and
Rose.
● To some people, this is a serious detriment to readability, because names
that look very similar in fact denote different entities. In that sense, case
sensitivity violates the design principle that language constructs that look
similar should have similar meanings. But in languages whose variable
names are case-sensitive, although Rose and rose look similar, there is no
connection between them.
Name….
● Obviously, not everyone agrees that case sensitivity is bad for names.
● In C, the problems of case sensitivity are avoided by the convention that
variable names do not include uppercase letters.
● In Java and C#, however, the problem cannot be escaped because many of
the predefined names include both uppercase and lowercase letters.
● For example, the Java method for converting a string to an integer value is
parseInt, and spellings such as ParseInt and parseint are not recognized.
● This is a problem of writability rather than readability, because the need to
remember specific case usage makes it more difficult to write correct
programs.
● It is a kind of intolerance on the part of the language designer, which is
enforced by the compiler.
Question?
Special Words
● In most languages, special words are classified as reserved words, which
means they cannot be redefined by programmers, but in some they are only
keywords, which means they can be redefined.
● A keyword is a word of a programming language that is special only in
certain contexts.
● A reserved word is a special word of a programming language that cannot be
used as a name.
● As a language design choice, reserved words are better than keywords
because the ability to redefine keywords can be confusing.
Special Words
● In most languages, names that are defined in other program units, such as
Java packages and C and C++ libraries, can be made visible to a program.
● These names are predefined, but visible only if explicitly imported. Once
imported, they cannot be redefined.
Variables
Variable
● A program variable is an abstraction of a computer memory cell or collection
of cells.
● Programmers often think of variable names as names for memory locations,
but there is much more to a variable than just a name.
● The move from machine languages to assembly languages was largely one
of replacing absolute numeric memory addresses for data with names,
making programs far more readable and therefore easier to write and
maintain.
● That step also provided an escape from the problem of manual absolute
addressing, because the translator that converted the names to actual
addresses also chose those addresses.
Variable
● A variable can be characterized as a sextuple of attributes: (name, address,
value, type, lifetime, and scope).
● Although this may seem too complicated for such an apparently simple
concept, it provides the clearest way to explain the various aspects of
variables.
● Our discussion of variable attributes will lead to examinations of the
important related concepts of aliases, binding, binding times, declarations,
scoping rules, and referencing environments.
sextuple attributes of a Variable:
• name,
• address,
• value,
• type,
• lifetime, and
• scope.
Name
● Variable names are the most common names in programs.
Address
● The address of a variable is the machine memory address with which it is
associated.
● This association is not as simple as it may at first appear.
● In many languages, it is possible for the same variable to be associated with
different addresses at different times in the program.
● It is possible to have multiple variables that have the same address.
● When more than one variable name can be used to access the same memory
location, the variables are called aliases.
Aliasing
● Aliasing is a hindrance to readability because it allows a variable to have its
value changed by an assignment to a different variable.
● For example, if variables named total and sum are aliases, any change to the
value of total also changes the value of sum and vice versa.
● A reader of the program must always remember that total and sum are
different names for the same memory cell.
● Because there can be any number of aliases in a program, this may be very
difficult in practice.
● Aliasing also makes program verification more difficult.
Type
● The type of a variable determines the range of values the variable can store
and the set of operations that are defined for values of the type.
● For example, the int type in Java specifies a value range of -2147483648 to
2147483647 and arithmetic operations for addition, subtraction,
multiplication, division, and modulus.
Value
● The value of a variable is the contents of the memory cell or cells
associated with the variable.
● It is convenient to think of computer memory in terms of abstract
cells, rather than physical cells.
● The physical cells, or individually addressable units, of most
contemporary computer memories are byte-size, with a byte usually
being eight bits in length.
Binding
● A binding is an association between an attribute and an entity, such as
between a variable and its type or value, or between an operation and a
symbol.
● The time at which a binding takes place is called binding time.
● Binding and binding times are prominent concepts in the semantics of
programming languages.
● Bindings can take place at language design time, language implementation
● time, compile time, load time, link time, or run time.
● For example, the asterisk symbol (*) is usually bound to the multiplication
operation at language design time. A data type, such as int in C, is bound to
a range of possible values at language implementation time.
Binding of Attributes to Variables
● A binding is static if it first occurs before run time begins and remains
unchanged throughout program execution.
● If the binding first occurs during run time or can change in the course of
program execution, it is called dynamic.
● The physical binding of a variable to a storage cell in a virtual memory
environment is complex, because the page or segment of the address space
in which the cell resides may be moved in and out of memory many times
during program execution.
Type Bindings
● Before a variable can be referenced in a program, it must be bound to a data
type.
● The two important aspects of this binding are how the type is specified and
when the binding takes place.
● Types can be specified statically through some form of explicit or implicit
declaration.
Type Bindings….
● An explicit declaration is a statement in a program that lists variable names
and specifies that they are a particular type.
● An implicit declaration is a means of associating variables with types
through default conventions, rather than declaration statements. In this
case, the first appearance of a variable name in a program constitutes its
implicit declaration.
● Both explicit and implicit declarations create static bindings to types.
Type Bindings….
Dynamic Type Binding
● With dynamic type binding, the type of a variable is not specified by a
declaration statement, nor can it be determined by the spelling of its name.
Instead, the variable is bound to a type when it is assigned a value in an
assignment statement.
● When the assignment statement is executed, the variable being assigned is
bound to the type of the value of the expression on the right side of the
nassignment.
● Such an assignment may also bind the variable to an address and a memory
cell, because different type values may require different amounts of
storage.
Storage Bindings and Lifetime
● Allocation: The memory cell to which a variable is bound somehow must be
taken from a pool of available memory.
● Deallocation is the process of placing a memory cell that has been unbound
from a variable back into the pool of available memory.
● The lifetime of a variable is the time during which the variable is bound to a
specific memory location.
● So, the lifetime of a variable begins when it is bound to a specific cell and
ends when it is unbound from that cell.
Static variables
● Static variables are those that are bound to memory cells before program
execution begins and remain bound to those same memory cells until
program execution terminates.
Local and Global Scope
● Local Scope: program structure that is a sequence of function
definitions, in which variable definitions can appear inside the
functions.
● Global scope Some languages, including C, C++, PHP, JavaScript,
and Python, allow a program structure that is a sequence of function
definitions, in which variable definitions can appear outside the
functions. Definitions outside functions in a file create global
variables, which potentially can be visible to those functions.
Scope and Lifetime
● Sometimes the scope and lifetime of a variable appear to be related.
Referencing Environments
● The referencing environment of a statement is the collection of all variables
● that are visible in the statement.
● The referencing environment of a statement in a static-scoped language is
the variables declared in its local scope plus the collection of all variables of
its ancestor scopes that are visible.
● In such a language, the referencing environment of a statement is needed
while that statement is being compiled, so code and data structures can be
created to allow references to variables from other scopes during run time.
Named constant
● A named constant is a variable that is bound to a value only once.
● Named constants are useful as aids to readability and program reliability.
● Readability can be improved, for example, by using the name pi instead of
the constant 3.14159265.
Questions?
END

More Related Content

What's hot

Programing paradigm & implementation
Programing paradigm & implementationPrograming paradigm & implementation
Programing paradigm & implementationBilal Maqbool ツ
 
From Programming to Modeling And Back Again
From Programming to Modeling And Back AgainFrom Programming to Modeling And Back Again
From Programming to Modeling And Back AgainMarkus Voelter
 
The GO programming language
The GO programming languageThe GO programming language
The GO programming languageMarco Sabatini
 
Architecting Domain-Specific Languages
Architecting Domain-Specific LanguagesArchitecting Domain-Specific Languages
Architecting Domain-Specific LanguagesMarkus Voelter
 
Perl Development (Sample Courseware)
Perl Development (Sample Courseware)Perl Development (Sample Courseware)
Perl Development (Sample Courseware)Garth Gilmour
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_ivNico Ludwig
 
C programming language Reference Note
C programming language Reference NoteC programming language Reference Note
C programming language Reference NoteChetan Thapa Magar
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNico Ludwig
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diarySHARDA SHARAN
 
over all view programming to computer
over all view programming to computer over all view programming to computer
over all view programming to computer muniryaseen
 
Dart PPT.pptx
Dart PPT.pptxDart PPT.pptx
Dart PPT.pptxDSCMESCOE
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++ shammi mehra
 

What's hot (19)

Programing paradigm & implementation
Programing paradigm & implementationPrograming paradigm & implementation
Programing paradigm & implementation
 
Programming Languages
Programming LanguagesProgramming Languages
Programming Languages
 
From Programming to Modeling And Back Again
From Programming to Modeling And Back AgainFrom Programming to Modeling And Back Again
From Programming to Modeling And Back Again
 
The GO programming language
The GO programming languageThe GO programming language
The GO programming language
 
Paradigms
ParadigmsParadigms
Paradigms
 
Architecting Domain-Specific Languages
Architecting Domain-Specific LanguagesArchitecting Domain-Specific Languages
Architecting Domain-Specific Languages
 
Perl Development (Sample Courseware)
Perl Development (Sample Courseware)Perl Development (Sample Courseware)
Perl Development (Sample Courseware)
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
C programming language Reference Note
C programming language Reference NoteC programming language Reference Note
C programming language Reference Note
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diary
 
over all view programming to computer
over all view programming to computer over all view programming to computer
over all view programming to computer
 
Dart PPT.pptx
Dart PPT.pptxDart PPT.pptx
Dart PPT.pptx
 
Introduction to programming languages part 1
Introduction to programming languages   part 1Introduction to programming languages   part 1
Introduction to programming languages part 1
 
Features of c
Features of cFeatures of c
Features of c
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++
 
OOP Poster Presentation
OOP Poster PresentationOOP Poster Presentation
OOP Poster Presentation
 
Introduction to programming c
Introduction to programming cIntroduction to programming c
Introduction to programming c
 
Introduction to ‘C’ Language
Introduction to ‘C’ LanguageIntroduction to ‘C’ Language
Introduction to ‘C’ Language
 

Similar to Computer programing 111 lecture 3

358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1sumitbardhan
 
A program _ is an abstraction in a programming language for the memor.pdf
A program _  is an abstraction in a programming language for the memor.pdfA program _  is an abstraction in a programming language for the memor.pdf
A program _ is an abstraction in a programming language for the memor.pdfshashanth1188
 
1.2 Evaluation of PLs.ppt
1.2 Evaluation of PLs.ppt1.2 Evaluation of PLs.ppt
1.2 Evaluation of PLs.pptmeenabairagi1
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfL2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfMMRF2
 
Using Variables in Programming
Using Variables in ProgrammingUsing Variables in Programming
Using Variables in Programmingflippanthorse6864
 
Using Variables in Programming
Using Variables in ProgrammingUsing Variables in Programming
Using Variables in Programmingabortivepyramid08
 
Using Variables in Programming
Using Variables in ProgrammingUsing Variables in Programming
Using Variables in Programmingunadvisednerve735
 
Programming languages and concepts by vivek parihar
Programming languages and concepts by vivek pariharProgramming languages and concepts by vivek parihar
Programming languages and concepts by vivek pariharVivek Parihar
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement_jenica
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfAbrehamKassa
 
Pattern-Level Programming with Asteroid
Pattern-Level Programming with AsteroidPattern-Level Programming with Asteroid
Pattern-Level Programming with Asteroidijpla
 

Similar to Computer programing 111 lecture 3 (20)

Unit 1
Unit 1Unit 1
Unit 1
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
 
A program _ is an abstraction in a programming language for the memor.pdf
A program _  is an abstraction in a programming language for the memor.pdfA program _  is an abstraction in a programming language for the memor.pdf
A program _ is an abstraction in a programming language for the memor.pdf
 
1.2 Evaluation of PLs.ppt
1.2 Evaluation of PLs.ppt1.2 Evaluation of PLs.ppt
1.2 Evaluation of PLs.ppt
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfL2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
 
Using Variables in Programming
Using Variables in ProgrammingUsing Variables in Programming
Using Variables in Programming
 
Using Variables in Programming
Using Variables in ProgrammingUsing Variables in Programming
Using Variables in Programming
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Using Variables in Programming
Using Variables in ProgrammingUsing Variables in Programming
Using Variables in Programming
 
C tokens
C tokensC tokens
C tokens
 
Programming languages and concepts by vivek parihar
Programming languages and concepts by vivek pariharProgramming languages and concepts by vivek parihar
Programming languages and concepts by vivek parihar
 
Golang online course
Golang online courseGolang online course
Golang online course
 
8844632.ppt
8844632.ppt8844632.ppt
8844632.ppt
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdf
 
Subprogram
SubprogramSubprogram
Subprogram
 
Pattern-Level Programming with Asteroid
Pattern-Level Programming with AsteroidPattern-Level Programming with Asteroid
Pattern-Level Programming with Asteroid
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
Unit 2.pptx
Unit 2.pptxUnit 2.pptx
Unit 2.pptx
 
Unit 2.pptx
Unit 2.pptxUnit 2.pptx
Unit 2.pptx
 

More from ITNet

lecture 8 b main memory
lecture 8 b main memorylecture 8 b main memory
lecture 8 b main memoryITNet
 
lecture 9.pptx
lecture 9.pptxlecture 9.pptx
lecture 9.pptxITNet
 
lecture 10.pptx
lecture 10.pptxlecture 10.pptx
lecture 10.pptxITNet
 
lecture 11.pptx
lecture 11.pptxlecture 11.pptx
lecture 11.pptxITNet
 
lecture 12.pptx
lecture 12.pptxlecture 12.pptx
lecture 12.pptxITNet
 
lecture 13.pptx
lecture 13.pptxlecture 13.pptx
lecture 13.pptxITNet
 
lecture 15.pptx
lecture 15.pptxlecture 15.pptx
lecture 15.pptxITNet
 
kandegeeee.pdf
kandegeeee.pdfkandegeeee.pdf
kandegeeee.pdfITNet
 
Ia 124 1621324160 ia_124_lecture_02
Ia 124 1621324160 ia_124_lecture_02Ia 124 1621324160 ia_124_lecture_02
Ia 124 1621324160 ia_124_lecture_02ITNet
 
Ia 124 1621324143 ia_124_lecture_01
Ia 124 1621324143 ia_124_lecture_01Ia 124 1621324143 ia_124_lecture_01
Ia 124 1621324143 ia_124_lecture_01ITNet
 
Cp 121 lecture 01
Cp 121 lecture 01Cp 121 lecture 01
Cp 121 lecture 01ITNet
 
Cp 111 5 week
Cp 111 5 weekCp 111 5 week
Cp 111 5 weekITNet
 
Teofilo kisanji university mbeya (TEKU) ambassador 2020
Teofilo kisanji university mbeya (TEKU) ambassador 2020Teofilo kisanji university mbeya (TEKU) ambassador 2020
Teofilo kisanji university mbeya (TEKU) ambassador 2020ITNet
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8ITNet
 
Tn 110 lecture 2 logic
Tn 110 lecture 2 logicTn 110 lecture 2 logic
Tn 110 lecture 2 logicITNet
 
Tn 110 lecture 1 logic
Tn 110 lecture 1 logicTn 110 lecture 1 logic
Tn 110 lecture 1 logicITNet
 
internet
internetinternet
internetITNet
 
Im 111 lecture 1
Im 111   lecture 1Im 111   lecture 1
Im 111 lecture 1ITNet
 
development study perspective full
development study perspective fulldevelopment study perspective full
development study perspective fullITNet
 
Gender issues in developement
Gender issues in developementGender issues in developement
Gender issues in developementITNet
 

More from ITNet (20)

lecture 8 b main memory
lecture 8 b main memorylecture 8 b main memory
lecture 8 b main memory
 
lecture 9.pptx
lecture 9.pptxlecture 9.pptx
lecture 9.pptx
 
lecture 10.pptx
lecture 10.pptxlecture 10.pptx
lecture 10.pptx
 
lecture 11.pptx
lecture 11.pptxlecture 11.pptx
lecture 11.pptx
 
lecture 12.pptx
lecture 12.pptxlecture 12.pptx
lecture 12.pptx
 
lecture 13.pptx
lecture 13.pptxlecture 13.pptx
lecture 13.pptx
 
lecture 15.pptx
lecture 15.pptxlecture 15.pptx
lecture 15.pptx
 
kandegeeee.pdf
kandegeeee.pdfkandegeeee.pdf
kandegeeee.pdf
 
Ia 124 1621324160 ia_124_lecture_02
Ia 124 1621324160 ia_124_lecture_02Ia 124 1621324160 ia_124_lecture_02
Ia 124 1621324160 ia_124_lecture_02
 
Ia 124 1621324143 ia_124_lecture_01
Ia 124 1621324143 ia_124_lecture_01Ia 124 1621324143 ia_124_lecture_01
Ia 124 1621324143 ia_124_lecture_01
 
Cp 121 lecture 01
Cp 121 lecture 01Cp 121 lecture 01
Cp 121 lecture 01
 
Cp 111 5 week
Cp 111 5 weekCp 111 5 week
Cp 111 5 week
 
Teofilo kisanji university mbeya (TEKU) ambassador 2020
Teofilo kisanji university mbeya (TEKU) ambassador 2020Teofilo kisanji university mbeya (TEKU) ambassador 2020
Teofilo kisanji university mbeya (TEKU) ambassador 2020
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8
 
Tn 110 lecture 2 logic
Tn 110 lecture 2 logicTn 110 lecture 2 logic
Tn 110 lecture 2 logic
 
Tn 110 lecture 1 logic
Tn 110 lecture 1 logicTn 110 lecture 1 logic
Tn 110 lecture 1 logic
 
internet
internetinternet
internet
 
Im 111 lecture 1
Im 111   lecture 1Im 111   lecture 1
Im 111 lecture 1
 
development study perspective full
development study perspective fulldevelopment study perspective full
development study perspective full
 
Gender issues in developement
Gender issues in developementGender issues in developement
Gender issues in developement
 

Recently uploaded

Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Recently uploaded (20)

Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Computer programing 111 lecture 3

  • 1. Names, Bindings, and Scopes CP 111 Lecture No. 3
  • 2. OUTLINE ● Names, ● Variables, ● Variable declarations, ● The Concept of Binding, ● Scope, Scope and Lifetime, ● Referencing Environments, and Named Constants.
  • 3. Names The term identifier is often used interchangeably with name.
  • 4. Names Design Issues The following are the primary design issues for names: ● Are names case sensitive? ● Are the special words of the language reserved words or keywords?
  • 5. Name…. ● A name is a string of characters used to identify some entity in a program. ● Names in most programming languages have the same form: a letter followed by a string consisting of letters, digits, and underscore characters ( _ ). ● Fortran 95+ allows up to 31 characters in its names. ● Names in Java, C#, and Ada have no length limit, and all characters in them are significant. C++ does not specify a length limit on names, although implementors sometimes do. ● Note that the use of underscores and mixed case in names is a programming style issue, not a language design issue.
  • 6. Name…. ● All variable names in PHP must begin with a dollar sign. ● In Perl, the special character at the beginning of a variable’s name, $, @, or %, specifies its type (although in a different sense than in other languages). ● In Ruby, special characters at the beginning of a variable’s name, @ or @@, indicate that the variable is an instance or a class variable, respectively.
  • 7. Name…. ● In many languages, notably the C-based languages, uppercase and lowercase letters in names are distinct; that is, names in these languages are case sensitive. ● For example, the following three names are distinct in C++: rose, ROSE, and Rose. ● To some people, this is a serious detriment to readability, because names that look very similar in fact denote different entities. In that sense, case sensitivity violates the design principle that language constructs that look similar should have similar meanings. But in languages whose variable names are case-sensitive, although Rose and rose look similar, there is no connection between them.
  • 8. Name…. ● Obviously, not everyone agrees that case sensitivity is bad for names. ● In C, the problems of case sensitivity are avoided by the convention that variable names do not include uppercase letters. ● In Java and C#, however, the problem cannot be escaped because many of the predefined names include both uppercase and lowercase letters. ● For example, the Java method for converting a string to an integer value is parseInt, and spellings such as ParseInt and parseint are not recognized. ● This is a problem of writability rather than readability, because the need to remember specific case usage makes it more difficult to write correct programs. ● It is a kind of intolerance on the part of the language designer, which is enforced by the compiler.
  • 10. Special Words ● In most languages, special words are classified as reserved words, which means they cannot be redefined by programmers, but in some they are only keywords, which means they can be redefined. ● A keyword is a word of a programming language that is special only in certain contexts. ● A reserved word is a special word of a programming language that cannot be used as a name. ● As a language design choice, reserved words are better than keywords because the ability to redefine keywords can be confusing.
  • 11. Special Words ● In most languages, names that are defined in other program units, such as Java packages and C and C++ libraries, can be made visible to a program. ● These names are predefined, but visible only if explicitly imported. Once imported, they cannot be redefined.
  • 13. Variable ● A program variable is an abstraction of a computer memory cell or collection of cells. ● Programmers often think of variable names as names for memory locations, but there is much more to a variable than just a name. ● The move from machine languages to assembly languages was largely one of replacing absolute numeric memory addresses for data with names, making programs far more readable and therefore easier to write and maintain. ● That step also provided an escape from the problem of manual absolute addressing, because the translator that converted the names to actual addresses also chose those addresses.
  • 14. Variable ● A variable can be characterized as a sextuple of attributes: (name, address, value, type, lifetime, and scope). ● Although this may seem too complicated for such an apparently simple concept, it provides the clearest way to explain the various aspects of variables. ● Our discussion of variable attributes will lead to examinations of the important related concepts of aliases, binding, binding times, declarations, scoping rules, and referencing environments.
  • 15. sextuple attributes of a Variable: • name, • address, • value, • type, • lifetime, and • scope.
  • 16. Name ● Variable names are the most common names in programs.
  • 17. Address ● The address of a variable is the machine memory address with which it is associated. ● This association is not as simple as it may at first appear. ● In many languages, it is possible for the same variable to be associated with different addresses at different times in the program. ● It is possible to have multiple variables that have the same address. ● When more than one variable name can be used to access the same memory location, the variables are called aliases.
  • 18. Aliasing ● Aliasing is a hindrance to readability because it allows a variable to have its value changed by an assignment to a different variable. ● For example, if variables named total and sum are aliases, any change to the value of total also changes the value of sum and vice versa. ● A reader of the program must always remember that total and sum are different names for the same memory cell. ● Because there can be any number of aliases in a program, this may be very difficult in practice. ● Aliasing also makes program verification more difficult.
  • 19. Type ● The type of a variable determines the range of values the variable can store and the set of operations that are defined for values of the type. ● For example, the int type in Java specifies a value range of -2147483648 to 2147483647 and arithmetic operations for addition, subtraction, multiplication, division, and modulus.
  • 20. Value ● The value of a variable is the contents of the memory cell or cells associated with the variable. ● It is convenient to think of computer memory in terms of abstract cells, rather than physical cells. ● The physical cells, or individually addressable units, of most contemporary computer memories are byte-size, with a byte usually being eight bits in length.
  • 21. Binding ● A binding is an association between an attribute and an entity, such as between a variable and its type or value, or between an operation and a symbol. ● The time at which a binding takes place is called binding time. ● Binding and binding times are prominent concepts in the semantics of programming languages. ● Bindings can take place at language design time, language implementation ● time, compile time, load time, link time, or run time. ● For example, the asterisk symbol (*) is usually bound to the multiplication operation at language design time. A data type, such as int in C, is bound to a range of possible values at language implementation time.
  • 22. Binding of Attributes to Variables ● A binding is static if it first occurs before run time begins and remains unchanged throughout program execution. ● If the binding first occurs during run time or can change in the course of program execution, it is called dynamic. ● The physical binding of a variable to a storage cell in a virtual memory environment is complex, because the page or segment of the address space in which the cell resides may be moved in and out of memory many times during program execution.
  • 23. Type Bindings ● Before a variable can be referenced in a program, it must be bound to a data type. ● The two important aspects of this binding are how the type is specified and when the binding takes place. ● Types can be specified statically through some form of explicit or implicit declaration.
  • 24. Type Bindings…. ● An explicit declaration is a statement in a program that lists variable names and specifies that they are a particular type. ● An implicit declaration is a means of associating variables with types through default conventions, rather than declaration statements. In this case, the first appearance of a variable name in a program constitutes its implicit declaration. ● Both explicit and implicit declarations create static bindings to types.
  • 25. Type Bindings…. Dynamic Type Binding ● With dynamic type binding, the type of a variable is not specified by a declaration statement, nor can it be determined by the spelling of its name. Instead, the variable is bound to a type when it is assigned a value in an assignment statement. ● When the assignment statement is executed, the variable being assigned is bound to the type of the value of the expression on the right side of the nassignment. ● Such an assignment may also bind the variable to an address and a memory cell, because different type values may require different amounts of storage.
  • 26. Storage Bindings and Lifetime ● Allocation: The memory cell to which a variable is bound somehow must be taken from a pool of available memory. ● Deallocation is the process of placing a memory cell that has been unbound from a variable back into the pool of available memory. ● The lifetime of a variable is the time during which the variable is bound to a specific memory location. ● So, the lifetime of a variable begins when it is bound to a specific cell and ends when it is unbound from that cell.
  • 27. Static variables ● Static variables are those that are bound to memory cells before program execution begins and remain bound to those same memory cells until program execution terminates.
  • 28. Local and Global Scope ● Local Scope: program structure that is a sequence of function definitions, in which variable definitions can appear inside the functions. ● Global scope Some languages, including C, C++, PHP, JavaScript, and Python, allow a program structure that is a sequence of function definitions, in which variable definitions can appear outside the functions. Definitions outside functions in a file create global variables, which potentially can be visible to those functions.
  • 29. Scope and Lifetime ● Sometimes the scope and lifetime of a variable appear to be related.
  • 30. Referencing Environments ● The referencing environment of a statement is the collection of all variables ● that are visible in the statement. ● The referencing environment of a statement in a static-scoped language is the variables declared in its local scope plus the collection of all variables of its ancestor scopes that are visible. ● In such a language, the referencing environment of a statement is needed while that statement is being compiled, so code and data structures can be created to allow references to variables from other scopes during run time.
  • 31. Named constant ● A named constant is a variable that is bound to a value only once. ● Named constants are useful as aids to readability and program reliability. ● Readability can be improved, for example, by using the name pi instead of the constant 3.14159265.
  • 33. END