Names, Bindings, and Scopes
Written on 19.15 by Unknown
We meet yet again through my blog and this time I'm gonna talk about my fifth assignment from Mr. Tri Djoko Wahjono, Ir, M.Sc. It is about " Names, Bindings, and Scopes", the fifth chapter from Sebesta's Programming Language Concepts book, so i answered 5 questions from the review questions and 5 questions from the problem sets. So here is my answer for them :
Review Question :
- What are the design issues for names?
- There are two primary design issues for names, first we have “are names case sensitive?”, and the second one we have ”are the special words of the language reserved words or keywords?".
- What is the potential danger of case-sensitive names?
- Writ ability and readability (because sometimes names that look alike are actually different).
- In what way are reserved words better than keywords?
- Reserved words are better than keywords because the ability to redefine keywords can be confusing.
- What is an alias?
- When more than one variable can be used to access the same memory location, the variables are called aliases.
- Which category of C++ reference variables is always aliases?
- Union types.
Problem set:
- Which of the following identifier forms is most readable? Support your decision.
- SumOfSales
- sum_of_sales
- SUMOFSALES
sum_of_sales, because there are underscore it’s easier to read and define its function.
- Some programming languages are typeless. What are the obvious advantages and disadvantage of having no types in language?
Advantage:
- The only advantage is that is allows coders to write sloppy programs quickly.
Disvantage:
- You are not in control of the data and variables, the compiler or interpreter is.
- If you mis-assign variables, there is no way for the compiler to catch any of your mistakes. It just “does what you said”, even if it is wrong.
- Supporting programs in a type-less language is much more difficult that in a strongly types one. It is often very difficult to determine what the original programmer wanted to do.
- Write a simple assignment statement with one arithmetic operator in some language you know. For each component of the statement, list the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language
- (C++)
int count;count = count + 5;
Possible types for count: set at language design time. Type of count: bound at compile time.
Set of possible values of count: bound at compiler design time. Value of count: bound at execution time with this statement. Set of possible meanings for the operator symbol ““:*bound at language definition time.*Meaning of the operator symbol “” in this statement: bound at compile time.
Internal representation of the literal “5”: bound at compiler design time.
- Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship.
- Both are related to the assignment and the statement
- Describe a situation when a history-sensitive variable in a subprogram is useful.
- History sensitive variables may be useful in data manipulation subprograms, where some operation is performed on a variable, and the function exits, then the function is called again. This way, the function doesn’t have to take the variable as a parameter, but only to return it.