Solutions Manual to Concepts of Programming Languages Twelfth Edition R.W. Sebesta 1 / 4
17
Answers to Selected Problems
Chapter 1
Problem Set:
- Some arguments for having a single language for all programming domains are: It
- Some arguments against having a single language for all programming domains are:
- One possibility is wordiness. In some languages, a great deal of text is required for
- The argument for using the right brace to close all compounds is simplicity—a right
- The reasons why a language would distinguish between uppercase and lowercase in its
would dramatically cut the costs of programming training and compiler purchase and maintenance; it would simplify programmer recruiting and justify the development of numerous language dependent software development aids.
The language would necessarily be huge and complex; compilers would be expensive and costly to maintain; the language would probably not be very good for any programming domain, either in compiler efficiency or in the efficiency of the code it generated. More importantly, it would not be easy to use, because regardless of the application area, the language would include many unnecessary and confusing features and constructs (those meant for other application areas). Different users would learn different subsets, making maintenance difficult.
even simple complete programs. For example, COBOL is a very wordy language. In Ada, programs require a lot of duplication of declarations. Wordiness is usually considered a disadvantage, because it slows program creation, takes more file space for the source programs, and can cause programs to be more difficult to read.
brace always terminates a compound. The argument against it is that when you see a right brace in a program, the location of its matching left brace is not always obvious, in part because all multiple-statement control constructs end with a right brace.
identifiers are: (1) So that variable identifiers may look different than identifiers that are names for constants, such as the convention of using uppercase for constant names and using lowercase for variable names in C, and (2) so that catenated words as names can have their first letter distinguished, as in TotalWords. (Some think it is better to include a connector, such as underscore.) The primary reason why a language would not 2 / 4
18
distinguish between uppercase and lowercase in identifiers is it makes programs less readable, because words that look very similar are actually completely different, such as SUM and Sum.
- One of the main arguments is that regardless of the cost of hardware, it is not free.
- The use of type declaration statements for simple scalar variables may have very little
- The main disadvantage of using paired delimiters for comments is that it results in
Why write a program that executes slower than is necessary. Furthermore, the difference between a well-written efficient program and one that is poorly written can be a factor of two or three. In many other fields of endeavor, the difference between a good job and a poor job may be 10 or 20 percent. In programming, the difference is much greater.
effect on the readability of programs. If a language has no type declarations at all, it may be an aid to readability, because regardless of where a variable is seen in the program text, its type can be determined without looking elsewhere. Unfortunately, most languages that allow implicitly declared variables also include explicit declarations. In a program in such a language, the declaration of a variable must be found before the reader can determine the type of that variable when it is used in the program.
diminished reliability. It is easy to inadvertently leave off the final delimiter, which extends the comment to the end of the next comment, effectively removing code from the program. The advantage of paired delimiters is that you can comment out areas of a program. The disadvantage of using only beginning delimiters is that they must be repeated on every line of a block of comments. This can be tedious and therefore error- prone. The advantage is that you cannot make the mistake of forgetting the closing delimiter.
Chapter 2
Problem Set:
- Because of the simple syntax of LISP, few syntax errors occur in LISP programs.
- The main reason why imperative features were put in LISP was to increase its
- The main motivation for the development of PL/I was to provide a single tool for
- IBM was, for the most part, incorrect in its view of the future of the uses of
Unmatched parentheses is the most common mistake.
execution efficiency.
computer centers that must support both scientific and commercial applications. IBM believed that the needs of the two classes of applications were merging, at least to some degree. They felt that the simplest solution for a provider of systems, both hardware and software, was to furnish a single hardware system running a single programming language that served both scientific and commercial applications.
computers, at least as far as languages are concerned. Commercial applications are nearly all done in languages that are specifically designed for them. Likewise for scientific applications. On the other hand, the IBM design of the 360 line of computers was a great success--it still dominates the area of computers between supercomputers and minicomputers. Furthermore, 360 series computers and their descendants have been widely used for both scientific and commercial applications. These applications have been done, in large part, in Fortran and COBOL. 3 / 4
19
- The argument for typeless languages is their great flexibility for the programmer.
- A good deal of restraint must be used in revising programming languages. The
- One situation in which pure interpretation is acceptable for scripting languages is
- New scripting languages may appear more frequently than new compiled languages
Literally any storage location can be used to store any type value. This is useful for very low-level languages used for systems programming. The drawback is that type checking is impossible, so that it is entirely the programmer's responsibility to insure that expressions and assignments are correct.
greatest danger is that the revision process will continually add new features, so that the language grows more and more complex. Compounding the problem is the reluctance, because of existing software, to remove obsolete features.
when the amount of computation is small, for which the processing time will be negligible. Another situation is when the amount of computation is relatively small and it is done in an interactive environment, where the processor is often idle because of the slow speed of human interactions.
because they are often smaller and simpler and focused on more narrow applications, which means their libraries need not be nearly as large.
Chapter 3
Instructor's Note:
In the program proof on page 160, there is a statement that may not be clear to all, specifically, (n + 1)* … * n = 1. The justification of this statement is as follows:
Consider the following expression:
(count + 1) * (count + 2) * … * n The former expression states that when count is equal to n, the value of the later
expression is 1. Multiply the later expression by the quotient:
(1 * 2 * … * count) / (1 * 2 * … * count) whose value is 1, to get (1 * 2 * … * count * (count + 1) * (count + 2) * … * n) / (1 * 2 * … * count) The numerator of this expressions is n!. The denominator is count!. If count is equal to n, the value of the quotient is n! / n!or 1, which is what we were trying to show.
- / 4