Pada post
Review Questions
1. What is unusual about Python’s design of compound statements?
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.
Python uses indentation to specify compound statements. For example,
if x > y :
x = y
print “case 1″
2. Under what circumstances must an F# selector have an else clause ?
If the expression returns a value, it must have an else clause.
If the expression returns a value, it must have an else clause.
3. What are the common solution to the nesting problem for two way selector?
The common solution to the nesting problem is to use alternating means of forming a compound
4. What are the design issues for multiple-selection statements?
The design issues are whatthe the form and type of the expression that controls the selection is, how the selectable segments specified are , whether execution flow through the structure is restricted to include just a single selectable segment or not, how the case value are specified, and how unrepresented selector expression values should be handled if at all.
The design issues are what
5. 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?
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.
Problem Sets
6. 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 w ords of ALGOL 68. For example, consider common typing errors such as transposing characters.
The potential readability problem is the typing errors. It’s very possible to occur if we don’t type the code carefully.
7. 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.
An alternative viewpoint is presented in Donald Knuth's Structured Programming with go to Statements, which analyzes many common programming tasks and finds that in some of them GOTO is the optimal language construct to use. [7] In their quasi-standard book on the C programming language, Dennis Ritchie and Brian Kernighan warn that goto is "infinitely abusable ", but also suggest that it could be used for end-of-function error handlers and for multi-level breaks from loops.
8. 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.
Operational semantics are a category of formal programming language semantics in which certain desired properties of a program, such as correctness, safety or security, are verified by constructing proofs from logical statements about its execution and procedures, rather than by attaching mathematical meanings to its terms (denotational semantics).An alternative viewpoint is presented in Donald Knuth's Structured Programming with go to Statements, which analyzes many common programming tasks and finds that in some of them GOTO is the optimal language construct to use
8. 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.
9. 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++)?
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. 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++)?
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 (forexample 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.
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
No comments:
Post a Comment