Software Design Spring 2007 Today: 1) get your environment squared away 2) start on Homework 1 For next time: 1) read Chapters 1 and 2 of "How to think..." 2) start on Homework 0 (choose a backup book) 3) get a three-ring binder and put these notes into it. Your environment ---------------- Python is a portable language, which means that it can run on Linux, Windows, MacOS and others. You _could_ do all of your work this semester in Windows, and I won't stop you, but I want to _strongly_ encourage you to work in Linux: 1) If you are not familiar with Linux, this is a good chance to learn. 2) Even if you never use Linux again, there are some ideas you will be exposed to that will make your life richer. 3) Since I don't use Windows, I can provide less help for Linux-avoiders (although I will try, or at least help you get help). Having said that, I will warn you that the more comfortable you are with another OS, the more adjustment it will take to get used to Linux. To help with adjustment, I have written a guide, called The Olinux Manual, which is available from http://wb/linux/ (wb stands for "whiteboard", which is an alternative to blackboard. from off campus, you need the full name, which is wb.olin.edu or ece.olin.edu) What's the plan? ---------------- Object-oriented programming in Python Software design patterns Basic algorithms and data structures Some sidebars (as time allows and interests dictate): usability engineering/HCI concurrent programming/threads network programming/distributed applications Pedagogic techniques -------------------- conventional DisInfo (dissemination of information) collect-transmit (student presentations) spiral learning (lots of foreshadowing) project-driven learning (medium-sized final project) one-room schoolhouse Goal: everyone learns a lot Corollary: beginners learn basic programming without being overwhelmed people with experience learn more advanced material without being bored beginners have a shot at the advanced material, but not required to master it people with experience _are_ required to do more than demonstrate basic mastery Three kinds of design --------------------- Analogy: lego basic bricks 1) given capabilities and 2) ways of interacting In a typical software design, you have a library of 1) built-in objects 2) built-in operations which you assemble into a solution. 1) design by assembly 2) design patterns 3) design by abstraction Basic algorithms ---------------- Given two words, how can you determine if they are anagrams (contain the same set of letters)? if is_anagram('tachymetric', 'mccarthyite'): print 'yes' 1) human algorithm? 2) basic python (well, except for the try statement) def is_anagram(s1, s2): t = list(s2) for c in s1: try: t.remove(c) except ValueError: return 0 return len(t) == 0 Problems? 3) a better (!) solution class Hist(dict): def __init__(self, s): for c in s: self[c] = self.get(c, 0) + 1 def is_anagram(s1, s2): return Hist(s1) == Hist(s2) Why is this better? ------------------- 1) more efficient algorithm (so what?) 2) more readable / less error prone 3) more reusable -- it creates a new, useful, named type (Hist) Design by Abstraction --------------------- defining new functions and classes creates new higher-level tools... that can be used to build the next layer of tools... and so on. Designing interfaces (between functions and between objects) is: 1) hard to do well 2) interesting and creative 3) where big brains pay off Style ----- Good code is 1) demonstrably correct 2) self-documenting (with comments that explain the non-obvious) 3) reusable (it creates new general-purpose abstractions) Some "style" is arbitrary convention, BUT Good style is mostly objective (not a matter of taste). A surprising amount of good style is good IDENTIFIER NAMES. def run(self): self.running = 1 while self.exists and self.running: self.step() self.update() sleep(self.delay) def stop(self): self.running = 0 Class organization ------------------ 2 one-hour classes per week (MR 10-11) more effective IF we don't lose the first 10 minutes! Dr Allen* says "make a lifestyle commitment" 1) eat well 2) sleep well 3) get some exercise 4) wash your hands frequently * Dr Allen has a Doctorate in Philosophy, and is not licensed to give medical advice. 2 two hours of lab per week during Wednesday 1-5pm, Short "entrance quiz" at the beginning of each lab. Start homework in lab, done by the beginning of the next. Das Buch -------- We will be using my book, "How to think like a computer scientist", but you should also buy one other Python book of your choice. I have put a stack of Python books on reserve: check em out, choose one, and place an order. Also check out the reviews at http://www.awaretek.com/book.html Note, almost all are intended for programmers. Exceptions (that I know of) are: Python: How to Program by Deitel and Deitel Learn to Program Using Python by Alan Gauld Python Programming by John M. Zelle (this is new -- I have not read it, but it is getting good reviews)