CogSci
3
Introduction to Computing

Home

Syllabus

Schedule

Contact Us
Regrade Form

Printable
Version

Department of
Cognitive
Science

Concepts in Computer Programming

PROGRAMMING YOUR PC NO LONGER REQUIRES ADVANCED SKILLS
New research is focusing on creating software applications that typical end users can program themselves, without having to learn any programming language. Massachusetts Institute of Technology Media Lab research scientist Henry Lieberman said end users should be able to tweak programs to get them to perform customized functions. He advocates optional features in software that would let people change certain things about how the program operates using macros, or simple pieces of code that automate tasks. Spreadsheets are already a good example of end-user programming because they allow people to organize and compare pieces of data together. Before, spreadsheets were custom-designed programs for a single application. Carol Traynor, assistant professor of computer science at Saint Anselm College, suggested that software include menus that simplify programming or embedded systems that would adapt the software to user preferences without them being aware of it. (Investor's Business Daily, 28 December 2001)

But until that research because mainstream practice, software programs will be created the "old fashioned" way.smile

This is a brief discussion of some of the concepts commonly used in writing computer software programs. Without actually writing a computer program in some programming language, these concepts will seem very abstract. However, you should recognize some of the ideas presented here in your assignments with HTML and Excel.

Most software programs are authored in a high level language such as: Cobol, Java, JavaScript, Lisp, or C++. Since computer languages really are a language any of them can, in principle, be used to solve any problem. However, each of these languages was designed to solve a different sort of problem; e.g., Cobol is used to create business oriented applications, and therefore a particular problem may be more or less easy to define and solve in a particular language.

Here is a small portion of a program written in a "pseudo-language" that has a syntax similar to that of C++ or JavaScript.

An Example


...
StudentQuizTotal = StudentQuizTotal + Quiz4Score;
if (StudentQuizTotal => 80) {
	print "Student %s cheated", StudentName;
	exit();
}
...

The strange looking first line is not an algebraic anamoly, but a common construct used in many programming languages, often called an assignment statement. The "=" sign does not mean "equals", but instead means "replace" or "store the value"; i.e., store the value of the expression on the right of the "=" into the variable named to the left of the "=" (StudentQuizTotal).

We might say: StudentQuizTotal) is "set to" the sum of StudentQuizTotal and the Quiz4Score. Or assign the sum of StudentQuizTotal and the Quiz4Score to StudentQuizTotal.

So the first line means something like:

  1. (To the right of the "=" sign), take the current value of the variable StudentQuizTotal
  2. To that, add the value currently contained in the variable Quiz4Score (presumably the score of quiz #4).
  3. Take that new total and store it (back) into the variable StudentQuizTotal.

The second line means something like:

  1. Take the value currently stored in the variable StudentQuizTotal
  2. And compare that to the value "80"
  3. If the value in StudentQuizTotal is greater or equal, then perform (execute) the program statements bracketed by '{' and '}'. JavaScript uses the curley brackets ('{' and '}') to group a number of JavaScript statements into a block.
  4. If the value in StudentQuizTotal is less than 80, do not execute the block of program statements bracketed by '{' and '}', but continue the program with the first statement following the '}'.

The Program Instructions

A software program written in a high level language like JavaScript consists of one or more program statements. These statements are (in general) a list of instructions to the computer on how to solve the particular problem that the progarm was written to solve.
  • Programming languages tend to have a very rigid grammar; this is to ensure that your instructions to the computer are unambiguous.
  • The syntax for a particular programming language is a description of the rules for making grammatically correct statements. The statements in the high level language are checked for correct syntax by a software program called a compiler.
  • The instructions in the high level language are the source code for the program.
  • If the source code syntax is correct, each statement is then decomposed into the one or more actual machine language instructions that can be understood by the computer processor. This is called compiling the program.
  • The result of the compile process is a file of machine language instructions, called an executable or object file or object program.
  • In order for the program to execute, it is first copied into RAM memory by the operating system software (think, Windows, or UNIX, or MacOS). Each machine language instruction occupies one or more RAM locations.
  • The computer processor follows (executes) the program, starting with the first instruction in the lowest numbered RAM location (probably location 0). After completing the first instruction, the computer executes the instruction at the next higher RAM location, and so forth until the instructions in the program have run/executed.
  • Not all of the instructions are necessarily executed! The program may purposely skip certain instructions, or execute others numerous times.

Comments

Programming languages, even HTML, allow the programmer to leave notes to herself (or other readers of the source code).
  • These are called comments, or sometimes remarks and are ignored completely by the compiler, even if they appear to have language (e.g., JavaScript) statements in the comment. That is, the program you are writing is unaware that there are comments in along with your JavaScript code.
  • There is a special syntax used for comments so the compiler will not confuse them with the source langage statements. For instance, JavaScript uses 2 slashes ("//") to indicate that the rest of the line is a comment. E.g.,
    var ndx;	// this variable will be used to index array Scores
    

  • JavaScript also has a multi-line comment (one that can contain several lines. The comment is started with "/*" and continues until a matching "*/" is found. Everthing in between is ignored by the compiler, and not seen by the computer when executing the program. E.g.,
    /*
     * This is an example of a multi-line comment; Note that
     * it doesn't have to be structured like this, it could be
     */
    ...
    /* all on a single line, like this second example */
    

  • Comments are invaluable when you look back at a program you have written a while ago and no longer clearly remember. Or when part of your program is tricky or obscure. Or when you are looking at someone else's program and trying to figure it out.
  • Comments can also be used as an aid in debugging your program. You can insert print statements in your program to help you figure it out. Rather than through them all away, just comment them out and make them invisible to the computer. For example:
    // document.write( "The value of counter = " + counter );
    

    Leaving the document.write() in your program (but inactive because it was "commented out" does 2 things:
    1. Let's you easily reactivate the document.write() by removing the '//' (or /*, if you did it that way) should you need to debug the program in the future
    2. Shows you where you had problems with the program in the past, again, if you need to debug more in the future.

The Program Data

In the course of running, the software program will manipulate numbers or strings of text characters.
  • Numbers are what you expect.smile Except there are 2 different kinds: integers, which have no decimal part, and floating point, which can have a decimal part.
    • Examples of integers are: 1, 3, 32,768, -5; examples of floating point numbers are: -0.5, 10.0, 99.99, 5.0, and 3.1415962.
    • Integers are stored in the computer as base 2 or binary numbers. For more information on binary, click here.
    • Floating point numbers are stored internally as a kind of "scientific notation", with an exponent and mantissa (fraction). See http://www.psc.edu/general/software/packages/ieee/ieee.html for a detailed description.
  • Strings are things like:
    "You owe %f6.2 dollars\n"
    or
    "The wombat bites, you die. Game over.\n".
    
    The '"' (quotes) are used to show what part of the text is the string, and to distinguish the string from other variables and keywords in the language. And to include spaces in the string, if you wish, as the examples above do.
  • Both the single quote \'/ and the double quote \"/ can be used,
    • Some languages (like Perl) treat the different quotes differently. Variable expansion will occur in double quoted strings in Perl but not in single quoted ones.
    • You can use the different types to include quotes of the other type in a string; e.g.,
      var Warning = "Please don't do that!";
      
  • Some computer languages make a distinction between: "9" and 9. That is, "9" is a string, not a number, and might not be manipulated like a number (added to or subracted from), or may not even have the value 9 in binary!

Variables

As the program runs, the results of computations are stored into variables.
  • When she writes the program, the programmer gives each variable a name, presumably one that would help a reader determine the purpose of the variable.
  • Generally, variable names have to start with a letter, and can have letters, digits, and "_" (underscore) in them. Punctuation and space are not allowed in variable names.
  • Deciding on meaningful variable names is not as easy as it might sound. It is possible to call most variables a simple, "x", or "y", but that hides the meaning of the variable. Long variable names, like "SumOfStudentQuizScores", while meaningful can become unwieldy to type over and over.
  • During the compile process, the compiler associates each variable name with a unique location in RAM. That is, variables are stored in RAM, and have a unique numeric address in RAM.
  • Most languages require that you declare each variable before you use it. This lets the compiler know that you will be using that name as a variable in your program (and makes it easier for the compiler to check your syntax).
  • Some languages (like C or C++ require the you declare each variable as being a certain type, depending on the kind of data it will hold. Some example "types" are: int (integer), long (for holding bigger integer values), or float for floating point values with decimal fractions.
  • Other languages, like Perl or JavaScript don't require a specific type be declared. In JavaScript, you declare a variable called "foo" with the following syntax:
    var foo;
    
  • Most languages (JavaScript is one) allow you to initialize the variable (give it a starting value) at the same time that you declare it. E.g.,
    var foo = 3;
    
  • Usually you will declare your variables before any executable statements. Said another way, you should have all of your declarations (in JavaScript, the "var foo" type statements) before any of the "if" or assignment, etc statements.

The Assignment Statement and Expressions

Variables have values assigned to them or changed via an assignment statement. The syntax is something like:
	Variable_name = expression;
  • In an assignment statement, we have a variable name on the left, an equal sign ("="), and then an expression. An expression is a phrase in the language (say JavaScript) that can be evaluated.
  • After the assignment statement is executed, the variable will have the value of the expression stored in it.
  • An expression can be simply a constant or another variable, in which case the variable to the left of the "=" takes on the value of that constant or the current value of the other variable.
  • Or expressions can be more complex, involving constants, functions and the values of other variables, and operators. Some of the operators in JavaScript are:

    Arithematic Operators
    Operator
    x
    A x B
    means
    - A minus B
    * A times B
    / A divided by B
    % The integer remainder after dividing A by B
    Text Operators
    + B concatenated on to the right of A

  • Even more complex expressions can be created using '(' and ')' for grouping sub expressions.

Constants

Some of the numbers and strings will remain unchanged during the execution of the program; these are called constants.
  • The program author may also elect to give a name to a constant in order to increase the clarity of the source program instructions to someone reading them. For instance: in the example we assume the value "80" was the maximum possible score that students could achieve on their class quizzes.
  • The progammer might well define a named constant "MaxScore" and use that instead of "80" in her program. That way, someone reading the program would better know what the value "80" meant.

Arrays and Structures

Frequently, a programmer will want to manipulate a large number of variables which all have a common function/meaning, and are to be treated in the program exactly the same; for example, student quiz scores. Rather than create a large number of unique variable names (and how many is a problem), the programmer creates an array.
  • An array is a variable name that is associated with a number of adjacent locations in RAM.
  • If the name of the variable is, for example, StudentQuizScores, individual values within the array are accessed via an array index, or just index using a syntax something like:
    	StudentQuizScores[i]
    
    which means the i-th element/value in the array "StudentQuizScores".
  • The array name plus index notation is treated just like a regular variable in the programming syntax. E.g.,
    	StudentQuizScores[i] = StudentQuizScores[i] + Quiz4Score;
    
  • Depending on the particular programming language, the index associated with the very first element in an array might have the value 1 or 0 (most modern ones use 0).
  • To declare an array in JavaScript:
    var StudentQuizScores = new Array(10);
    			// declares StudentQuizScores to be an array
    			// and gives it 10 "indices", at 0 through 9
    			// But none of the StudentQuizScores[i] values
    			// have been set to anything (yet)
    
    Or
    var Colors = new Array( "red", "liteblue", "yellow", "green" );
    			// declares Colors to be an array with
    			// 4 elements (at indexes 0 through 3)
    			// and sets their initial value
    
Another type of data is called a record or structure, and is used to access information stored in a database, among other uses. A record is similar to an array in that there is more than a single RAM location associated with the record variable name. However, while an array is holds a number of like "objects" (values), a record holds different kinds of "objects". For example, LastName (a string), FirstName (a string), BirthDate (a number, or perhaps a "date"), Address (a string), City (a string), Zipcode (integer), Startdate ("date"), and Salary (a number),
  • In a complex program, you might have a record which contains an array as one of its elements (fields). For example, you frequently see a mailing address represented as 3 (or more) "address lines" to account for things like department, or apartment address, or PO Box, in addition to the more normal street address.
  • Or you might have an array of records.
Begin

Objects

JavaScript doesn't have records or structures per se, but it does have objects. In fact, JavaScript is called an Object Oriented programming languange ("OOP"). An object is something like a record in that it can hold a number of different types and sizes of variables with in it.

Some of those variables can be set or queried like normal variables and are called properties of the object. For instance, string variables which we just talked about are really objects in JavaScript. They have one important property, namely their length (how many characters are in the string). Consider:

    var str = "abcde";
    var n = str.length;	// how many characters in str
    
When referring to a property of an object, you use the object name, followed by a '.', and then the property name; e.g., str.length in our example above.

As well as properies, objects also may have methods which also allow you to set or query data inside an object. Unlike a property, which is like a variable, methods are functions which can have multiple arguments.

The Date object is an example of an object that has many methods associated with it. You can think of a Date object as a number or several numbers that hold everything that has to do with a particular month, day, year, and time. The methods let you extract (or set) various component numbers.

    var today = new Date();		// create a new Date object
    var hour = today.getHours();	// the current hour
    if (hour> 12) {
    	// it's after 12 PM!
    }
    

Some important objects as far as the assignment goes are:

  • document object. It lets you add HTML to your page via the document.write() method. The argument(s) to document.write will appear on your page where the document.write is. Also, if you have <FORM>, you can name the <FORM> itself as well as the various <INPUT> elements by using the NAME="..." attribute. Then you can refer to the elements via a syntax like document.FormName.ElementName.value. (Note "value" must be lowercase.Frown)
  • Date() object. Create a Date() object via the new keyword (as above), and then you can extract the hours (today.getHours()) or seconds (today.getSeconds()) or other Date component using the associated method.
  • Array() object. Again, use the new keyword to create an array object.
      var letters = new Array( "A", "B", "C" );	// create a new Array
      var many = letters.length;	// how many elements in the array
      
End

Flow of Control

So far, the programs that we have talked about are like simple cooking recipes; you have a list of ingredients (data), and a series of steps to follow in order. But how does a programmer deal with a situation like:
    ...
  1. If you have a conventional oven, ...
  2. If you have a microwave oven, ...
Or
    ...
  1. Repeat the previous steps until the dough is firm ...

To program these sorts of instructions, the programmer employs conditional or flow of control statements. As we saw in the earlier example, in addition to program statements to do calculations, there are program statements which change what statements will be executed next (based on some condition). Recall that normally the next instruction to be executed is the one in the next higher numbered RAM location. A flow of control statement causes the program flow to be transferred to instruction in another RAM location instead.

The machine language instruction that changes the program flow is called a branch or jump instruction; the Jumping ahead (to a higher numbered RAM location has the affect of skipping the program statements in between.

One of the classic flow of control constructs in high level languages is the if (or as EXCEL calls it, the logical if. The general form is:


if CONDITION
	then BLOCK-1
	otherwise BLOCK-2

Here "CONDITION" is a "logical expression" which asks a question, like: is the StudentScore greater than or equal to 70 (StudentScore >= 70), or is the Counter variable less than the NumberOfElements (Counter < NumberOfElements). A table of the Logical Operators follows:

Logical Expressions
Operator
x
A x B
means
== A is equal B
!= A is not equal B
> A is greater than B
< A is less than B
>= A is greater than or equal to B
<= A is less than or equal to B Logical And and OR
&& Logical expression A AND Logical expression B; both must be true for the whole expression to be true
|| Logical expression A OR Logical expression B; either or both may be true for the whole expression to be true

  • If the answer to the question (CONDITION) is true or yes, then the group of statements represented by "BLOCK-1" is executed.
  • If the answer to the question (CONDITION) is false or no, then the group of statements represented by "BLOCK-2" is executed.
  • Each time the "if" is executed, either "BLOCK-1" statements are executed, or "BLOCK-2" statements are executed, but not both. They are mutually exclusive. Note that the "if" might be in the body of a loop (see loops) so it might be executed a number of times as the program runs. And the answer to the CONDITION may vary depending on the values of the variables used in the CONDITION logical expression.
  • In JavaScript (and C++ and Java) BLOCK-1 and BLOCK-2 are a series of statements (but could be a single statemnt) called a block, surrounded by "{" and "}" (called curley brackets).

Here is a more concrete example, in the style of the JavaScript language:


if (StudentQuizTotal >= 70) {
	print "You have a passing grade (P)";
} else {
	print "You have a failing grade (NP)";
}

In the earlier example, the if statement there was no "else" part; in general, the "else" and BLOCK-2 statements are optional. In the first example, the if statement may cause the statements in the '{', '}' brackets to be skipped over. In any case, the program will continue with the statements following the close bracket ('}').

Another classic programming construct is to have a series of "if-then-else" statements strung together so that only one of the many BLOCK-1 (true condition) blocks is executed, to the exclusion of all the rest. For instance, in the next example, we want the StudentLetterGrade variable to be assigned only one grade.

Note that we use indenting to help show the logical structure of the program; i.e., one "if" is embedded in the "else" part of another "if". Indenting your source program is a valuable tool in helping you see the structure of your program as you create and modify it.


if (StudentQuizTotal >= 90) {
	StudentLetterGrade = "A";
} else {
	if (StudentQuizTotal >= 80) {
		StudentLetterGrade = "B";
	} else {
		if (StudentQuizTotal >= 70) {
			StudentLetterGrade = "C";
		} else {
			StudentLetterGrade = "F";
		}
}

Only one of the "StudentLetterGrade = X" statements will be executed. In other words, if the StudentQuizTotal is 90 or greater, then a 'A' (text string) is assigned. Otherwise (i.e., else), if the StudentQuizTotal is greater or equal 80, assign a 'B'. And so on.

This programming construct is so frequently used that in some programming languages there is a special syntax that avoids all the indenting that occurs with trying to show the embedded program structure. For instance, Perl has an "elif" part of the "if" which means "else if".

In JavaScript, there is an "else if" statement instead of "elif". The previous example would look like the following in JavaScript, and is arguably more readable.


if (StudentQuizTotal >= 90) {
        StudentLetterGrade = "A";
} else if (StudentQuizTotal >= 80) {
        StudentLetterGrade = "B";
} else if (StudentQuizTotal >= 70) {
        StudentLetterGrade = "C";
} else {
        StudentLetterGrade = "F";
}

Loops

It is also possible for the program to branch backwards. Jumping backwards to an instruction in a lower numbered RAM location has the affect of creating a loop, where the series of instructions between the jump instruction and where it jumps to, is executed over (and over) again. Each execution of the instructions of the loop body is called an iteration.

The loop is terminated when some condition is met. For instance, the loop counter reaches a certain value. Sometimes, through programmer oversight, the terminating condition will never be met; this results in an error called an infinite loop. (Of course, this is just expression since the loop really does end: when you reboot the computer, pull the plug out of the wall, or the world ends. All, way short of infinity. smile)

A Loop Example


var Index, TotalScores, LastScore;
...
TotalScores = 0;
Index = 0;
While (Index <= LastScore) {
	TotalScores = TotalScores + StudentQuizScore[Index];
	Index = Index + 1;
}
print "Total of all student scores is %d", TotalScores;
...

Explanation:
  1. Initialize the variable TotalScores to 0;
  2. Initialize the variable called Index to 0; index will be used both as the "loop counter" and as an index into the StudentQuizScore array.
  3. Compare Index to the value in LastScore, and if it is less
    1. Add the value of the Index-th element of StudentQuizScores to the current value in TotalScores; then store that sum back into TotalScores.
    2. Add 1 to the current value in Index.
    3. Compare that new value in Index, and if still less than LastScore, proceed with step "a" again.
    4. When at last the value in Index is greater than than that in LastScore, continue with the statements following the '}' bracket.
  4. Print the total of the scores.

Note that though the instructions within the loop are the same, the data values that are operated on each time are different, because Index changes each time "through" the loop. And since Index is different, StudentQuizScore[Index] is also different (and different location in the array).

Loops are one of the mechanisms that give computer software programs their power.

The previous loop example involved a while loop. Here is a for loop which does exactly the same thing, but with different syntax.


...
TotalScores = 0;
for (Index = 0; Index <= LastScore; Index = Index+1) {
	TotalScores = TotalScores + StudentQuizScore[Index];
}
print "Total of all student scores is %d", TotalScores;
...

Think of a for as
  • Having an INITIALIZE part that happens once before the loops starts.
  • A CONDITION that gets tested before the body of the loop is executed, even the very first time. Once the CONDITION becomes false, the execution of the loop stops.
  • And an INCREMENT part that happens at the end of each iteration through the loop, just before the CONDITION is tested again.
So the equivalent while loop would look like:
INTIALIZE;
while ( CONDITION ) {
	// the body of the loop is here and then
	INCREMENT
}

Subroutines and Functions

Another way to change a program's flow is to call a function or subroutine. (For this discussion, a subroutine is the same as a fuction, except that a function returns a value that can be used in a calculation, while a subroutine does not return a value.) For instance, suppose we define the following function called DegreesCentigrade. The function is defined to have a single argument (here called DegreesFahrenheit). The purpose of the function is convert its argument (presumably a temperature in degrees Fahrenheit) to a temperature in degrees Centigrade and return that temperature to the caller of the function.

A Function Definition


function DegreesCentigrade( DegreesFahrenheit ) {
	NewTemp = ((DegreesFahrenheit - 32) / 9) * 5;
	return NewTemp;
}

The code above is the function definition. The function is not run at the time of its definition. The definition describes the steps that will be taken (instructions executed) when the function is actually called (used) elsewhere in the program.

The argument, DegressFahrenheit in this example, is called a formal argument. It is just a placeholder that will be replaced by the actual argument when the function is called. For instance:

Using a Function


...
CentigradeBoiling = DegreesCentigrade( 212 );
CentigradeFreezing = DegreesCentigrade( 32 );
...
DoubleBoiling = 2 * DegreesCentigrade( 212 );
...

The values 212 and 32 are two different argument values for the function to use as part of its computation. The first time "DegreesCentigrade" is called, the variable DegreesFahrenheit will have the value 212, while the second time it will have the value 32.

Functions can be used right in another calculation. Where the function name and argument list appears will be replaced by the value returned by the function. You can even use a function (and it's arguments) as a argument to another function!

Functions are a clever way of packaging commonly used sequences of instructions so they can be reused without the need to write all the instructions each time. This is the same rationale for defining a style for a paragraph in Microsoft Word--it lets the author see which paragraphs are the same, and should be treated or modified in the same ways. By using arguments, the function can perform the same computation, but on different data each time, making it even more flexible and useful.

Taking the idea one step further, groups of common functions are stored in a library. Typical library functions would include a function to sort the data in an array, return the current time of day, day of the week, read or write information to a file on the computer disk, as well as many mathmatical and statistical functions.

For instance, in JavaScript the "math object" is used to hold many common mathematical functions (as well as constants). Math.PI is the constant pi, 3.14159..., while Math.sqrt(x) will compute the square root of variable x, and Math.cos(rad) computes the cosine of the variable rad. Consult documentation on JavaScript for a full description of the functions (called "methods") and constants available in the Math object. (Perhaps: http://developer.netscape.com/docs/manuals/js/client/jsref/math.htm.)

In order to make use of a library function, a programmer merely has to know the name of the function, what argument(s) it takes (and what order), and what result is returned.

About Function Arguments

A function might require a single argument, no argument, a fixed number of arguments, or even a variable number (this is generally more difficult). Unlike the attributes used with HTML tags, the order of function arguments is critical when there is more than one. HTML avoids this problem by using a "ATTRIBUTE_NAME=X" syntax for the tag arguments (attributes), so the order doesn't matter. I.e., the name of the particular attribute is given along with the value being assigned to it.

Using a different strategy, most programming languages rely on the order that the arguments are given (called "passed") to the function. For example, imagine a function called "pow" which takes 2 arguments, and returns the value of the first argument raised to the second argument power.


Begin
function pow( N,P ) {
	if ( P <= 0) {
		Error( "Fail! Can't deal with imaginary numbers" );
	}
	return N ** P; /* "X ** Y" means X raised to the Y power */
}
End
So pow(2,5) means 25 which is 32. That is not the same as pow(5,2) , which is is 52--25; not the same at all!

Recursion: a Special Type of Function

Remember loops? Some computer languages allow a function to invoke itself, which can also cause the repetition or looping of instructions. This process is called recursion; such a function is called a recursive function.

Recursion is a very natural way to solve some types of problems where there is hierarchical or symmetric data to work with. As with a loop, there needs to some way of exiting the (recursive) loop. You don't want infinite recursion any more than you would want an infinite loop.

A commonly used example of recursion is the mathematical function factorial. The definition and notation of factorial is something like:


factorial(N) == N!	/* N! is how mathematicians write factorial of N */
N! == N * (N-1) * (N-2) * (N-3) * ... * 1

That is, N! is the product (multiplication) of all the numbers from 1 to N.

While recursion is very helpful for some data structures, like trees, factorial is easily solved using a loop. For instance:


Begin
function factorial( N ) {
	var result;	/* a temporary variable for this function */
	if ( N <= 1) {
		return 1;
	}
	for( i=N; N > 1; N = N-1 ) {
		result = result * i;
	}
	return result;
}
End

But you could also think of this function in a recursive way, which might be much more natural!


function factorial( N ) {
	if ( N <= 1)
		return 1;
	return N * factorial( N-1 );
}

Which seems more natural/logical to you--iteration (looping) or recursion? The claim is that if you whichever technique you learn first will always seem most natural.

Variable Scope

Some variables are declared within a function and are said to be local to that function. Other variables may be declared such that their values are available to all functions; they are called global variables. The parts of your program where a particular variable is defined and accessible is called the scope of the variable.

JavaScript has both local variables (those declared within a function), and global ones--those variables declared outside the '{' and '}' of a function body definition. Parameters (arguments) to a function are also local to that function, and are not defined outside the function.

Consider the following example code:


var x;		// a global variable
var y;		// a 2nd global variable
...
function ComputeIt( N ) {
	var y;	// this is a local variable! Because it has the
		// same name as a global variable we cannot access
		// that global value from inside this function
	var z;	// a local variable, as is the parameter 'N'

	if ( N <= 1)
		return 1;
	y = x * N;	// our local y is set based on global x
	return y;	// return our local value; global y is not changed
}

function SetVal( N ) {
	y = N;		// set the global variable to the argument.
}

Here we have declared 2 global variables: x and y. Any function can access their values or even set their values. Global variables are one way (though perhaps not the best way) that functions can communicate information to each other.

Because we have declared a local variable y in our function "ComputeIt", we can not refer to the global variable y with the same name. All references to y with the scope of "ComputeIt" (i.e., between the '{' and matching '}' are taken to mean the local variable y. If we really need to refer to the global y, we need to give the local version a different name that doesn't conflict.

Input/Output

We need to get information into the computer and the results of software computations back out again. At the machine language level, this is done in one of two ways, depending on the device type, "character" or "block".
  • With a character device, the software program interacts with the device as if it were an array of RAM memory. For instance, when printing letters to the computer console screen, the software program stores each letter at a special memory location. The console hardware then displays the letter on the screen.
  • With a block device, a large number bytes (characters) of information are read (or written) at a time. Here the software program instructs the device to read or write its information starting at a particular RAM location address, and how many bytes of information are to be transfered. The computer hard disk is an example of a block device.
When we print something in our high level language, we might use a format to describe both the kind of data (string, integer, decimal) we are printing, and how the a number or string should appear on the screen or printer. E.g., how many digits to the left and right of the decimal point should be displayed, or how many characters of a text string should be seen. That's the purpose of the "%s" in the print statement of our first example.
print "Student %s cheated", StudentName;

The "%s" says to interpret the variable "StudentName" as if it were a string. Similarly,
print "Average score %f5.2", AverageScore;

says to print the value in variable "AverageScore" as a decimal number 5 digits maximum (including the decimal point), with 2 digits to the right of the decimal point.

Similar formats are used when reading information in. The format describes how many characters should be considerred a single unit, and what sort of variable they should be stored in.

Note that in JavaScript, you are generally using the document.write() function ("method") to write strings or numbers out to the document page. There is no convenient way to control the percision of numbers when outputting them in JavaScript.

There is also document.writeln() function ("method") in JavaScript. The difference between document.writeln() and document.write() is that document.writeln() prints a newline after it prints its argument list. Sort of like appending an HTML <BR>. The result is that the output from the next document.write() (or document.writeln()) will appear on the line below.

When you use document.write() several times in a row, the outputs will appear to be concatenated together as if produced by a single document.write(). For example, consider the following


var N = 3;

...

// remember + means concatenation when dealing with strings
document.write( "We're only going to ask you " + N + " time" );

if ( N > 1 ) {
	document.write( "s" );
}
...

If N is equal 1, then you will see: "We're only going to ask you 1 time". But if N is 2 or more, then you will see: "We're only going to ask you N times", where N is the real value of variable N.

Bugs and Debugging

We have presented several examples of JavaScript syntax now. Once you have got your syntax right, your program can be compiled and is ready to be run. It may come as a surprize to you that your program can run, but not produce the correct/desired result!

Your program has a "bug", a term coined by Rear Admiral Grace Hopper who discovered a moth that crawled into an early computer causing it to malfunction. (Actually, I think both the computer and the moth malfunctioned.smile)

How can this (bugs) happen in software?

  • You typed 3, when you meant 2. (A typo)
  • You used the variable "Cat" when you should have used the variable "Dog".
  • You didn't pass the proper arguments to a function or subroutine. Or you didn't pass them in the proper order (remember function pow()). Or a function or subroutine behaved in a way that is different from the way it was documented.
  • You forgot to declare a local variable that has the same name as a global one, so your function winds up manipulating the global value when you didn't intend that to happen.
  • You didn't really understand the problem correctly, so your solution is incorrect.
  • ...
Bugs can happen for many reasons, but, basically, you have not correctly described the solution to the problem to the computer in your program.

The process of tracking down these errors (bugs) and elimenating them is called debugging.

Using a Debugger

Many high level language development enviroments include a software program called a debugger. The debugger is a tool for interacting with your program as it runs. The kinds of things that the debugger lets you do include:
  • List the source code for your program (usually with the lines numbered so you can refer to a particular line in your program)
  • Insert a break point at a particular place in your program. When your program runs, and starts to execute a line where you have put a break point, the program will stop and the debugger will take control.
  • You can, of course, remove a break point you inserted previously.
  • You can have the debugger run your program one line at a time (this is called single stepping your program). It's a good way to see which part of an "if" statement gets executed.
  • You can continue from a break point, meaning that your program starts running again until it encounters another break point (could be this same one again) or finishes.
  • At any time the debugger is in control, you can print out the value of variables and arrays. This should help you understand what your program is really doing versus what it should be doing.smile
If debugger is available, learn to use it; it is far superior to using print statements! If your language or environment don't have a debugging capability, you'll have to resort to print statements to help show you the value of variables at various places in your program.

Unfortunately, JavaScript does not provide a debugging environment.

  • Instead of a print statement, you'll have to use alter() to display the values of your variables, because
  • If you use document.write(), the output from your document.write() statements will be mingled with any other HTML you have on your page (and make it hard to find/read).Frown
  • Don't forget you can concatenate strings together as a single argument for an alert(); e.g.,
    alert( "The value of x=" + x );
    

A Classic Bug

As an example of a bug, consider the following bit of code:
var X = 0;
var Y = 1;

if ( X = Y ) {
	print "Yes";
} else {
	print "No";
}

As long as Y is not zero, this code will always print "Yes", no matter what the value of X is! On the other hand, the trivially changed code below will always print "No" regardless of the value of .
var X = 0;
var Y = 0;

if ( X = Y ) {
	print "Yes";
} else {
	print "No";
}

What the heck is going on? Several things.
  • First, in many languages, JavaScript included, the value 0 is considered "false" while anything non-zero (even a negative number) is considered "true". So expressions like X < Y evaluate to a 0 if X is less than Y or a 1 if X is greater than or equal to Y.
  • In both examples, we don't have a logical expression: X==Y, instead we have an assignment expression: X=Y!
  • In the first example: if ( X = Y ), we assign Y (which has value != 0, thus true) to X. Then test to see if the result is non zero or zero. It's nonzero, so "Yes" is printed even though on casual inspection, it looks like we are getting 0 == 1!
  • In the second example, the opposite happens. Here Y has value 0, which then is assigned to variable X. The result is test for non zero or zero; of course, it's zero, and "No" is printed. So it looks as though 0 != 0.
The moral is to make sure that you use == and not = when testing for equality.

Solving Problems with Software Programs

So a software program is a list of instructions to the computer on how solve a particular problem. The problem might be summing up a number of student scores, or figuring out the temperature in Centigrade when given the Fahrenheit equivalent, or something more complex like computing the trajectory of a space shuttle or forecasting the weather.

How well the program solves the problem depends on a number of issues. One is the complexity of the problem being solved; how well is the programmer (or programmers, since large programs are often written by teams) able to describe the steps of the solution. A common technique for large programs is to break it up into smaller sub-problems until each part becomes a more managable size. (This is a good place to utilize functions or subroutines.)

Another area for the programmer to consider is how to deal with incorrect or missing data. Consider the following simple function that computes the area of a circle given the diameter of the circle.


function AreaOfCircle( Diameter ) {
	var PI = 3.1415962;
	var Radius = Diameter / 2.0;
	var Area;
	Area = (Radius * Radius) * PI;
	return Area;
}

The function simply takes its "Diameter" parameter and divides it by 2 to get the Radius of the circle. Then it multipless the Radius times the Radius times PI (e.g., PI * Radius2).

Simple. But what would happen if, for some reason, the function was given the value of -1.5 for the Diameter? What does it mean to have a circle with a negative diameter? The function would compute something, but what?

This is an example of "garbage in, garbage out"; where a software program produces a result based on nonsense input. Programs need to check input values for "reasonableness" before using them in computations. A more extreme example is shown in the line of code below:


	MPG = Gallons / Miles;

which might be trying to compute the miles per gallon (MPG) for some vehicle. If, for whatever reason, Miles has the value zero, the program will abruptly terminate when the division is attempted because dividing by zero is undefined (mathemnatically) and causes a computer hardware error!

Other Techniques--Neural Networks

In recent years, certain types of problems have been solved using neural networks. A neural network is a software implementation or model of the way scientists believe individual neurons in the brain behave. The programmer groups these artificial neurons together into a network of layers of input, output, and perhaps "hidden" layers in between.

Neural networks are especially useful when there is no obvious relationship between the inputs and outputs. "Obvious" meaning clear set of steps--i.e, a program--to get from the input to the output.

The network is then "trained" using known input and output sets. The network is presented with the known input and the result is compared with the desired output. If the network's result doesn't match the desired one, the difference between the two is used to alter the values of "hidden layer" neurons, and the network produces a new result. The new answer is compared with the desired output again and the difference between the two is fed back into the hidden layer. The process repeats until the difference between the nework's output and the desired output is acceptibly close as defined by the programmer.

Once the network is trained, the hidden layer values remain fixed, and the network can be given real inputs to work on. That is, the neural network has become, in essence, a function like we talked about earlier, except that there is no list of instructions inside the function telling how to derive the output from the inputs. Instead the process of creating the output was learned by the network.

Other Techniques--Statistical Modeling

Statistical modelling is another way to deal with function outputs which don't come follow from their inputs in the clearly describable way needed to write a program. A "large" sample of input and output results are collected. (How large the sample has to be is part of the science of statistics and out of the scope of this article.)

This sample is studied closely to discover any trends--e.g., 54% of the voters in the sample voted for the Democratic candidate. If the sample is statistically valid, then that trend can be mapped onto the whole population (i.e., all inputs and outputs) from which the sample was taken.

Getting the statistics just right is not easy as we saw in the 2000 US Presidential election!

The Operating System

Generally, software programs do not interact with the computer hardware directly. Instead, they use library functions that, in turn, interact with the operating system. The operating system is a software program that controls the various resources: RAM, screen, keyboard, hard disk, and even schedules the use of the CPU itself.

The operating system library provides a level of abstraction so that the application programmer does not need to be concerned with the many various details associated with hardware devices. For instance, the programmer does not need to know how large the disk drive holding her file of data is, nor where exactly on the disk it is located.

The operating system also acts as a resource manager or referee when multiple software programs try to access the disk or printer at the same time.

The specifications for how a programmer should call these operating system library functions is called an API, or "Application Program Interface". By publishing an API, or (even better) making it a standard by turning it over to an international standards committee, the operating system manufacturer lets any programmer write software that will run under their "OS".

On the other hand, by keeping parts of an API secret, the operating system manufacturer can keep other programmers from using certain features, and thus create programs that don't work as efficiently as they might (if they could use that functionality of the operating system).

Why would a operating system vendor not what some programs to run inefficiently? If that vendor also produced application software that had to compete with different vendors. By knowing the secret APIs, the OS vendor's application software would probably perform better.

The Software Industry

Let's take a look at the business of writing and selling software.

It does not take much to produce a software program:

  • A computer
  • A compiler of some sort (JAVA, C++, etc)
  • An idea,
  • Some practice programming, and
  • Lots of patience (for debugging smile)

Copying Software -- Piracy

A software program is not a physical thing, like a toaster. It is the embodiment of an idea, and, therefore, software programs are not usually patented. Instead they, like other intellectual property, are generally protected by copyright laws.

Unlike a toaster, it's relatively easy to create a copy of a software program. If the illegal copies are sold, it is called software piracy, and is a major concern and loss of revenue for the software industry.

REPORT SHOWS INCREASE IN PIRACY
The Business Software Alliance released a report showing that software piracy grew last year, mostly as a result of growing computer markets in countries with high piracy rates. Since the BSA's first study on software piracy in 1994, worldwide piracy rates had dropped until 2001. For example, software makers obtained 44 settlements with American companies in 2001 as a result of enforcement activities, with an estimated 25 percent of business software programs in the U.S. pirated. According to the most recent study, the worldwide piracy rate jumped from 37 percent in 2000 to 40 percent in 2001, costing the industry about $11 billion in lost sales. Vietnam leads the list, with a piracy rate of 94 percent, claimed the study, followed by ex-Soviet Bloc countries like Russia and the Ukraine. Washington Post, 10 June 2002
ONLINE AUCTIONS: BUYER BEWARE
Upwards of 60 percent of the software being offered at the auction sites of eBay, ZDNet, and ExciteAtHome is illegal, according to a Software & Information Industry Association (SIIA) survey. The survey scrutinized software products from Macromedia, FileMaker, Adobe Systems, and Visio; these particular software producers were chosen for the survey because they had complained to the SIIA about problems with the auction sites. The survey finds that illegal software was being offered in 109 out of 221 auction sales, while 72 offerings were legal, and 40 were of an undetermined nature. Most of the illegal software being sold violated licensing regulations, the survey determined. The SIIA, eBay, and other companies are holding talks about coming up with a solution to crack down on illegal software sales, says eBay's Jay Monahan. (IDG News Service 09/01/99)

CALIFORNIA'S GOVERNOR SIGNS SOFTWARE ORDER
In a symbolic move aimed at stopping software piracy, California Gov. Gray Davis signed an executive order on Friday requiring state agencies to enforce copyright laws internally. Software piracy has become so rampant that many agencies responsible for protecting copyrights have been unknowingly using illegal products themselves, Davis says. Although anti-piracy laws are already in place, Davis says "a whole range of laws have not been enforced as well as they should have been." Meanwhile, Microsoft charged four California businesses with software piracy on Friday, saying in its lawsuit that pirated software accounts for 30 percent of California's software sales. Pirated software results in lost sales taxes and wages that cost $11 billion each year globally and $2.8 billion in the United States. The Internet facilitates copying and distributing software, and therefore has made anti-piracy laws more difficult to enforce. (Houston Chronicle 10/16/99)
ARE UNIVERSITIES PIRACY PLAYGROUNDS?
University students and employees are becoming increasingly involved in software piracy, according to the Business Software Alliance (BSA) and the Software and Information Industry Association (SIIA). Illegal copying of software costs the industry nearly $3 billion a year, according to the two groups, and it is estimated that 38 percent of the 615 million new software applications installed around the world in 1998 were pirated. Piracy is particularly prevalent at universities because the institutions are extremely wired, with most students and employees enjoying unlimited Internet access, and because of widespread ignorance of copyright laws. Experts contend that students need to be told that there are limits to what they can do with software that has been legitimately purchased, and that software can only be legally copied one time for "backup" measures. Copyright experts say college IT administrators should choose one person on the staff to be in charge of piracy issues. That person should create and enforce regulations relating to software piracy based on current law, highlighting the fact that students could face expulsion or suspension from campus as a result of breaching policy. (Security Management, March 2000)

Copy Protection Schemes

Various schemes have been tried to prevent the illegal use of software, including:
  • Specially created copy protected software installation disks that prevented the simple copying of the software. Of course, this also prevented the consumer from making a legitimate backup copy of the disk.
  • A special piece of hardware that plugged into the computer's serial port or parallel port that was "sensed" by the software program and required to be present (plugged in). If the device was not present, the program would refuse to run. Such devices are sometimes called: dongles. Dongles are a nuisance because they can be easily lost, rendering the software useless.
  • A specially crafted "installation code" that is required to install the program
  • Some software programs look for copies of themselves on the local area network, and refuse to run a second copy. With many computers hooked directly to the Internet, many software vendors have their programs register themselves directly with the vendor over the Internet--so called "phoning home".
  • MICROSOFT SOFTENS XP ANTIPIRACY FEATURE
    Microsoft has announced that it will alter the controversial Product Activation policy in its forthcoming Windows XP operating system so that users can modify a certain number of hardware components inside their PC without having to register with the company for a new access code. The policy, which is intended to prevent the software from being copied to multiple PCs, has come under fire because it restricts access to the operating system if users make common changes to their PCs' hardware components. Users who add a graphics card or additional memory, for example, would have to contact Microsoft and re-register. Microsoft says it will allow users to change a certain number of hardware components within a limited amount of time--this time limit has not been decided yet--without having to gain a new access code. (Reuters, 18 July 2001)
None of these devices make consumers happy, as bought the software package, they feel they own the software package, and should be able to do whatever they wish with it.

But you don't own it!

The Software License

Software vendors normally do not sell you software. Instead they license to you. I.e., you do not own it, you only have a (limited) right to use it. The license typically limits the number of copies you can make, and other restrictions.

During the installation phase of a new software package, you have to "agree" to the license which is presented to you online. The license is full of legalese, which makes it hard to understand.

If you do not "agree" to the license, the installation process will quit without installing the product.

This is often true of software that you can download for free from the vendor's own website; i.e., software they are giving away!

Some software companies had a statement on the physical package that the software came in--in their eyes, opening the package (to install the software or look at the manual) meant that you agreed to their license. This is called a shrink wrapped license.

Some of the reasons that the vendors don't want you to actually own the software are:

  • If you actually owned it, you might want to make a bunch of copies of it to use on other computers you own. This is usually explicitly forbidden by the software license.
  • If you actually owned it, you might want to make a copy for a friend or relative to use.
  • If you actually owned it, you might want to open it up and see how it worked, like you might a toaster. Then you could make your own version. This is called reverse engineering, and is usually expressly forbidden by the software license.
  • If you could actually figure out how it worked, you might be able to make changes and improve it. Or use the ideas you find in the program source code to create your own, competing product.
  • If you owned the software, you could sell it to someone else when you were done with it, or dissatisfied with it. Caere, which makes an OCR package (Optical Character Recognition) recently tried to keep some one from selling their package on e-Bay.

Microsoft would seem to have gone one step further with its new operating system Windows XP. The license apparently forbids the use of "VNC" ( www.uk.research.att.com/vnc/download.html) which allows the remote display and control of a Windows computer. The following is from Infoworld:

    Reader Frank Brown sent me a completely different concern about XP, relating to VNC (Virtual Network Computing), a free remote-access application I described last week (see "Your virtual network," InfoWorld, March 11).

    Microsoft's XP license agreement says, "Except as otherwise permitted by the NetMeeting, Remote Assistance, and Remote Desktop features described below, you may not use the Product to permit any Device to use, access, display, or run other executable software residing on the Workstation Computer, nor may you permit any Device to use, access, display, or run the Product or Product's user interface, unless the Device has a separate license for the Product."

    From an article in InfoWorld

The Software Business

Like any business, the software industry makes money by selling your their product. Unlike other industries, software products don't wear out or break (but see "Software bugs." (They might become obsolete though.)

So in order to continue to make money, software developers must continually "improve" their product by releasing upgrades or whole new versions of their application.

In order to entice customers to buy the new versions, the developers add more and more features to their products, a process sometimes called "creeping featurism". This, in turn, makes the programs larger and larger (and slower), and increases the chances of flaws within the programs. (Larger and slower programs is one main reason people feel they need to purchase new computers.)

As the speed and availability of the Internet improve, a new model for software is developing: rented software.

COMPUTING POWER ON TAP
Rented applications are changing the face of computing, creating greater flexibility and customization. Rather than buy a software program, companies can now rent an application for as long as it is needed. Already, common desktop applications such as address books and calendars are available on the Internet, and many more types of programs are joining them. Startup Bidcom exemplifies this trend by creating a forum for all parties involved in a construction project. Participants such as architects, builders, and financiers can create and share via the Internet all of the documents used in the project in one site, eliminating the time and effort needed to distribute the documents via fax and e-mail. A new type of company, the application service provider (ASP), has arisen to distribute these applications. ASPs profit by charging by the hour for access to software programs. The trend in rented applications is also creating changes among traditional hardware and software distributors such as IBM. IBM is positioning itself as a supplier to ASPs, offering reliable computing power and software to help ASPs rent out applications. (Financial Times 11/01/99)
SOFTWARE EVOLVING INTO A SERVICE RENTED OFF THE NET
The transition of software from traditional packages to an Internet-based service is likely to advance significantly in 2000. Companies are already using the Internet for internal communications as well as customer transactions, and 24-hour Internet connections are becoming common in homes. Software companies in the future will sell applications as a service, just as utility companies sell electricity or phone service. The move to Internet-based computing is happening much more rapidly than the last major shift in computing, which was the move to client/server architectures that occurred about 10 years ago. In the future, the client could become essentially a Web browser, rather than a powerful PC. The shift of computing to the Internet threatens Microsoft's dominance, which was built on the PC computing model. Experts say any ruling in the antitrust trial might be irrelevant because of the rapid changes brought by Internet computing that are diminishing Microsoft's hold on the market. (New York Times 12/20/99)
MICROSOFT SAYS ITS FUTURE LIES IN SUBSCRIPTIONS
Microsoft CEO Steve Ballmer said the company is gearing itself to collect subscription revenues rather than offer only packaged software. The company is moving forward with a subscription model on several fronts, including the MSN ISP business, the HailStorm Web service, year-long subscriptions to the new Windows XP products, and Microsoft's new interactive TV product, UltimateTV. Already, the company has engineered many of its products for the move, such as incorporating a Web architecture in Office XP products so that they can be easily integrated into back-end office solutions from Great Plains Software. Microsoft acquired Great Plains this year and has begun packaging Great Plains software with Office features such as Excel and Outlook. Analysts question the new model, however, saying it could endanger Microsoft's stable business and cause mass confusion in the marketplace. (Wall Street Journal, 31 May 2001)
MANY COLLEGES WILL HAVE TO PAY MORE FOR MICROSOFT PRODUCTS
Microsoft is planning changes to its software purchasing and licensing agreements with universities and colleges. Although the changes will likely mean increased software costs for most institutions, with costs rising between 10 and 60 percent, some colleges and universities will actually be able to save money by buying only the simplified base package. Additionally, Microsoft is changing its Campus Agreement program to encourage schools to license its software under the company's subscription-renewal time line. Microsoft wants consumers not to purchase software but to buy into Microsoft's vision of software as an Internet-based service. Larry Rapagnani, assistant IT provost at the University of Notre Dame, said the new agreements make alternative software such as Linux and Sun Microsystems' Star Office more attractive to schools and departments needing to cut costs. (Chronicle of Higher Education Online, 9 July 2001)

Software Bugs

Writing a large software program is a non trivial task.
  • There is the problem of properly expressing the solution to the problem (that the program is supposed to provide).
  • There is the problem of interfacing the part of the program actually written by the programmer with other parts (library procedures or otherwise) not written by the programmer herself.
  • And then there is the sheer size of the program, thousands or perhaps millions of lines of program code, any one of which may contain a typo, or logical flaw.

Software vendors are also very anxious to get their product to market before competitors. They may not take sufficient time to check the newest "improvements" in their new version. So it is almost certain that a large program will contain faults or bugs.

Windows 2000 was rumored to have over 65,000 known "defects" at the time of its release! And Windows XP, the newer, better Windows 2000 also has problems!

SECURITY FLAW COMPROMISES WINDOWS XP
Windows XP contains several security flaws that could further stymie sales for the new system, which has sold significantly less than previous Windows releases despite being billed as the best version yet. Hackers can remotely commandeer the target computer, crash it, redirect it to a Web site, or even use it in a denial-of-service attack. The flaws involve the "universal plug and play" feature that connects to other devices via the Internet. Windows Millennium Edition and Windows 98 also share the flaw when loaded with special Windows XP compatibility software. Microsoft and security consultants from eEye, the company who discovered the flaws, have released patches, which are now available on the Microsoft Web site. (Washington Post, 21 December 2001)

Image if your brand new car had 65,000 known flaws! Would you even buy such an automobile? (How do you feel about Ford Explorers with Firestone tires?)

Some of the flaws are related to security. Newer windows operating systems allow remote control of the computer, presumably so that a helpdesk or system administrator could fixes problems without having to be right at the computer. But that capability also might allow a hacker to remotely control your system. Security holes are bugs that allow the possible control by a hacker.

Microsoft has often been accussed of being lax on security, claiming that it's customers have asked for more interoperability, not security. (Those 2, security and interoperability are often in conflict with each other.) In January of 2002, Bill Gates changed Microsoft's goals, making security a priority. However, flaws still remain. See the announcement: http://news.com.com/2100-1001-960639.html

How Much Do Those Bugs Cost?

STUDY PUTS A NUMBER TO LOSSES FROM BUGGY SOFTWARE
A new study from the National Institute of Standards and Technology (NIST) says that the U.S. economy loses almost $60 billion annually as a result of buggy software. According to the study, better testing could eliminate about one third of that loss, but much of the rest will remain. The study addressed the problem as it affects three major industries, automotive, aerospace, and financial services, and extrapolated those results to the nation as a whole. Authors of the study did not present specific actions to resolve the problem, but they did suggest that current methods for testing software are "fairly primitive" and that significant improvements could be made in that area. ComputerWorld, 25 June 2002 http://www.idg.net/ic_878966_1794_9-10000.html

Only the software industry gets away with this--consumers just assume that software will have bugs.

Here is a joke that surmmarizes the feeling about software:

    An electrical engineer, a mechanical engineer, and a software engineer all share a rented car from the airport. Driving along, they come to a red light and the car dies and won't restart.

    The mechanical engineer says, "I bet it's a mechanical problem like a stuck fuel pump; if I had tools, I bet I could fix it."

    The electrical engineer says, "I bet it's a electrical problem like the ignition; if I had tools, I bet I could fix it."

    And they both look over at the software engineer who had been silent. The software engineer says, "How about we all get out of the car and then get back in and then try it again?" (I.e., reboot it!)

Despite the fact that everyone knows that software has bugs (for whatever reasons), software vendors are not forthright with customers about bugs, presumably due to liability issues. As well as restrict what you can do with the software you bought, the license also has disclaimers as to the vendors liabilty due to bugs.

It may seem easier to fix a software bug than to fix a broken toaster; after all, the vendor just has to type in the correct program code and recompile. As usual there are issues.

  • First, and foremost, the person fixing the bug has to understand the program well enough to know how it is failing and how to fix it.
  • Thus, a bug fix has a relatively high likelihood of creating a new bug, something like 10%.
  • Each time a bug is "fixed" the resulting software is essentially a new version, different from previous ones, though perhaps only in minor ways. However, it also may have new and different bugs. Tracking all these different potential versions is a logistic nightmare for the vendor. So, instead, the vendor saves up all the bug fixes it has created in incorporates them all into a single software upgrade.
  • The software vendors periodically create new releases of a product that have both enhancements and bug fixes. But these releases come out only once or twice a year. Not much help if you can't get your payroll to work due to a software bug.
  • Sometimes vendors will incorporate an important bug fix into the enhanced version of a product, or related product, without really announcing the fact that bug fix is included. This procedure is called slip-streaming, and is used presumably to avoid legal liability for the bug in the first place.
SOFTWARE MAKERS AND BUYERS SHOULD CHAT
Flaws in software could be minimized, if not eliminated, if consumers would communicate with software makers and refuse to tolerate unreliable products, says author Mark Minasi. Software vendors compete with one another by adding new features and more power to their products at the expense of reliability, Minasi argues in his most recent book, "The Software Conspiracy: Why Software Companies Put Out Faulty Products, How They Can Hurt You, and What You Can Do About It." U.S. consumers spend over 65 million minutes a year on tech support phone lines, Minasi notes. In addition, although consumers now trust software makers less than used-car dealers, according to the Better Business Bureau, Minasi says consumers are more tolerant of shoddy software than any other flawed product. (USA Today 12/01/99)
Legislators and other politicians, hearing consumer complaints about the computer and software industry practices, tried to fix the problem with legislation: the UNIFORM COMPUTER INFORMATION TRANSACTIONS ACT.

However, the sofware industry loaded the commitees working the the proposed laws with their own members, rather than consumer advocates!

GROUP APPROVES CONTROVERSIAL SOFTWARE LAW
The National Conference of Commissioners on Uniform State Laws (NCCUSL) voted Thursday in favor of the controversial UCITA proposal that would create common licensing rules for software and other IT transactions. The vote does not make UCITA law, but experts say that most state legislatures adopt laws recommended by the organization. Critics say UCITA would rob IT companies and other software customers of their rights and leave them at the whim of software vendors. The law deregulates product licensing and addresses software, multimedia interactive products, data and databases, and the Internet and online information. It also contains provisions to allow vendors to shut down software remotely if they suspect a violation of the licensing terms, make shrink-wrapped licensing terms enforceable even though the buyer will not see the license until after the software is purchased, ban reverse engineering, and allow vendors to disclaim warranties. (InfoWorld Electric 07/29/99)

The complete text of the UCITA law can be found at: http://www.law.upenn.edu/bll/ulc/ucita/ucita200.htm

More information can be found at: www.infoworld.com/ucita.


Terms to Know

actual argument copy protected indenting print statements
address creeping featurism index program flow
an infinite loop curley brackets infinite recursion properties
API curley brackets initialize record
argument database int recursion
array Date object integers recursive function
array index debugger intellectual property remarks
assignment statement debugging interfacing reverse engineering
attributes declare iteration sample
backup copy dongles library scope
base 2 elif license security
binary executable local shrink wrapped
block execute logical expression single stepping
block expression logical if slip-streaming
block device factorial long software piracy
break point fed back loop software upgrade
bug float loop body source code
bytes floating point loop counter standard
call a function flow of control machine language statements
called for loop methods strings
caller formal argument name style
character device format named constant subroutine
commented out function definition neural networks syntax
comments garbage in, garbage out object file type
compiler global variables Object Oriented UCITA law
compiling grammar object program upgrades
concatenated hacker objects variables
conditional hard disk operating system version
constants high level language operators while loop
continue if patented

WML
©opyright 2000-2004 Mark R. Wallen
Last updated: Sun Sep 19 12:20:44 2004