NIM: 1801382963
Kali ini saya akan menjawab Assignment #8 dari Chapter 8 Programming Language Concepts R Sebesta
Review Questions
6. 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.
7. Under
what circumstances must an F# selector have an else clause?
*If the
expression returns a value, it must have an else clause.
8. What are
the common solutions to the nesting problem for two-way selectors?
*The common
solution is to force an alternative semantics, by using compound statements.
9. What are
the design issues for multiple-selection statements?
*-What is
the form and type of the control statement?
-How are
the selectable segments specified?
-Is
execution flow through the structure restricted to include just a single
selectable segment?
-How are
case values specified?
-What is
done about unrepresented expression values?
10. 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 Set
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 words 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).
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 (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.
No comments:
Post a Comment