Wake up with CPS 006 Program Design and Methodology I Computer Science and Programming What Is Computer Science? Computer Scienc
Total Page:16
File Type:pdf, Size:1020Kb
Computer Science and Programming z Computer Science is more than programming ¾ The discipline is called informatics in many countries ¾ Elements of both science and engineering • Scientists build to learn, engineers learn to build Wake up with CPS 006 – Fred Brooks Program Design and Methodology I ¾ Elements of mathematics, physics, cognitive science, music, art, and many other fields z Computer Science is a young discipline Jeff Forbes ¾ Fiftieth anniversary in 1997, but closer to forty years of research and development ¾ First graduate program at CMU (then Carnegie Tech) in http://www.cs.duke.edu/courses/cps006/current 1965 http://www.cs.duke.edu/csed/tapestry z To some programming is an art, to others a science, to others an engineering discipline A Computer Science Tapestry 1.1 A Computer Science Tapestry 1.2 What is Computer Science? Computer Science What is it that distinguishes it from the z Artificial Intelligence thinking machines separate subjects with which it is related? z Scientific Computing weather, cars, heart, modelling What is the linking thread which gathers these z Theoretical CS analyze algorithms, models disparate branches into a single discipline? My answer to these questions is simple --- it is z Computational Geometry theory of animation, 3-D models the art of programming a computer. It is the art z Architecture hardware-software interface of designing efficient and elegant methods of z Software Engineering engineering, science getting a computer to solve problems, z Operating Systems the soul of the machine theoretical or practical, small or large, simple z Graphics from Windows to Hollywood or complex. z Many other subdisciplines C.A.R. (Tony)Hoare A Computer Science Tapestry 1.3 A Computer Science Tapestry 1.4 Stories Algorithms as Cornerstone of CS z Who is Shawn Fanning and what did he do (19 years old)? z Step-by-step process that solves a problem ¾ more precise than a recipe z Who is Marc Andreessen and what did he do (21 years old)? ¾ eventually stops with an answer ¾ general process rather than specific to a computer or to a z Who is Claude Shannon and what did he do (21 years old)? programming language z Searching: for phone number of G. Samsa, whose number is 929-9338, or for the person whose number is 489-6569 z Who is Linus Torvalds and what did he do (21 years old)? ¾ Are these searches different? z If the phone book has 8 million numbers in it (why are there z Who is Dmitry Sklyarov and what did he do (26 years old)? only 7.9 million phone numbers with area code 212?) ¾ How many queries to find phone number of G. Samsa? z Who is Tim Berners-Lee and what did he do (35 years old)? ¾ How many queries to find person with number 929-9338 ¾ What about IP addresses? z Who is Owen Astrachan and what did he do (44 years old)? A Computer Science Tapestry 1.5 A Computer Science Tapestry 1.6 Search, Efficiency, Complexity Sorting Experiment: why do we sort? z Think of a number between 1 and 1,000 z Groups of four people are given a bag containing strips of paper ¾ respond high, low, correct, how many guesses needed? ¾ on each piece of paper is an 8-15 letter English word ¾ create a sorted list of all the words in the bag z Look up a word in a dictionary ¾ there are 100 words in a bag ¾ Finding the page/word, how many words do you look at? z What issues arise in developing an algorithm for this sort? z Looking up a phone number in the Manhattan, NY directory ¾ ¾ How many names are examined? ¾ z Can you write a description of an algorithm for others to z How many times can 1,024 be cut in half? follow? ¾ ¾ 210 = 1,024, 220 = 1,048,576 Do you need a 1-800 support line for your algorithm? ¾ Are you confident your algorithm works? A Computer Science Tapestry 1.7 A Computer Science Tapestry 1.8 Themes and Concepts of CS Theory, Language, Architecture z Theory z We can prove that in the worst case quicksort is bad ¾ properties of algorithms, how fast, how much memory ¾ doesn’t matter what machine it’s executed on ¾ average case, worst case: sorting cards, words, exams ¾ doesn’t matter what language it’s coded in ¾ ¾ provable properties, in a mathematical sense unlikely in practice, but worst case always possible z Solutions? Develop an algorithm that works as fast as z Language quicksort in the average case, but has good worst case ¾ programming languages: C++, Java, C, Perl, Fortran, Lisp, performance Scheme, Visual BASIC,more? ¾ quicksort invented in 1960 ¾ Assembly language, machine language, ¾ introsort (for introspective sort) invented in 1996 ¾ Natural language such as English z Sometimes live with worst case being bad z Architecture ¾ bad for sorting isn’t bad for other algorithms, needs to be ¾ Main memory, cache memory, disk, USB, SCSI, ... quantified using notation studied as part of the theory of algorithms ¾ pipeline, multi-processor A Computer Science Tapestry 1.9 A Computer Science Tapestry 1.10 Abstraction, Complexity, Models Alan Turing (1912--1954) z What is an integer? z Instrumental in breaking codes during WW II ¾ In mathematics we can define integers easily, infinite set of numbers and operations on the numbers (e.g.,+, -, *, /) z Developed mathematical model of a computer called a Turing {…-3, -2, -1, 0, 1, 2, 3, …} Machine (before computers) ¾ In programming, finite memory of computer imposes a ¾ solves same problems as a limit on the magnitude of integers. Pentium III (more slowly) • Possible to program with effectively infinite integers (as z Church-Turing thesis large as computation and memory permit) at the expense of ¾ All “computers” can solve the efficiency same problems • At some point addition is implemented with hardware, but z Showed there are problems that that’s not a concern to those writing software (or is it?) cannot be solved by a computer • C++ doesn’t require specific size for integers, Java does z Both a hero and a scientist/ z Floating-point numbers have an IEEE standard, required mathematician, but lived in an era because it’s more expensive to do arithmetic with 3.14159 than hard for gay people with 2 A Computer Science Tapestry 1.11 A Computer Science Tapestry 1.12 Complexity: What’s hard, what’s easy? C.A.R. (Tony) Hoare (b. 1934) z What is a prime number? z 671998030559713968361666935767 z Won Turing award in 1980 is not prime, I can prove it but I ¾ 2, 3, 5, 7, 11, 13, … z Invented quicksort, but didn’t can’t give you the factors. ¾ Largest prime? see how simple it was to program recursively z Finding factors is “hard”, z 48112959837082048697 z Developed mechanism and determining primality is “easy” z 671998030559713968361666935769 theory for concurrent ¾ What does this mean? processing z How do we determine if these numbers are prime? ¾ Why do we care? z In Turing Award speech used “Emporer’s New Clothes” as ¾ Test 3, 5, 7, … metaphor for current fads in z Encryption depends on this ¾ If we can test one million programming numbers a second, how relationship, without encryption long to check a 100 digit #? and secure web transactions where would we be? “Beginning students don’t know how to do top-down design z Why do we care? because they don’t know which end is up” A Computer Science Tapestry 1.13 A Computer Science Tapestry 1.14 Creating a Program From High- to Low-level languages z Specify the problem z C++ is a multi-purpose language ¾ remove ambiguities ¾ Scheme - functional language ¾ identify constraints ¾ Java, Smalltalk- everything is object oriented z Develop algorithms, design z Compilers translate C++ to a machine-specific executable classes, design software architecture program z Implement program ¾ The compiler is a program, input is C++, output is an ¾ revisit design executable ¾ test, code, debug ¾ What language is the compiler written in? ¾ revisit design ¾ In theory C++ source code works on any machine given a z Documentation, testing, compiler for the machine maintenance of program z C++ and other programming language are more syntactically rigid than English and other natural languages z From ideas to electrons A Computer Science Tapestry 1.15 A Computer Science Tapestry 1.16 Levels of Programming Language Alternatives to compilation z Machine specific assembly language, Sparc on left, Pentium z Some languages are interpreted, Scheme and Java are examples on right, both generated from the same C++ ¾ like simultaneous translation instead of translation of written document. The same word may be translated many main: main: times save %sp,-128,%sp pushl %ebp ¾ The interpreter is a program that translates one part of a mov 7,%o0 movl %esp,%ebp source code at a time st %o0,[%fp-20] subl $12,%esp mov 12,%o0 movl $7,-4(%ebp) • The interpreter is machine specific, written in some st %o0,[%fp-24] movl $12,-8(%ebp) programming language ld [%fp-20],%o0 movl -4(%ebp),%eax z JVM, the Java Virtual Machine ld [%fp-24],%o1 imull -8(%ebp),%eax ¾ Like a PC or Mac but machine is virtual, written in software call .umul,0 movl %eax,-12(%ebp) ¾ nop xorl %eax,%eax Executes Java byte codes which are created from Java source st %o0,[%fp-28] jmp .L1 • Like assembly language: between source code and executable mov 0,%i0 .align 4 ¾ JVM must be written for each architecture, e.g., Linux, b .LL1 xorl %eax,%eax Windows, Mac, BeOS, ... nop jmp .L1 A Computer Science Tapestry 1.17 A Computer Science Tapestry 1.18 What is a computer? Why is programming fun? z Turing machine: invented by Alan Turing in 1936 as a Mainframe, PC,laptop, What delights may its practitioner expect as a reward? theoretical model supercomputer First is the sheer joy of making things Second is the pleasure of making things that are useful infinite tape, moving tape-reader 0 1 Third is the fascination of fashioning complex puzzle-like objects of interlocking moving parts Fourth is the joy of always learning A computer is a computer, is a computer, Church-Turing Finally, there is the delight of working in such a tractable medium.