Question

In: Computer Science

1b. Explain each of the following with an example in two languages of your choice for...

1b. Explain each of the following with an example in two languages of your choice for each item. (25 points)

  • Orthogonality

  • Generality

  • Uniformity

Solutions

Expert Solution

Orthogonality:

  • In geometry, orthogonal means "involving right angles", but the term has been extended to general use, meaning the property of being independent (relative to something else)
  • Language constructs should not behave differently in different contexts.
  • The language constructs can be combined in a meaningful way.
  • The interactions of constructs, or the context of use, should not cause unexpected restrictions or behavior.
  • There should be no strange interactions!

In the context of a programming language, a set of features/constructs is said to be orthogonal if those features can be used freely in combination with each other. In particular, the degree of orthogonality is lessened if

  • particular combinations are forbidden (as exceptional cases) or
  • the meaning of a particular combination is not evident from the meanings of its component parts, each one considered without regard to context.

Examples of non-orthogonality :

  • C passes all parameters by value, except arrays, which are passed by reference.
  • In Java, primitive data types are passed by value, the rest by reference, yet they look the same! (This is also non-uniformity)
  • In Java, assigning objects is an assignment of references, while assigning primitive data types is done by value.
  • In C and C++, values of all data types, except array types, can be returned from a function.
  • In C, local variables must be defined at the beginning of a block, in C++ variable definitions can occur anywhere inside a block, but before use of course.

Example from assembly languages:

  • In VAX assembler, the instruction for 32-bit integer addition is of the form

ADDL op1 op2

where each of the opi's can refer to either a register or a memory location. This is nicely orthogonal.

  • In contrast, in the assembly languages for IBM mainframes, there are two separate analogous ADD instructions, one of which requires op1 to refer to a register and op2 to refer to a memory location, the other of which requires both to refer to registers. This is lacking in orthogonality.

Generality:

  • Avoiding special cases in the availability or use of constructs.
  • Combining closely related constructs into a single more general one.
  • Too much generality is bad!

Examples of Lack of Generality:

  • C lacks nested function definitions.
  • Pascal has no variable-length arrays, arrays lack generality.
  • In C, two structures or arrays cannot be directly compared using the equality (==) operator, but must be compared element by element. Ada on the other hand allows totally new operators to be defined. C++ can overload operators.
  • In Pascal, constants may not be expressions, opposite to Ada.
  • Java does not have multiple inheritance, but interface inheritance implementation is a good enough substitute.

Uniformity:

  • Similar things should look similar and have similar meanings
  • Inversely, different things should look different i.e. consistency of appearance and behavior.
  • Non-uniformity and non-orthogonality may be very closely related in some instances.

Examples of lack of uniformity:

  • In C++, a semicolon is necessary after a class definition but forbidden after a function definition.  class A { … }; int f() { … }
  • This non-uniformity was forced to allow C++ to be compatible with C.
  • Returned values from functions in Pascal look like assignments

function f : boolean;

begin

f :=true;

end;


Related Solutions

Give an example out of your kitchen of the following: Explain how your choice falls into...
Give an example out of your kitchen of the following: Explain how your choice falls into this category, and if there is a chemical name or symbol for it, please provide that as well. a) a compound                         b) a heterogeneous mixture                               c) an element (symbol) Moving to the Caves… Lechuguilla Caves specifically. Check out this picture of crystals of gypsum left behind in Lechuguilla Cave. https://upload.wikimedia.org/wikipedia/commons/c/c1/Lechuguilla_Chandelier_Ballroom.jpg 2) Describe three physical properties of these crystals, explain how each may...
With relevant example of your choice, explain in 2 (Two) pages the most important framework for...
With relevant example of your choice, explain in 2 (Two) pages the most important framework for managing operations used by production firm .
Compare two programming languages of your choice based on all these criteria. 1. Readability 2. Writability...
Compare two programming languages of your choice based on all these criteria. 1. Readability 2. Writability 3.Reliability 4. Cost
Are the following languages regular languages or not ? Justify your answer with a proof. ?...
Are the following languages regular languages or not ? Justify your answer with a proof. ? = {? | ? represents an integer strictly greater than 2020}, on alphabet Σ = {0,…,9}. ? = {? | |?|a > |?|b} on alphabet Σ = {a,b} ? = {? | ? is the code of a LOOP program syntactically correct } ? = {02?| ? ∈ ℕ} sur alphabet Σ = {0}.
Define the following terms and give an example of each 1a. Negative technological change 1b. Substitutes...
Define the following terms and give an example of each 1a. Negative technological change 1b. Substitutes in production 1c. Price ceiling 1d. Producer surplus 1e. Efficient market
Formal Languages Give a regular expression for each of the following languages: L2a = {w ?...
Formal Languages Give a regular expression for each of the following languages: L2a = {w ? {0,1}* | w corresponds to the binary encoding of non-negative integers that are evenly divisible by 4 L2b = {w ? {a,b}* | w contains at least one 'a' and exactly two b's} L2c = {w ? {0, 1, 2}* | w starts with a 2, ends with a 1 and contains an even number of 0's}.
Label each of the following statements true, false, or uncertain. Explain your choice carefully. (a) A...
Label each of the following statements true, false, or uncertain. Explain your choice carefully. (a) A sudden fear that a country is going to devalue leads to an increase in the domestic interest rate. (b) Because economies tend to return to their natural level of output in the medium run, it makes no difference whether a country chooses a fixed or flexible exchange rate. (c) A change in the expected future exchange rate changes the current exchange rate.
In each of the following indicate which reaction will occur faster. Explain your choice. A. BuBr...
In each of the following indicate which reaction will occur faster. Explain your choice. A. BuBr or BuI with sodium cyanide in dimethyl sulfoxide (DMSO) B. 1-Chloro-2-methylbutane or 1-chloropentane with sodium iodide in acetone C. Hexyl chloride or cyclohexyl chloride with sodium azide in dimethyl formamide D. Solvolysis of 1-bromo-2,2-dimethylpropane or tert-butyl bromide in ethanol E. Reaction of 1-chlorobutane with sodium acetate (NaOAc) in acetic acid or sodium methoxide in methanol F.Reaction of 1-chlorobutane with sodium azide (NaN3) or sodium...
*Explain the difference between procedural and nonprocedural languages. Use specific procedural and nonprocedural languages of your...
*Explain the difference between procedural and nonprocedural languages. Use specific procedural and nonprocedural languages of your choice to illustrate the difference. *Explain what is backtracking in Prolog systems, and why backtracking is necessary. *Explain resolution and unification in Prolog, and their relationship. *Write Prolog programs for the following problems: a) Reverse a list. b) Find the length of a list. c) Find the average of a list of numbers. *Write Scheme programs for the following problems: a) Reverse a list....
Label each of the following statements true, false, or uncertain. Explain your choice carefully. a. When...
Label each of the following statements true, false, or uncertain. Explain your choice carefully. a. When domestic inflation equals foreign inflation, the real exchange rate is fixed. b. A devaluation is an increase in the nominal exchange rate. c. A sudden fear that a country is going to devalue leads to an increase in the domestic interest rate. d. A change in the expected future exchange rate changes the current exchange rate. e. Because economies tend to return to their...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT