next up previous
Next: Performance Up: Lecture Notes for CS210 Previous: Lecture Notes for CS210

Abstraction

Computers have been growing exponentially in power since they were invented - this is commonly known as Moore's law. Within our lifetimes, the power of a personal computer as increased at least a thousand fold. With this increased computing power, we can put computers to work on larger and more complicated tasks. However, as the complexity increases, we are forced to use more layers of abstraction to achieve our goals or face excessively large and incomprehensible programs.

Inside a computer, all data is represented as 0s and 1s (bits), or to be precise, the presence or absence of an electrical current. These bits are grouped together into words and most operations of a computer work with words instead of individual bits. For example, a computer might read a series of words using each as an individual instruction telling it what work to do. A word ``1000101010101'' might mean that two particular pieces of data should be added together. We add another layer of abstraction, assembly language, so that a programmer can write ``add A,B'' and have another program, an assembler, worry about the details of how the bits should be set. Assembly languages are usually architecture dependent since they depend on what kinds of instructions are understood - for example, not all computers have instructions for division.

The next layer of abstraction, the high-level programming languages, allows statements such as ``A + B'' and ``foreach $thing (@stuff) { do_something($thing); }''. C and C++ are examples of high-level languages (the second example is Perl). High-level languages are translated into assembly language by compilers, which are allowed significant leeway in there output. Instead of the fairly mechanical translation of an assembler, a compiler may choose its output and attempt to optimize it so that the output program is better in some way, perhaps in the number of instructions generated or in the time it takes to execute the output program. Like most layers of abstraction, high-level languages allow a programmer to forget about low level details and concentrate on the big picture. High-level languages are almost always machine-independent - given the appropriate compilers, one should be able to compile the same program for different machines. This allows a programmer to forget about what instructions a machine supports (they may differ if the program is going to run on different machines) and focus more on what the program is doing rather than on how it is being done. Some high level languages such as Java even provide facilities such as garbage collection so that the programmer never needs to free memory - as soon as there are no more references to it, it is automatically freed. Additionally, the abstraction provided allows the same programs to be written in a much shorter fashion making them easier to write and understand.

Another feature that arose with high-level languages was the use of subroutine libraries to reuse parts of program. Common functions such as printing numbers often are provided as part of the default library of a high-level language and it is usually possible to write one's own library. Given these libraries, one may use the functions with reasonable expectations of their behavior (i.e. ``printf("%d", 5)'' will print out the number five) without any knowledge of how the functions are implemented. In fact, these libraries may even be updated (e.g. a bug fix) so that a program gains the benefits of a new library implementation as soon as it is recompiled without any changes to the program source.

Another extension of this idea was to provide a program (or set of programs), the operating system, to manage running programs and provide some hardware abstraction. The operating system provides a consistent interface to hardware and convenient abstractions such as files and deals with starting and stopping other programs. Details such as the type of hard drive used are hidden - instead, a more convenient abstraction, the file system, is presented. Similarly, details such as scheduling (if applicable) are handled automatically so a well written program need not worry whether there are other programs running at the same time.


next up previous
Next: Performance Up: Lecture Notes for CS210 Previous: Lecture Notes for CS210
Jeffrey Considine 2001-05-01