CSCI 3308 — Homework 3

Here are the answers to homework 3 as submitted by a student in the Fall 2006 class (same student whose answers were featured for Homework 1). We'd like other students to see the quality of work being submitted by their peers.

1. Explain the difference between a Program, and a Programming System as given by Brooks. (3 pts.)

A program is what is produced by entrepreneurial programmers working in garages or students to hand in as assignments. A program is considered finished by these types of programmers when it is a complete executable that is ready to be run by the author on the system on which it was developed. This is the type of output that the typical programmer is accustomed to and therefore this is what he uses when estimating a timeframe for the completion of a programming task.

However, for a program to be useful in a business environment, more effort must be put into its development. One way of making such a program more useful is to expend the effort to make it part of a programming system. A programming system is a collection of interacting programs that are coordinated together in a similar function and have a disciplined format. The assemblage of many of these components together constitutes an entire facility for large tasks. In order to transform a program into a programming system component, the program must be written so that all inputs and outputs conform in syntax and semantics with precisely defined interfaces. As part of the system, the program can only use its fair share of resources so it works in harmony with other components. Finally, a programming system component must be tested with all of the other components it is integrated with in all possible combinations in order to catch subtle bugs of interaction that are not apparent in the freestanding program. Brooks estimates that turning a freestanding program into a programming system component of the same function costs three times more due to adding these additional aspects to the program.

2. Explain the difference between a Program, and a Programming Product as given by Brooks. (3 pts.)

Again, a program can be thought of as an executable program that is complete in itself and is ready to be run by the author on the system on which it was developed. This is the kind of output that is produced by programmers working in garages and students to turn in as assignments. Although the program technically works at this point, more effort is still needed to turn the program into something that will be useful to an organization. Underestimating or ignoring this additional effort is the downfall of many programmers who are trying to meet deadlines.

One way of transforming a program into something more usable is to turn it into a programming product. Additional effort must be put into the initial program to make it able to be run, tested, repaired, and extended by anybody. It must also be usable in many environments for many sets of data and written in a generalized fashion so as to be able to take a wide range of inputs. Also, a programming product must be thoroughly documented and tested. These additional characteristics are what differentiate a program from a programming product. Brooks estimates that taking the additional steps to transform a program into a programming product takes thrice the effort of creating a program.

3. What files from the list above (r1q5s rqqs q51qs sss qqrs) match the shell wildcard pattern "[qrs]*q?s"? (2 pts.)

Answer: r1q5s rqqs qqrs

The shell wildcard pattern [qrs]*q?s is a rule for matching file names within the shell. Translated into english, it reads:

[qrs] Match files where the first letter of the file name is one of the lowercase letter 'q', 'r', or 's'. Followed by:
* Zero or more characters of any kind. Followed by:
q The lowercase letter 'q'. Followed by:
? Any single character. Followed by:
s The lowercase letter 's'.

All five files meet the first condition of starting with either 'q', 'r', or 's'. The next two conditions state that the file name must have 0 or more characters followed by a 'q'. Four of the file names meet this condition, and 'sss' is elminated because it does not have a 'q' in it. The next two conditions state that a single character followed by an 's' must follow the 'q' from before. Three of the four file names meet this condition, with 'q51qs' being eliminated because it does not have a single character between the 'q' and the 's'. Therefore, the files from the list above that match the shell wildcard pattern [qrs]*q?s are: r1q5s, rqqs, and qqrs.

4. Write a regular expression that would capture the two distances given for the two segments mentioned in the file. This means that your regular expression will surround the pattern that matches the distances in parens and will ignore all other numbers in the file. Note: you should write only one regular expression that can capture both distances and your regular expression can NOT be "(1254.25|538.702)". (2 pts.)

The regular expression ([0-9]+\.[0-9]+) will capture the two distances given for the two segments mentioned in the file. To build this regular expression, we must first look at the data we are trying to capture. In this case it is a distance in miles that is expressed as an arbitrary number of miles followed by a fractional number of miles in decimal notation with an arbitrary precision. Since we know that each distance will have a decimal point, the first part of the regular expression is the escaped decimal point '\.'. Next, we know that on either side of this decimal point there will be a series of one or more digits in the range 0-9 to make up the miles and the fractional part of the miles after the decimal point. So we use the '[0-9]' pattern to match the digit in the range 0-9 and use the '+' operator to indicate that one or more instances of this pattern should be matched. We place this pattern range and operator on either side of the escaped decimal point to indicate that we want to match one or more digits on both sides of the decimal point. Finally, we place parenthesis around the entire regular expression to capture the results of the match and store it as a backreference that we can later retrieve using a variable such as \1 or $1. The final regular expression is therefore ([0-9]+\.[0-9]+). A perl script illustrating how this regular expression captures the distances is as follows:

#!/usr/bin/perl
$string="                                                         01/06/2006

For the 25th segment of our trip, we traveled 1254.25 miles between
New York City and Boulder, Colorado. For the 26th segment of our
trip, we traveled 538.702 miles between Boulder and Los Gatos,
California.\n";
while($string =~ m/([0-9]+\.[0-9]+)/g){print $1; print "\n";}
exit(0);

Executing this script causes perl to assign the string in question to the variable '$string' and then use the specified regular expression to find the distances. The while loop searches for each matching instance in the string and the 'print $1' statement prints the backreference to the most recently found match. The end result is that the two distance values, and only the two distance values, are printed out on the command line when this perl script is executed.