Saturday, March 3, 2007

Software Development Process

I haven't considered that there are different methods to develop software, especially if it is done in collaboration.

I have five interesting Wikipedia entries I should read and digest (entry summaries taken from Wikipedia):

Software development process
A software development process is a structure imposed on the development of a software product. Synonyms include software lifecycle and software process. There are several models for such processes, each describing approaches to a variety of tasks or activities that take place during the process.
Waterfall model
The waterfall model is a sequential software development model (a process for the creation of software) in which development is seen as flowing steadily downwards (like a waterfall) through the phases of requirements analysis, design, implementation, testing (validation), integration, and maintenance. The origin of the term "waterfall" is often cited to be an article published in 1970 by W. W. Royce; ironically, Royce himself advocated an iterative approach to software development and did not even use the term "waterfall". Royce originally described what is now known as the waterfall model as an example of a method that he argued "is risky and invites failure".
Iterative and incremental development
Iterative and Incremental development is a software development process developed in response to the weaknesses of the more traditional waterfall model. The two most well known iterative development frameworks are the Rational Unified Process and the Dynamic Systems Development Method. Iterative and incremental development is also an essential part of Extreme Programming and all other agile software development frameworks.
Agile software development
Agile software development is a conceptual framework for undertaking software engineering projects.

There are a number of agile software development methods, such as those espoused by The Agile Alliance. Most agile methods attempt to minimize risk by developing software in short timeboxes, called iterations, which typically last one to four weeks. Each iteration is like a miniature software project of its own, and includes all of the tasks necessary to release the mini-increment of new functionality: planning, requirements analysis, design, coding, testing, and documentation. While an iteration may not add enough functionality to warrant releasing the product, an agile software project intends to be capable of releasing new software at the end of every iteration. In many cases, software is released at the end of each iteration. This is particuarly true when the software is web-based and can be released easily. Regardless, at the end of each iteration, the team reevaluates project priorities.

Agile methods emphasize realtime communication, preferably face-to-face, over written documents. Most agile teams are located in a bullpen and include all the people necessary to finish software. At a minimum, this includes programmers and their "customers" (customers are the people who define the product; they may be product managers, business analysts, or actual customers). The bullpen may also include testers, interaction designers, technical writers, and managers.

Agile methods also emphasize working software as the primary measure of progress. Combined with the preference for face-to-face communication, agile methods produce very little written documentation relative to other methods. This has resulted in criticism of agile methods as being undisciplined.
Formal methods
In computer science and software engineering, formal methods are mathematically-based techniques for the specification, development and verification of software and hardware systems. The use of formal methods for software and hardware design is motivated by the expectation that, as in other engineering disciplines, performing appropriate mathematical analyses can contribute to the reliability and robustness of a design. However, the high cost of using formal methods means that they are usually only used in the development of high-integrity systems, where safety or security is important.

Of course, there are many more articles to read on this subject. There is a list on Wikipedia of all entries about the Software Development Process.

After listening to the Cincon Smalltalk podcast series (of which most episodes have Industry Misinterpretations in their title), episode Industry Misinterpretations Episode 23: Retrospective Coherence (MP3 file), I came to the conclusion that this topic, the software development process, is a really interesting.

Some fun and interesting paraphrases from that podcast episode:

Most people hear to listen, not to understand, like they have read-only memory
in order for a complex system to have resilience, it has to have some degree of inefficiency
process and code optimization should always be the last step in development, otherwise the system loses it's flexibility and ultimately breaks down
the purpose of most meetings is to keep people from taking responsibility

And then there are many more profound notions in this episode. Be sure to listen, but be warned that the audio quality is a bit poor.

Friday, March 2, 2007

How to read technical texts

Perhaps I should reveal a recipe how to read technical texts more efficiently. It is really simple:

  1. read the text through and try to keep track of the global ideas; stop if you lose track of the material, and restart from the point you started, using method 2
  2. read the text more carefully, and do all the exercise and examples; stop if you lose track and get stuck in solving the exercise or doing the examples, and restart from the point you started, using method 3
  3. read the text for a third time, do all the exercise and examples, and add some of yourself; stop if you get stuck

Every time you get stuck, start over again from the point you started the last time, up to the point you got stuk. During the rereading of this part of the text, use a higher order method (1, 2, 3). So you could be reading little pieces of text, each time in another reading mode (1, 2, 3). Once you get past the point you got stuck in the text in the latest iteration, switch back to a lower order reading method.

If you get stuck in step 3, you need to find alternative information sources to supplement your reading. Try to find those sources through Google, by using the items you didn't understand as search terms. It simply means you lack information you need to understand the text. Once you have grasped the new concepts, reread the difficult parts of the technical text, using method 3.

You should have read the complete text at least three times, using methods 1, 2, and 3. Here is a diagram of the reading methods

1) global reading without doing exercises and examples
->
2) detailed reading doing all exercises and examples
->
3) reading doing all exercises and examples with some examples of your own

Structure and Interpretation of Computer Programs

Through the Code Newbie forum (I'm forum member Rasheed), I got a reference to Structure and Interpretation of Computer Programs by MIT Press. They use Scheme, just like that other great on-line book, How to Design Programs (also see Why this blog?, and the tag How to Design Programs on this blog).

There is also a series of hour long lectures on Google video. I have here a list of videos I have found (lectures 9a, 9b, and 10a were missing when I did a search on Google Video):

I also found the original videos, which you can download from this page. That is perhaps the best way to retrieve the videos. You can either download or torrent a DIVX .avi or a MPEG video file from each of the 20 lectures (ten times a and b lessons). This was a good reason for me to start using the Azureus bit-torrent client, because I want these lessons burnt on DVD.

How to Design Programs - 2.4 Errors

Here are the exercises and my solotions of Section 2.4, called "Errors", in How to Design Programs.

Exercise 2.4.1.

Evaluate the following sentences in DrScheme, one at a time:

(+ (10) 20)
(10 + 20)
(+ +)

Read and understand the error messages.

Solution

> (+ (10) 20)
function call: expected a defined name or a primitive operation name after an open parenthesis, but found a number

The number 10 shouldn't be between parentheses here.

> (10 + 20)
function call: expected a defined name or a primitive operation name after an open parenthesis, but found a number

The number 10 is at the wrong position, it should read (+ 10 20)

> (+ +)
+: this primitive operator must be applied to arguments; expected an open parenthesis before the primitive operator name

There should be a value or expression at that position (followed by a second value or expression).

Exercise 2.4.2.

Enter the following sentences, one by one, into DrScheme's Definitions window and click Execute:

(define (f 1)
  (+ x 10))

(define (g x)
  + x 10)

(define h(x)
  (+ x 10))

Read the error messages, fix the offending definition in an appropriate manner, and repeat until all definitions are legal.

Solution

(define (f 1)
  (+ x 10))
__________

define: expected a name for the function's 1st argument, but found a number

The faulty 1 should be replaced by a x:

(define (f x)
  (+ x 10))

(define (g x)
  + x 10)
__________

define: expected only one expression for the function body, but found at least one extra part

There is a open parenthesis missing, and a close parenthesis should be added to the end:

(define (g x)
  (+ x 10))

Exercise 2.4.3.

Evaluate the following grammatically legal Scheme expressions in DrScheme's Interactions window:

(+ 5 (/ 1 0))

(sin 10 20)

(somef 10)

Read the error messages.

Solution

> (+ 5 (/ 1 0))
/: division by zero
> (sin 10 20)
sin: expects 1 argument, given 2: 10 20
> (somef 10)
reference to an identifier before its definition: somef

Exercise 2.4.4.

Enter the following grammatically legal Scheme program into the Definitions window and click the Execute button:

(define (somef x)
  (sin x x))

Then, in the Interactions window, evaluate the expressions:

(somef 10 20)

(somef 10)

and read the error messages. Also observe what DrScheme highlights.

Solution

> (somef 10 20)
somef: this procedure expects 1 argument, here it is provided 2 arguments

There should only be one argument, e.g. (somef 10)

(define (somef x)
  (sin x x))

__________

> (somef 10)
sin: expects 1 argument, given 2: 10 10

The sin primitive accepts only one argument, it should read (sin x) in the definition.

How to Design Programs - 2.3 Word Problems

Here are the exercises and my solotions of Section 2.3, called "Word Problems", in How to Design Programs.

Exercise 2.3.1.

Utopia's tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the program tax, which determines the tax on the gross pay.

Also define netpay. The program determines the net pay of an employee from the number of hours worked. Assume an hourly rate of $12.

Solution

The gross pay is

gross = 12 * h

the tax is 15% of the gross pay, or

tax = gross * 0.15

The net pay is gross pay minus tax, or

netpay = grosspay - tax

This means that both tax and net pay are depending on the number of hours worked.

(define (grosspay h)
  (* h 12))

(define (tax h)
  (* (grosspay h) 0.15))

(define (netpay h)
  (- (grosspay h) (tax h)))

Exercise 2.3.2.

The local supermarket needs a program that can compute the value of a bag of coins. Define the program sum-coins. It consumes four numbers: the number of pennies, nickels, dimes, and quarters in the bag; it produces the amount of money in the bag.

Solution

This is really easy:

value = pennies * 1 + nickels * 5 + dimes * 10 + quorters * 25

or in DrScheme:

(define (sum-coins p n d q)
  (+ p (+ (* n 5) (+ (* d 10) (* q 25)))))

Exercise 2.3.3.

An old-style movie theater has a simple profit function. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the function total-profit. It consumes the number of attendees (of a show) and produces how much income the attendees produce.

Solution

Each performances brings in a revenue of:

revenue = attendees * 5

The performance costs are:

cost = 20 + attendees * 0.5

The profit is:

profit = revenue - cost

or in DrScheme:

(define (revenue n)
  (* n 5))
(define (cost n)
  (+ 20 (* n 0.5)))
(define (total-profit n)
  (- (revenue n) (cost n)))

Thursday, March 1, 2007

How to Design Programs - 2.2 Variables and Programs

Here are the exercises and my solotions of Section 2.2, called "Variables and Programs", in How to Design Programs.

Exercise 2.2.1.

Define the program Fahrenheit->Celsius, which consumes a temperature measured in Fahrenheit and produces the Celsius equivalent. Use a chemistry or physics book to look up the conversion formula.

solution

I found a formula here:

(F-32)*5/9 = C

Expressing this in DrScheme:

(define (Fahrenheit->Celsius F)
  (* (- F 32) (/ 5 9)))

Exercise 2.2.2.

Define the program dollar->euro, which consumes a number of dollars and produces the euro equivalent. Use the currency table in the newspaper to look up the current exchange rate.

Solution

Type this into Google

1 dollar in euros

The result was:

1 U.S. dollar = 0.757002271 Euros

So we need to multiply the amount of dollars with 0.757002271:

(define (dollar->euro D)
  (* D 0.757002271))

Exercise 2.2.3.

Define the program triangle. It consumes the length of a triangle's side and the perpendicular height. The program produces the area of the triangle. Use a geometry book to look up the formula for computing the area of a triangle.

Solution

According to this math page, the area of a triangle is calculated as follows:

A = (w * h) / 2

This means expressed in DrSchema, as a function:

(define (triangle w h)
  (/ (* w h) 2))

Exercise 2.2.4.

Define the program convert3. It consumes three digits, starting with the least significant digit, followed by the next most significant one, and so on. The program produces the corresponding number. For example, the expected value of

(convert3 1 2 3)

is 321. Use an algebra book to find out how such a conversion works.

Solution

According to this page, a number like 123 can be expressed as follows:

123 = 1 * 100 + 2 * 10 + 3

So, if the digits are given in the reverse order, 3, 2, 1, then the first value should be multiplied by 100, the second with 10, and the products should be added together with the third digit. This gives the following program:

(define (convert3 n1 n2 n3)
  (+ n1 (+ (* 10 n2) (* 100 n3))))

Exercise 2.2.5.

A typical exercise in an algebra book asks the reader to evaluate an expression like

for n = 2, n = 5, and n = 9. Using Scheme, we can formulate such an expression as a program and use the program as many times as necessary. Here is the program that corresponds to the above expression:

(define (f n)
  (+ (/ n 3) 2))

First determine the result of the expression at n = 2, n = 5, and n = 9 by hand, then with DrScheme's stepper.

Also formulate the following three expressions as programs:

  1. n2 + 10
  2. (1/2) · n2 + 20
  3. 2 - (1/n)

Determine their results for n = 2 and n = 9 by hand and with DrScheme.

Solution

For n = 2, n = 5, n = 9,

is 2(2/3), 3(2/3), and 5. With Stepper the results are 8/3, 11/3, and 5.

For n = 2 and n = 9 in n2 + 10, the results are 14 and 91.

(define (g n)
  (+ (sqr n) 10))

gives:

> (g 2)
14
> (g 9)
91

For n = 2 and n = 9 in (1/2) · n2 + 20, the results are 22 and 60(1/2).

(define (h n)
  (+ (* 1/2 (sqr n)) 20))

gives:

> (h 2)
22
> (h 9)
60.5

For n = 2 and n = 9 in 2 - (1/n), the results are 1(1/2) and 1(8/9).

(define (j n)
  (- 2 (/ 1 n)))

gives:

> (j 2)
1.5
> (j 9)
1.8

which are all correct.

How to Design Programs - 2.1 Numbers and Arithmetic

Here are the exercises and my solotions of Section 2.1, called "Numbers and Arithmetic", in How to Design Programs.

Exercise 2.1.1.

Find out whether DrScheme has operations for squaring a number; for computing the sine of an angle; and for determining the maximum of two numbers.

Solution:

In the Help Desk, Manuals, Beginning Student Language, there are these entries:

sqr : (num -> num)

purpose:
to compute the square of a number

sin : (num -> num)

purpose:
to compute the sine of a number (radians)

pi : real

purpose:
the ratio of a circle's circumference to its diameter

max : (real real ... -> real)

purpose:
to determine the largest number

Now, this would mean the following:

(define (square n)
  (sqr n))

(define (sin-angle a)
  (sin (* (* 2 pi) (/ a 360))))

(define (maximum n1 n2)
  (max n1 n2))

Running this code gives the following output:

> (square 5)
25
> (sin-angle 90)
#i1.0
> (sin (/ pi 2))
#i1.0
> (sin-angle 180)
#i1.2246467991473532e-16
> (sin pi)
#i1.2246467991473532e-16
> (maximum 3 5)
5
> (maximum -3 -5)
-3

So, there is the primitive sqr to calculate the square of a number, you need to use a formula with pi to convert from angles to radian, and there is the primitive max to calculate the maximum of two numbers.

Exercise 2.1.2.

Evaluate (sqrt 4), (sqrt 2), and (sqrt -1) in DrScheme. Then, find out whether DrScheme knows an operation for determining the tangent of an angle.

Solution:

> (sqrt 4)
2
> (sqrt 2)
#i1.4142135623730951
> (sqrt -1)
0+1i
> (tan (* (* 2 pi) (/ 45 360)))
#i0.9999999999999999