Chapter 1 Flashcards
(16 cards)
What are some features of specific programming languages you know
whose rationales are a mystery to you?
Languages like Python, Modula-3, and Perl have unique features that often confound programmers. Python’s use of whitespace for syntax, Modula-3’s unique approach to Object-Oriented Programming, and Perl’s philosophy of multiple ways to accomplish a task can all be puzzling.
What arguments can you make for the idea of a single language for all
programming domains?
It would dramatically cut the costs of programming training and compiler purchase and maintenance; it would simplify programming recruiting and justify the development of numerous language dependent software development aids.
What arguments can you make against the idea of a single language for all programming domains?
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.
Name and explain another criterion by which languages can be judged
(in addition to those discussed in this chapter).
One possibility is wordiness. In some languages, a great deal of text is required for even simple complete programs. For example, COBOL is a very wordy language. In Ada, programs require a lot ofduplication 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.
What common programming language statement, in your opinion, is most detrimental to readability?
[NOT SURE]
In my opinion, one common **programming **language statement that can be detrimental to readability is the “goto” statement. The “goto” statement allows for unconditional jumps in the control flow of a program, often leading to complex and convoluted code. Its misuse can make the code difficult to understand, debug, and maintain.
The main reason “goto” is considered harmful to readability is that it introduces unstructured control flow, which can result in spaghetti code. It makes it challenging to follow the logical flow of the program, as execution can jump to arbitrary locations within the code. This makes it harder for developers to comprehend the code’s behavior, leading to bugs and reducing maintainability.
Java uses a right brace to mark the end of all compound statements.
What are the arguments for and against this design?
The argument for using the right brace to close all compounds is simplicity—a right
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.
Many languages distinguish between uppercase and lowercase letters in
user-defined names. What are the pros and cons of this design decision?
The reasons why a language would distinguish between uppercase and lowercase in its
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
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.
What are the arguments for writing efficient programs even though
hardware is relatively inexpensive?
One of the main arguments is that regardless of the cost of hardware, it is not free.
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.
Describe some design trade-offs between efficiency and safety in some
language you know.
In C, prioritizing efficiency often means using manual memory management (e.g., malloc/free) and pointer arithmetic, which can speed up execution but increases the risk of memory leaks and buffer overflows. On the other hand, prioritizing safety involves using bounds-checked arrays, smart pointers (in C++), or runtime checks, which reduce vulnerabilities but add overhead.
In Python, dynamic typing and garbage collection enhance safety by preventing memory corruption and type mismatches, but they reduce efficiency due to higher memory usage and slower execution compared to statically typed languages.
Ultimately, the trade-off depends on the application—system programming favors efficiency (C), while high-level scripting prioritizes safety (Python).
In your opinion, what major features would a perfect programming lan
guage include?
A perfect programming language would include:
Performance & Efficiency – Fast like C++ but with JIT support.
Memory Safety – Automatic management like Rust or garbage collection.
Strong, Inferred Typing – Prevents errors while keeping syntax concise.
Interoperability – Easy integration with C, Python, and WebAssembly.
Concise & Readable Syntax – Expressive like Python, structured like Go.
Concurrency & Parallelism – Safe multi-threading and async/await.
Meta-programming – Lightweight macros and reflection.
Error Handling – Explicit but minimal boilerplate.
Security & Sandboxing – Prevents undefined behavio
Describe the advantages and disadvantages of some programming envi
ronment you have used.
Python Programming Environment
Advantages:
Ease of Use – Simple, readable syntax with high-level abstractions.
Rich Standard Library – Includes built-in modules for networking, data processing, and more.
Dynamic Typing & Memory Management – No need to worry about memory allocation.
Cross-Platform – Runs on Windows, Linux, and MacOS without modification.
Disadvantages:
Slower Execution – Interpreted and dynamically typed, making it slower than C.
Higher Memory Usage – Due to garbage collection and dynamic objects.
Limited Low-Level Control – Not ideal for systems programming or real-time applications.
How do type declaration statements for simple variables affect the read
ability of a language, considering that some languages do not require
them?
The use of type declaration statements for simple scalar variables may have very little
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.
Many contemporary languages allow two kinds of comments: one in
which delimiters are used on both ends (multiple-line comments), and
one in which a delimiter marks only the beginning of the comment (one
line comments). Discuss the advantages and disadvantages of each of
these with respect to our criteria
The main disadvantage of using paired delimiters for comments is that it results in
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.