240 likes | 462 Views
CS50++. CS 51 & CSCI E-250 Spring 2013. Greg Morrisett. What’s 51 about?. Programming isn’t hard. Programming well is very hard. We want you to write code that is: Reliable, efficient, readable, testable, provable, maintainable … elegant ! Expand your problem-solving skills:
E N D
CS 51 & CSCI E-250Spring 2013 Greg Morrisett
What’s 51 about? Programming isn’t hard. Programming well is veryhard. We want you to write code that is: • Reliable, efficient, readable, testable, provable, maintainable… elegant! Expand your problem-solving skills: • Recognize problems & map them onto the right languages, abstractions, & algorithms.
What is this course about? Computer Science II: Abstraction & Design • How to engineer solutions to computational tasks. • Decompose goals into solvable sub-units. • Recognize and adapt existing solutions to new problems. • Recognize when problems are unsolvable. • Find and use the right tools for the job. • By “engineer”, we mean to produce good solutions. • Correct, reliable, & secure. • Efficient: time, space, power, money. • Scalable: adaptatable, decentralized. • Elegant!
Course Focus “Software Engineering in the Small” • Introduce new programming abstractions • e.g., closures, abstract & algebraic data types, polymorphism, modules, classes & inheritance, synchronization, events, etc. • increase your computational tool-box, stretch your thinking. • Introduce engineering design • e.g., coding style, interface design, efficiency concerns, testing. • models & analytic tools (e.g., big-O, evaluation models.) • learn to analyze, think, and express with precision.
Who should take this course? • CS concentrators & minors should: • knowledge & experience is crucial for upper-level, software-intensive courses (compilers, OS, networking, AI, graphics, etc.) • 51 : build up abstractions ; 61: drive through abstractions • Also electrical engineering, statistics, [applied] math, systems & synthetic biology, finance, economics, etc. • these fields (and many others) demand computational thinking. • Entrepreneurs • engineering take on design is invaluable. • Necessary background: • basic programming, algorithms, data structures (CS50) • mathematical “sophistication”
What will happen in the course? • Lectures • available online, but come anyway • lots of code walk-throughs, live design • Sections • not just reiterating lecture material • design is best done in small groups • Homeworks & project • homeworks: exercise abstractions, understanding (40%) • project: significant design component (20%) • Exams • mid-term (20%) and final (20%)
(Likely) Problem Sets • Getting up and going with VM & OCaml • Ocaml core language exercises • Moothmatica: Higher-order functions & polymorphism • RSA Crypto, Ocamlmodules • Game trees, priority queues • Moogle: dictionaries, sets, web crawling, page rank • Moosic: refs & streams • Robocows: objects and events
Final Projects • 4 people • Focus on something algorithmically interesting. • goal is to learn some CS on your own. • goal is to experience clean-slate design, testing, construction • goal is to experience working in a team • Many checkpoints • form team and core idea (beginning of March) • functional specification • technical specification • alpha release: basic functionality • beta release: usable by the staff • project video & writeup (before reading period)
Some nice projects • SAT solver • Mini-WolframAlpha • Robobee pollination • BSP trees for representing 3D scenes • Spam filter using Bayesian techniques • Circuit minimization via Binary Decision Diagrams • K-means clustering of genomic data • Compression algorithms • Natural language parsing
Collaboration • First few homeworks must be done alone. • Later homeworks will be done in pairs. • The final project will be done in groups of 4. • The exams, obviously, must be done alone. • Final projects can incorporate other people’s code as long as you acknowledge them. • It’s okay to talk to other students about coding issues, helping to find a bug, etc. • It’s not okay to ask for or reveal a solution to a problem. • When in doubt, go to a TF.
Logistical Information • Web: • http://cs51.seas.harvard.edu/ • See Policies link for issues related to late assignments, collaboration, etc. • 2 late days. Period. Don’t use them. • Books: • Recommended: The Functional Approach to Programming, by Guy Cousineau & Michel Mauny • Augmented by lecture, section notes & articles.
Homework (Today!) Go to the course web site: http://cs51.seas.harvard.edu/ Click on the Piazza link on the left. • sign up for a Piazza account. • check here for announcements. • in particular, office hours for software installation.
Staff: cs51-staff@eecs.harvard.edu KomalSayed (Head TF) Anna Gommerstadt (XO) Gabe Goldberg (CSCI E-250 Head TF)
Course Tools We’ll be using a very different programming environment. • get used to learning languages (not that hard once you’ve absorbed representatives from major genres.) • ObjectiveCaml (a.k.a. ML, Ocaml & F#): • functional & higher-order programming • substitution & environment models of evaluation • types, polymorphism • abstract data types, interfaces, modules • imperative & object-oriented programming • encapsulation, classes, subtyping, inheritance • events, parallelism, concurrency, synchronization
Why focus on functional programming? Functional programming is at the core of each language. • orthogonal design – lets us tease apart abstractions • simple models – closely related to simple math • future proof: half the issues with concurrency disappear • surprising power: higher-order programming • e.g., map-reduce framework from Google
Why Ocaml? Ocaml is a modern functional language: • Alternatives: Racket, Haskell, Erlang, Scala, etc. • Good mix of conciseness, performance: see http://dada.perl.it/shootout/craps_cpumemloc.html • statically typed, type inference • advantages of static typing, conciseness of scripting languages • designed around inductive definitions & pattern matching • promotes good style: e.g., compiler tells you when you miss cases • powerful module system • reifies ideas like interface, implementation, parameterization • integrated object system • a little unusual, but we avoid having to switch languages • Microsoft has released F# (a dialect) as a commercial product.
Language & Code • Language & abstractions matter. • Try formulating an algorithm to multiply Roman numerals. • Often, don’t have the luxury of choosing the language. • We can still conceptualize & prototype using the right language abstractions. • If we understand relationships between linguistic abstractions, we can realize the code in any language.
Example: Red-Black Trees • A particular kind of balanced search tree [Guibas & Sedgewick 1978]. 7 11 4 1 5 15 12 17 0 3
C code (part 1/4) void rb_insert( Tree T, node x ) { tree_insert( T, x ); x->colour = red; while ( (x != T->root) && (x->parent->colour == red) ) { if ( x->parent == x->parent->parent->left ) { y = x->parent->parent->right; if ( y->colour == red ) { x->parent->colour = black; y->colour = black; x->parent->parent->colour = red; x = x->parent->parent; } else { if ( x == x->parent->right ) { x = x->parent; left_rotate( T, x ); } x->parent->colour = black; x->parent->parent->colour = red; right_rotate( T, x->parent->parent ); } } else { . . . /* repeat above with red/black swapped */
C code (part 2/4) void left_rotate( Tree T, node x ) { node y; y = x->right; x->right = y->left; if ( y->left != NULL ) y->left->parent = x; y->parent = x->parent; if ( x->parent == NULL ) T->root = y; else if ( x == (x->parent)->left ) x->parent->left = y; else x->parent->right = y; y->left = x; x->parent = y; } /* repeat above for right_rotate with “obvious” changes */
Ocaml Code for Insert let balance c t1 t2 t3 = match (c, t1, t2, t3) with| ((Blk,T(Red,T(Red,a,x,b),y,c),z,d)| (Blk,T(Red,a,x,T(Red,b,y,c)),z,d)| (Blk,a,x,T(Red,T(Red,b,y,c),z,d))| (Blk,a,x,T(Red,b,y,T(Red,c,z,d)))) -> T(Red,T(Blk,a,x,b),y,T(Blk,c,z,d))| _ = T x let insert x t = match t with | Empty -> T(R,Empty,x,Empty) | T(color,a,y,b) -> ifx <= y thenbalance color(ins x a) yb elseif x > y thenbalance coloray(ins x b)
Who uses Ocaml (or other ML variants)? • Mostly research & education: • INRIA, Microsoft, Google, Xerox, Galois, major universities. • Note: required of all math/cs/science high-schoolers in France. • e.g., advanced compilers & static analyses, scientific computing, visualization, security, networking, etc. • Examples: Astree static analysis tool, Coq proof assistant, • Increasingly, Wall Street: • When billions are on the line, you don’t want an infinite loop. • Example: Jane Street Capital • proprietary trading firm • http://www.janestcapital.com/yaron_minsky-cufp_2006.pdf