# 15 July 00Bentley: FYI1 Truth, Beauty and Engineering: What I'd Like My CS Freshman Kid to Learn Next Year Jon Bentley Bell Labs www.programmingpearls.com/fyi.html.

## Presentation on theme: "15 July 00Bentley: FYI1 Truth, Beauty and Engineering: What I'd Like My CS Freshman Kid to Learn Next Year Jon Bentley Bell Labs www.programmingpearls.com/fyi.html."— Presentation transcript:

15 July 00Bentley: FYI1 Truth, Beauty and Engineering: What I'd Like My CS Freshman Kid to Learn Next Year Jon Bentley Bell Labs www.programmingpearls.com/fyi.html

15 July 00Bentley: FYI2 Context Main Course: Curriculum Design What content? Which courses? Which languages? This Talk: Desserts and Spices Little add-ons for first-year courses (Weave-throughs?)

15 July 00Bentley: FYI3 Outline Engineering Tricks of the Trade Eyes Open to the World Beauty Elegance Communication Truth History Ethics

15 July 00Bentley: FYI4 A Quiz A TV Commercial U.S. college students eat 60 million slices of pizza per month. Is this reasonable? How much does a one-hour lecture cost? A program sorts one million integers in one second. How long to sort two million? How long will an exhaustive search take to solve a TSP of size 10? 20? 30? How much do calculus texts cost?

15 July 00Bentley: FYI5 The Back of the Envelope Important for engineers and citizens How to teach quick calculations? Probably not a lecture (nor even half an hour) Woven throughout an education What to teach Tabular computations Rules of thumb Quick checks Safety factors

15 July 00Bentley: FYI6 Problem Definition For 72 psychological subjects, randomly permute order of experimenters (1, 2, 3) stress conditions (High, Medium, Low) Desired results 1 3L 2M 1H 2 3H 1M 2L 3 1L 2H 3M 4 1M 2L 3H … How to generate?

15 July 00Bentley: FYI7 An Elegant Solution Educational Goals Knowledge about how to solve a problem Wisdom about what problem to solve 123 213 132 LMH MLH LHM

15 July 00Bentley: FYI8 Debugging Tales A banking system quits on international data. The programmer cant log in standing up. A program works once twice.

15 July 00Bentley: FYI9 Engineering Tricks of the Trade Back of the Envelope Estimates Problem Definition Debugging Tradeoffs, Symmetry Components, Prototypes Simplicity, Elegance programmingpearls.com/tricks.html

15 July 00Bentley: FYI10Bentley: FYI Engineers Eyes How does that CD player work? Random play: algorithm? RNG? How much music? Compared to MP3? Error correction? Scratches? Bounces? Textual description of content? Remote control? Store state at power off? Representation? Navigation over a long spiral?

15 July 00Bentley: FYI11Bentley: FYI Real-World Software Your Watch Automobiles Entry systems: Keys, combinations, remote Antilock brakes, carburetors, transmissions, … Memory for user preferences GPS, maps, radar, HUDs, … Count the processors! Networks? Entry Systems Dorms, cars, arenas, turnpikes, hotel rooms, … Sound, Pictures, Motion Pictures

15 July 00Bentley: FYI12Bentley: FYI Some Wonderful Books Adams, Conceptual Blockbusting Petroski, To Engineer Is Human Polya, How To Solve It Strunk and White, Elements of Style Huff, How to Lie with Statistics Fisher and Ury, Getting to Yes

15 July 00Bentley: FYI Outline Engineering Beauty Elegance Communication Truth

15 July 00Bentley: FYI Elegance Gordon Bell: The cheapest, fastest and most reliable components are those that arent there. Antoine de Saint Exupéry: A designer knows he has arrived at perfection not when there is no longer anything to add, but when there is no longer anything to take away. Albert Einstein: Everything should be made as simple as possible, but no simpler.

15 July 00Bentley: FYI A C++ Program // count # occurrences of all characters in a file // written: 8/5/94, Owen Astrachan, modified 5/1/99 void Print(const tvector & counts, int total); void Count(istream & input, tvector & counts, int & total); int main() { int totalAlph = 0; string filename = PromptString("enter name of input file: "); ifstream input(filename.c_str()); if (input.fail() ) { cout << "could not open file " << filename << endl; exit(1); } tvector charCounts(CHAR_MAX+1,0); // all initialized to 0 Count(input,charCounts,totalAlph); Print(charCounts,totalAlph); return 0; } void Count(istream & input, tvector & counts, int & total) // precondition: input open for reading // counts[k] == 0, 0 <= k < CHAR_MAX // postcondition: counts[k] = # occurrences of character k // total = # alphabetic characters { char ch; while (input.get(ch)) // read a character { if (isalpha(ch)) // is alphabetic (a-z)? { total++; } ch = tolower(ch); // convert to lower case counts[ch]++; // count all characters } void Print(const tvector & counts, int total) // precondition: total = total of all entries in counts['a']..counts['z'] // postcondition: all values of counts from 'a' to 'z' printed { const int MIDALPH = 13; cout.setf(ios::fixed); // print 1 decimal place cout.precision(1); char k; for(k = 'a'; k <= 'm'; k++) { cout << k << setw(7) << counts[k] << " "; cout << setw(4) << 100 * double(counts[k])/total << "% \t\t"; cout << char(k+MIDALPH) << setw(7) << counts[k+MIDALPH] << " "; cout << setw(4) << 100 * double(counts[k+MIDALPH])/total << "%" << endl; }

15 July 00Bentley: FYI A Longer Program Roberts, The Art and Science of C ( A-W, 1995 ) 3 1/2 pages Functions: main, CountLetters, CountLettersInString, RecordLetter, DisplayLetterCounts, LetterIndex, ClearIntegerArray

15 July 00Bentley: FYI Kernighan and Pikes Program unsigned long count[UCHAR_MAX+1]; /* freq main: display byte frequency counts */ int main(void) { int c; while ((c = getchar()) != EOF) count[c]++; for (c = 0; c <= UCHAR_MAX; c++) if (count[c] != 0) printf("%.2x %c %lu\n", c, isprint(c) ? c : '-', count[c]); return 0; }

15 July 00Bentley: FYI Elegant Sorts void isort(int *a, unsigned n) { int i, j; for (i = 1; i < n; i++) for (j = i; j > 0 && a[j-1] > a[j]; j--) swap(j, j-1, a); } void qsort(int *a, unsigned n) { int i, j; if (n <= 1) return; for (i = 1, j = 0; i < n; i++) if (a[i] < a[0]) swap(++j, i, a); swap(0, j, a); qsort(a, j); qsort(a+j+1, n-j-1); }

15 July 00Bentley: FYI Strunk and Whites Rule 17 Vigorous writing is concise. A sentence should contain no unnecessary words, a paragraph no unnecessary sentences, for the same reason that a drawing should have no unnecessary lines and a machine no unnecessary parts. This requires not that the writer make all sentences short, or avoid all detail and treat subjects only in outline, but that every word tell.

15 July 00Bentley: FYI Code in Programming Pearls Sorting unique integers Vector rotation Anagrams Maximum-sum subvector Binary search Insertion sort, quicksort, heapsort Random samples Heaps Longest duplicated substrings Markov text

15 July 00Bentley: FYI Communication Essential skill for all students Audience: Technical and nontechnical Writing and speaking How to teach it? Example: Lectures, handouts, web pages, … Practice Documentation Essays Term papers Oral presentations

15 July 00Bentley: FYI Outline Engineering Beauty Truth History Ethics

15 July 00Bentley: FYI Caching Ideally one would desire an indefinitely large memory capacity such that any particular [word] would be immediately available.… It does not seem possible to achieve such a capacity. We are therefore forced to recognize the possibility of constructing a hierarchy of memories, each of which has greater capacity than the preceding but which is less quickly accessible. Preliminary discussion of the logical design of an electronic computing instrument, Burks, Goldstine, von Neumann, 1946

15 July 00Bentley: FYI Kinds of History The Field The Human Side The 1990 house Organizational 1965: Triangle Universities Computation Center Personal My 32K computers: 1969, 1973, 1981, 1999 Artifacts Old computers, disks Strongs Exhaustive Concordance

15 July 00Bentley: FYI A Victorian Search Engine Strongs Exhaustive Concordance Sample Entry thankful See also UNTHANKFUL Ps 100:4 be t unto him, and bless his name. Ro 1:21 him not as God, neither were t; Col 3:15 called in one body; and be ye t. Compare to AltaVista http://gatekeeper.dec.com/pub/DEC/SRC/publications /sites/talk/AltaVista_Technical-abs.html A Fun Programming Exercise

15 July 00Bentley: FYI History in Pearls 1950s Brookss Kentucky state income tax 1960s Anagrams; fast binary search 1970s Suffix arrays; Maximum-sum subarray Lesks touch-tone phone directory Kernighans symmetric matrices 1980s Data communication within Lockheed

15 July 00Bentley: FYI Ethics First-year Students When may they copy text and code? Why? Vary the rules! Social Issues: Napster? Ellisons spies? Older Students Growing a spelling list Snooping through files; reading mail College privacy: prox cards, web histories,... Real Problems Ethical questions that made me lose sleep

15 July 00Bentley: FYI A Whole World Cracking DVDs How do DVDs work? Mathematics, science, technology Back of the Envelope Bandwidth for sharing a DVD? History of movies and protection Ethics Concise Text and Code

Download ppt "15 July 00Bentley: FYI1 Truth, Beauty and Engineering: What I'd Like My CS Freshman Kid to Learn Next Year Jon Bentley Bell Labs www.programmingpearls.com/fyi.html."

Similar presentations