Section 1.1. What is Computer Science About?


[Page 2 (continued)]

1.1. What is Computer Science About?

Computer science is the study of process: how we do things, how we specify what we do, how we specify what the stuff is that you're processing. But that's a pretty dry definition. Let's try a metaphorical one.

Computer Science Idea: Computer Science is the Study of Recipes (Programs)

They're a special kind of recipeone that can be executed by a computational device, but that point is only of importance to computer scientists. The important point overall is that a computer science program defines exactly what's to be done as shown in the recipe in (Figure 1.1).


If you're a biologist who wants to describe how migration works or how DNA replicates, or if you're a chemist who wants to explain how an equilibrium is reached in a reaction, or if you're a factory manager who wants to define a machine-and-belt layout and even test how it works before physically moving heavy things into position, then being able to write a program that specifies exactly what happens, in terms that can be completely defined and understood, is very useful. This exactness is part of why computers have radically changed so much of how science is done and understood.


[Page 3]

It may sound funny to call programs or algorithms a recipe, but the analogy goes a long way. Much of what computer scientists study can be defined in terms of recipes:

  • Some computer scientists study how recipes are written: Are there better or worse ways of doing something? If you've ever had to separate whites from yolks in eggs, you know that knowing the right way to do it makes a world of difference. Computer science theoreticians worry about the fastest and shortest recipes, and the ones that take up the least amount of space (you can think about it as counter spacethe analogy works). How a recipe works, completely apart from how it's written, is called the study of algorithms. Software engineers worry about how large groups can put together recipes that still work. (The recipe for some programs, like the one that keeps track of Visa/MasterCard records, has literally millions of steps!)

  • Other computer scientists study the units used in recipes. Does it matter whether a recipe uses metric or English measurements? The recipe may work in either case, but if you have to read the recipe and you don't know what a pound or a cup is, the recipe is a lot less understandable to you. There are also units that make sense for some tasks and not others, but if you can fit the units to the tasks well, you can explain yourself more easily and get things done fasterand avoid errors. Ever wonder why ships at sea measure their speed in knots? Why not use things like meters per second? There are places, like at sea, where more common terms aren't appropriate or don't work as well. The study of computer science units is referred to as data structures. Computer scientists who study ways of keeping track of lots of data in lots of different kinds of units are studying databases.


  • [Page 4]
  • Can recipes be written for anything? Are there some recipes that can't be written? Computer scientists actually do know that there are recipes that can't be written. For example, you can't write a recipe that can absolutely tell, for any other recipe, if the other recipe will actually work. How about intelligence? Can we write a recipe that, when a computer followed it, the computer would actually be thinking (and how would you tell if you got it right)? Computer scientists in theory, intelligent systems, artificial intelligence, and systems worry about things like this.

  • There are even computer scientists who worry about whether people like what the recipes produce, like the restaurant critics for the newspaper. Some of these are humancomputer interface specialists who worry about whether people like how the recipes work (those "recipes" that produce an interface that people use, like windows, buttons, scrollbars, and other elements of what we think about as a running program).

  • Just as some chefs specialize in certain kinds of recipes, like crepes or barbecue, computer scientists also specialize in special kinds of recipes. Computer scientists who work in graphics are mostly concerned with recipes that produce pictures, animations, and even movies. Computer scientists who work in computer music are mostly concerned with recipes that produce sounds (often melodic ones, but not always).

  • Still other computer scientists study the emergent properties of recipes. Think about the World Wide Web. It's really a collection of millions of recipes (programs) talking to one another. Why would one section of the Web get slower at some point? It's a phenomena that emerges from these millions of programs, certainly not something that was planned. That's something that networking computer scientists study. What's really amazing is that these emergent properties (that things just start to happen when you have many, many recipes interacting at once) can also be used to explain non-computational things. For example, how ants forage for food or how termites make mounds can also be described as something that just happens when you have lots of little programs doing something simple and interacting.

The recipe metaphor also works on another level. Everyone knows that some things in a recipe can be changed without changing the result dramatically. You can always increase all the units by a multiplier (say, double) to make more. You can always add more garlic or oregano to the spaghetti sauce. But there are some things that you cannot change in a recipe. If the recipe calls for baking powder, you may not substitute baking soda. If you're supposed to boil the dumplings then saute' them, the reverse order will probably not work well (Figure 1.1).

Figure 1.1. A cooking recipethe order of the steps is important.
(This item is displayed on page 3 in the print version)

CHICKEN CACCIATORE

3 whole, boned chicken breasts

1 medium onion, chopped

1 tbsp chopped garlic

2 tbsp and later 1/4 c olive oil

1 1/2 c flour

1/4 c Lawry's seasoning salt

1 bell pepper, chopped (optional) any color

1 (28 oz) can chopped tomatoes

1 (15 oz) can tomato sauce

1 (6.5 oz) can mushrooms

1 (6 oz) can tomato paste

1/2 of (26 oz) jar of spaghetti sauce

3 tbsp Italian seasoning

1 tsp garlic powder (optional)

Cut up the chicken into pieces about 1 inch square. Saute the onion and garlic until the onion is translucent. Mix the flour and Lawry's salt. You want about 1:41:5 ratio of seasoning salt to flour and enough of the whole mixture to coat the chicken. Put the cut up chicken and seasoned flour in a bag, and shake to coat. Add the coated chicken to the onion and garlic. Stir frequently until browned.

You'll need to add oil to keep from sticking and burning; I sometimes add up to 1/4 cup of olive oil. Add the tomatoes, sauce, mushrooms, and paste. (And the optional peppers, too.) Stir well. Add the Italian seasoning. I like garlic, so I usually add the garlic powder, too. Stir well. Because of all the flour, the sauce can get too thick. I usually cut it with the spaghetti sauce, up to 1/2 jar. Simmer 2030 minutes.


Similarly, for software recipes (programs), there are usually things you can easily change: The actual names of things (though you should change names consistently), some of the constants (numbers that appear as plain old numbers, not as variables), and maybe even some of the data ranges (sections of the data) being manipulated. But the order of the commands to the computer, however, almost always has to stay exactly as stated. As we go on, you'll learn what can be changed safely, and what can't.


[Page 5]

Computer scientists specify their programs with programming languages (Figure 1.2). Different programming languages are used for different purposes. Some of them are wildly popular, like Java and Visual Basic. Others are more obscure, like Squeak and T. Others are designed to make computer science ideas very easy to learn, like Scheme or Python, but the fact that they're easy to learn doesn't always make them very popular nor the best choice for experts building larger or more complicated programs. It's a hard balance in teaching computer science to pick a language that is easy to learn and is popular and useful enough that students are motivated to learn it.

Figure 1.2. Comparing programming languages: A common simple programming task is to print the words "Hello, World!" to the screen.

Python/Jython def hello():   print "Hello World" Java public class HelloWorld {   public static void main(String[] args)   {     System.out.println( "Hello World!" );   } } C++ #include <iostream.h> main() {     cout << "Hello World!" << endl;     return 0; } Scheme  (define helloworld          (lambda ()                  (display "Hello World")                  (newline)))


Why don't computer scientists just use natural human languages, like English or Spanish? The problem is that natural languages evolved the way that they did to enhance communications between very smart beings, humans. As we'll go into more in the next section, computers are exceptionally dumb. They need a level of specificity that natural language isn't good at. Further, what we say to one another in natural communication is not exactly what you're saying in a computational recipe (program). When was the last time you told someone how a videogame like Doom or Quake or Super Mario Brothers worked in such minute detail that they could actually replicate the game (say, on paper)? English isn't good for that kind of task.


[Page 6]

There are so many different kinds of programming languages because there are so many different kinds of programs to write. Programs written in the programming language C tend to be very fast and efficient, but they also tend to be hard to read, hard to write, and require units that are more about computers than about bird migrations or DNA or whatever else you want to write your program about. The programming language Lisp (and its related languages like Scheme, T, and Common Lisp) is very flexible and is well suited to exploring how to write programs that have never been written before, but Lisp looks so strange compared to languages like C that many people avoid it and there are (natural consequence) few people who know it. If you want to hire a hundred programmers to work on your project, you're going to find it easier to find a hundred programmers who know a popular language than a less popular onebut that doesn't mean that the popular language is the best one for your task!

The programming language that we're using in this book is Java (http://java.sun.com for more information on Java). Java is a very popular programming language. Delta uses it to handle its web site (http://www.delta.com). NASA used it on the Mars Rover "Spirit" (http://www.sun.com/aboutsun/media/features/mars.html). It has been used in touchscreen kiosks for Super Bowl fans (http://java.sun.com/features/1998/01/superbowl.html).

Java is known for being object-oriented, platform neutral (runs on many computers and electronic devices), robust, and secure. An early drawback to Java was that programs written in Java often had a slower execution time than ones written in C or C++. However, current Java compilers and interpreters have substantially reduced this problem.

Let's make clear some of the terms that we'll be using in this book. A program is a description of a process in a particular programming language that achieves some result that is useful to someone. A program could be small (like one that implements a calculator), or could be huge (like the program that your bank uses to track all of its accounts). An algorithm (in contrast) is a description of a process apart from any programming language. The same algorithm might be implemented in many different languages in many different ways in many different programsbut it would all be the same process if we're talking about the same algorithm.

Computer Science Idea: Programs versus Algorithms

A program is written in a programming language and can be executed by a computer. An algorithm can be written in English and is a description of a process. Many programs can implement an algorithm in many different programming languages.




Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net