15 July 00Bentley: FYI1 Truth, Beauty and Engineering: What I'd Like My CS Freshman Kid to Learn...
-
Upload
markus-rolling -
Category
Documents
-
view
213 -
download
1
Transcript of 15 July 00Bentley: FYI1 Truth, Beauty and Engineering: What I'd Like My CS Freshman Kid to Learn...
15 July 00 Bentley: FYI 1Bentley: FYI
Truth, Beauty and Engineering:What I'd Like My CS Freshman Kidto Learn Next Year
Jon BentleyBell Labs
www.programmingpearls.com/fyi.html
15 July 00 Bentley: FYI 2Bentley: FYI
ContextMain 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 00 Bentley: FYI 3Bentley: FYI
OutlineEngineering
Tricks of the Trade
Eyes Open to the World
Beauty
Elegance
Communication
Truth
History
Ethics
15 July 00 Bentley: FYI 4Bentley: FYI
A QuizA 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 00 Bentley: FYI 5Bentley: FYI
The Back of the EnvelopeImportant 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 00 Bentley: FYI 6Bentley: FYI
Problem DefinitionFor 72 psychological subjects, randomly
permuteorder of experimenters (1, 2, 3)
stress conditions (High, Medium, Low)
Desired results 1 3L 2M 1H2 3H 1M 2L3 1L 2H 3M4 1M 2L 3H …
How to generate?
15 July 00 Bentley: FYI 7Bentley: FYI
An Elegant Solution
Educational GoalsKnowledge about how to solve a problem
Wisdom about what problem to solve
123
213
132LMH
MLH
LHM
15 July 00 Bentley: FYI 8Bentley: FYI
Debugging TalesA banking system “quits” on international
data.
The programmer can’t log in standing up.
A program works once twice.
15 July 00 Bentley: FYI 9Bentley: FYI
Engineering Tricks of the TradeBack of the Envelope Estimates
Problem Definition
Debugging
Tradeoffs, Symmetry
Components, Prototypes
Simplicity, Elegance
programmingpearls.com/tricks.html
15 July 00 Bentley: FYI 10Bentley: FYI
Engineer’s EyesHow 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 00 Bentley: FYI 11Bentley: FYI
Real-World SoftwareYour Watch
AutomobilesEntry systems: Keys, combinations, remote
Antilock brakes, carburetors, transmissions, …
Memory for user preferences
GPS, maps, radar, HUDs, …
Count the processors! Networks?
Entry SystemsDorms, cars, arenas, turnpikes, hotel rooms, …
Sound, Pictures, Motion Pictures
15 July 00 Bentley: FYI 12Bentley: FYI
Some Wonderful BooksAdams, 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 00 Bentley: FYIBentley: FYI
OutlineEngineering
Beauty
Elegance
Communication
Truth
15 July 00 Bentley: FYIBentley: FYI
EleganceGordon Bell: The cheapest, fastest and most
reliable components are those that aren’t 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 00 Bentley: 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<int> & counts, int total);void Count(istream & input, tvector<int> & 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<int> charCounts(CHAR_MAX+1,0); // all initialized to 0 Count(input,charCounts,totalAlph); Print(charCounts,totalAlph); return 0;}
void Count(istream & input, tvector<int> & 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<int> & 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 00 Bentley: FYI
A Longer ProgramRoberts, The Art and Science of C (A-W, 1995)
3 1/2 pages
Functions: main, CountLetters, CountLettersInString, RecordLetter, DisplayLetterCounts, LetterIndex, ClearIntegerArray
15 July 00 Bentley: FYI
Kernighan and Pike’s Programunsigned 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 00 Bentley: FYI
Elegant Sortsvoid 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 00 Bentley: FYI
Strunk and White’s Rule 17Vigorous 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 00 Bentley: FYI
Code in Programming PearlsSorting unique integersVector rotationAnagramsMaximum-sum subvectorBinary searchInsertion sort, quicksort, heapsortRandom samplesHeapsLongest duplicated substringsMarkov text
15 July 00 Bentley: FYI
CommunicationEssential skill for all students
Audience: Technical and nontechnical
Writing and speaking
How to teach it?Example: Lectures, handouts, web pages, …
PracticeDocumentation
Essays
Term papers
Oral presentations
15 July 00 Bentley: FYIBentley: FYI
OutlineEngineering
Beauty
Truth
History
Ethics
15 July 00 Bentley: FYI
CachingIdeally 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 00 Bentley: FYI
Kinds of HistoryThe Field
The Human SideThe 1990 house
Organizational1965: Triangle Universities Computation Center
PersonalMy 32K computers: 1969, 1973, 1981, 1999
ArtifactsOld computers, disks
Strong’s Exhaustive Concordance
15 July 00 Bentley: FYI
A Victorian Search EngineStrong’s Exhaustive Concordance
Sample Entrythankful 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 AltaVistahttp://gatekeeper.dec.com/pub/DEC/SRC/publications
/sites/talk/AltaVista_Technical-abs.html
A Fun Programming Exercise
15 July 00 Bentley: FYI
History in Pearls1950’s
Brooks’s Kentucky state income tax
1960’sAnagrams; fast binary search
1970’sSuffix arrays; Maximum-sum subarray
Lesk’s touch-tone phone directory
Kernighan’s symmetric matrices
1980’sData communication within Lockheed
15 July 00 Bentley: FYI
EthicsFirst-year Students
When may they copy text and code?Why? Vary the rules!
Social Issues: Napster? Ellison’s spies?
Older StudentsGrowing a spelling list
Snooping through files; reading mail
College privacy: prox cards, web histories, ...
Real ProblemsEthical questions that made me lose sleep
15 July 00 Bentley: FYI
A Whole WorldCracking DVDs
How do DVDs work?Mathematics, science, technology
Back of the EnvelopeBandwidth for sharing a DVD?
History of movies and protection
Ethics
Concise Text and Code