Saturday, December 6, 2014

Q&A Assignment #11 Chapter 9 Review Questions & Problem Set

Name : Vina Melinda
NIM  : 1801380106

Untuk kali ini saya akan menjawab Assignment #11 Problem Set dan Review Questions dari Chapter 9 dari Sebesta.


Review Questions:

6. Q: What is a Ruby array formal parameter?
A: Ruby supports a complicated but highly flexible actual parameter configuration. The initial parameters are expressions, whose value objects are passed to the corresponding formal parameters. The initial parameters can be following by a list of key => value pairs, which are placed in an anonymous hash and a reference to that hash is passed to the next formal parameter. These are used as a substitute for keyword parameters, which Ruby does not support. The hash item can be followed by a single parameter preceded by an asterisk. This parameter is called the array formal parameter.

7. Q: What is a parameter profile? What is a subprogram protocol?
A: Parameter profile of a subprogram contains the number, order, and types of its formsl parameter. A protocol of subprogam is ite parameter profile plus, if it is a function, its return type。

8. Q: What are formal parameters? What are actual parameters?
A: Formal parameter is the parameter in the subprogram header. They are sometimes thought of as dummy variables because they are not variable in the usual case. Actusl parameter is a subprogram call statement that must inckude the nameof the subprogram and a list of parameters to be bound to the formal parameter of the subprogram.

9. Q: What are the advantages and disadvantages of keyword parameters?
A: The advantage of keyword parameters is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.

10. Q: What are the differences between a function and a procedure?
A: A function returns a value and a procedure just executes commands. The name function comes from math. It is used to calculate a value based on input. A procedure is a set of command which can be executed in order. In most programming languages, even functions can have a set of commands. Hence the difference is only in the returning a value part. But if you like to keep a function clean, (just look at functional languages), you need to make sure a function does not have a side effect.


Problem Set:

6. Q: Present one argument against providing both static and dynamic local
variables in subprograms.
A: In subprograms local variables can be static or dynamic. If local variable treated statically, this allows for compile-time allocation or deallocation and ensures proper type checking but doesn't allow recursion. However, if local variables treated dynamically, this allows for recursion at the cost of run-time allocation or deallocation and initialization because these are stored on a stack, referencing is indirect based on stack position and possibly time consuming.

7. Q:Consider the following program written in C syntax:
void fun (int first, int second) {
first += first;
second += second;
}
void main() {
int list[2] = {1, 3};
fun(list[0], list[1]);
}
For each of the following parameter-passing methods, what are the values
of the list array after execution?
a. Passed by value
b. Passed by reference
c. Passed by value-result
A: a. 1, 3
b. 2, 6
c. 2, 6

8. Q: Argue against the C design of providing only function subprograms.
A: If a language only provides functions, then programmers must live with the restriction of returning only one result from any subprogram or functions must allow side effects, which is considered bad.

9. Q: From a textbook on Fortran, learn the syntax and semantics of statement
functions. Justify their existence in Fortran.
A: The Fortran 90 standard (ISO/IEC 1539: 1991) describes the syntax and semantics of a programming language. However, the standard addresses certain aspects of the Fortran processing system, but does not address others. When specifications are not covered by the standard, the interpretation is processor dependent; that is, the processor defines the interpretation, but the interpretation for any two processors need not be the same. Programs that rely on processor-dependent interpretations typically are not portable. (Jeanne C. Adams, Walter S. Brainerd, et. al., 1992)

10. Q: Study the methods of user-defined operator overloading in C++ and Ada,
and write a report comparing the two using our criteria for evaluating
languages.
A: C was downgraded because it is essentially limited to syntactic (re)naming of predefined data types and data structures, with building-block capabilities within these limitations. Unlike Ada, neither C nor C++ allows restrictions to the range of a type. The C++ extensions to C in this category are the most significant enhancement. A class in C++ is a user-defined data type that provides data hiding, guaranteed initialization of data, implicit type conversion for user-defined types, dynamic typing, user-controlled memory management, and mechanisms for overloading operators. Ada has been downgraded slightly by the SEI for lacking a mechanism like classes that permits programming by specialization and extension. (Nelson H. Weiderman, 1991)

Monday, December 1, 2014

Q&A Assignment #10 Chapter 8 Review Questions & Problem Set

Name : Vina Melinda
NIM  : 1801380106

Untuk kali ini saya akan menjawab Assignment #10 Problem Set dan Review Questions dari Chapter 8 dari Sebesta.


Review Questions:

6. Q: What is unusual about Python’s design of compound statements?
A:  Python uses indentation to specify compound statements. For example,if x > y :
x = y
print “case 1″
equally indent statements are grouped as one compound statement.

7. Q: Under what circumstances must an F# selector have an else clause?
A: If the expression returns a value, it must have an else clause

8. Q: What are the common solutions to the nesting problem for two-way
selectors?
A: The common solution to the nesting problem is to use alternating means of forming a compound statements.

9. Q: What are the design issues for multiple-selection statements?
A:
1. What is the form and type of the expression that controls the selection?• How are the selectable segments specified?
2. Is execution flow through the structure restricted to include just a single selectable segment?
3. How are the case values specified?
4. How should unrepresented selector expression values be handled, if at all?

10. Q: Between what two language characteristics is a trade-off made when
deciding whether more than one selectable segment is executed in one
execution of a multiple selection statement?
A: The C# switch statement differs from that of its C-based predecessors in two ways. First, C# has a static semantics rule that disallows the implicit execution of more than one segment. The rule is that every selectable segment must end with an explicit unconditional branch statement: either a break,which transfers control out of the switch statement, or a goto, which can transfer control to one of the selectable segments (or virtually anywhere else).
As with C, if there is no break at the end of the selected segment, execution continues into the next segment.

Problem Set:

6. Q: Analyze the potential readability problems with using closure reserved
words for control statements that are the reverse of the corresponding
initial reserved words, such as the case-esac reserved words of
ALGOL 68. For example, consider common typing errors such as transposing
characters.
A: There's not really a readability problem, it's simply something you get used to, and after some experience the problems falls out of the process. Similar to how many Lisp users "don't see" the parentheses. They simply don't stand out in the general case for the experienced reader.
You have to recall the time of Algol, notably the "68" part, as in 1968.The bright side of the fi, esac, and od is that they clearly indicate what kind of block they're terminating, and they do it with a single token. Esac is no less clear than }, which is a meaningless bracket until you know otherwise. The {} have the benefit of consistency, while less wordy than Pascals begin - end generic block sequence.Finally, consider how dominant the English language is in computer language design, and while folks who don't speak english may have some initial issues with the languages, that clearly passes over time.So, it's a short hurdle that falls away quickly with use.

7. Q: Use the Science Citation Index to find an article that refers to Knuth
(1974). Read the article and Knuth’s paper and write a paper that summarizes
both sides of the goto issue.
A: Considering the time frame of the early to mid seventies, Knuth’s description of an advantage of the use of gotos was well understood. In fact C language which was created in the late ’60s had already dealt with the problem you’ve given as an example. With nested loops and conditions calling for exiting those loops from deep within the nesting, gotos are more efficient and even more elegant than multiple test flags and testing statements. So C incorporated the “break” statement to handle that problem. Redefining “goto” in a situation where its use is valuable to something more restricted and directed to the problem was the answer. An answer given years before.

8. Q: In his paper on the goto issue, Knuth (1974) suggests a loop control
statement that allows multiple exits. Read the paper and write an operational
semantics description of the statement
A: Work on the formal semantics of programming languages began in the 1960’s
– a useful early reference is which reports on a conference held in Badenbei-Wien in 1964. The subsequent literature on formal semantics of sequential languages is extensive. A good state of the art example of a formal definition is that of standard ML. This definition is written in Structured
Operational Semantics. It is sobering that, after a quarter century of denotational semantics, it is still found more convenient to tackle the semantics of a language like SML in an operational way. Furthermore, it must be clear that it is extremely difficult to get a formal semantics to the stage where it correctly reflects the intuitions about a language. There are some language standards like that for Modula 2 which are actually being written using formal techniques. But overall the situation is that formal semantic definitions are written only by a very small number of highly skilled people.
The situation with recording the formal semantics

9. Q: What are the arguments both for and against the exclusive use of Boolean expressions in the control statements in Java (as opposed to also
allowing arithmetic expressions, as in C++)?
A: The primary argument for using Boolean expressions exclusively as control expressions is the reliability that results from disallowing a wide range of types for this use. In C, for example, an expression of any type can appear as a control expression, so typing errors that result in references to variables of incorrect types are not detected by the compiler as errors.No , it would not be a good idea. Although this custom precedence sounds like increasing flexibility, requiring parentheses to show a custom precedence would impact in readability and writability of a program.

10. Q: In Ada, the choice lists of the case statement must be exhaustive, so that there can be no unrepresented values in the control expression. In C++,
unrepresented values can be caught at run time with the default selector.
If there is no default, an unrepresented value causes the whole
statement to be skipped. What are the pros and cons of these two designs
(Ada and C++)?
A: In Ada, the choice lists of the "case" statement must be exhaustive, so that there can be no unrepresented values in the control expression.
In C++, unrepresented values can be caught at run time with the "default" selector. If there is no default, an unrepresented value causes the whole statement to be skipped.
Ada was designed for military grade software development.
The idea is that whenever you modify code in such a way that a new case emerges (for example adding a new value for an enumeration type), you are forced to manually revisit (and therefore re-validate) all the case statements that analyze it. Having a "default" is risky: you may forget that there is a case somewhere where the new case should not have been handled by the default.