DOC PREVIEW
Duke CPS 006 - abstractions over code

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Compsci 06/101, Fall 2010 3.1 Compsci 6/101: Sept 6-10  We've looked at the language Python  Names and types: int, float, long, String, file, …  Operations: *, +, -, /, %, **  Types and values different from "real life"  What is 7/3 in Python?  What is "champion"[2:5]  What's String+String and String*int and String+int  For useful work: organizing code/programs  Functions, modules, indentation, naming Compsci 06/101, Fall 2010 3.2 Functions: abstractions over code  Naming something gives you power  How do you find absolute value?  What is length of a string?  We can write and call functions  Re-use and/or modify  Store in module, import and re-use functions  Import standard modules and use functions from them  Functions can (should?) return a value  We've seen len return an int, what about file.read?  Other functions return Strings, floats, or other types Compsci 06/101, Fall 2010 3.3 Anatomy of a Python function def name(params): body  Define a function, provide a name, provide parameters, provide a function body  How to decide on name?  Do we need parameters?  What does body of function do  Functions provide a named abstraction over code  Huh? What is math.isinf(..) or math.sqrt(..)? Compsci 06/101, Fall 2010 3.4 Design, Implementation, Testing  Designing Python code and functions  What do you want the code to do?  Other aspects of code, e.g., portability, efficiency, size, …  Understand how to solve a problem without computer  Implementing design in code  Translation of ideas into vocabulary of Python  We don't have a large vocabulary, but it will grow!  Testing code, functions  How do you know when function is right?  What confidence can testing provide?Compsci 06/101, Fall 2010 3.5 Nancy Leveson: Software Safety  Mathematical and engineering aspects, invented the discipline  Air traffic control  Microsoft word There will always be another software bug; never trust human life solely on software. huffington post?  Therac 25: Radiation machine  http://en.wikipedia.org/wiki/Therac-25  http://bit.ly/5qOjoH  Software and steam engines Compsci 06/101, Fall 2010 3.6 Writing and testing functions  Review of slicing operator for strings  What is an index, where does indexing begin?  Value of s[a:b] compare s[a:] compare s[:b]  Review problems from last set of notes  Pounds to …, BMI, Heron's formula  Algorithm Problem Test (APT)  Role in Compsci 6/101 and other courses  Similar to Unit Testing, part of Agile Development Compsci 06/101, Fall 2010 3.7 String functions in Python  Strings are objects, some functions 'builtin'  Use web, or Python: strip, startswith, find, count, …  Strings are immutable: "hello".replace("h","j")  Python operators/functions that work with strings  We've seen len, what about in? What's going on?  Slicing review, modify or create new?  Views of strings: what are they?  From an abstract point of view, from Pythonic POV? Compsci 06/101, Fall 2010 3.8 Jon Kleinberg  2005 MacArthur Fellow, 2008 Infosys Award, 2008 Discover “20 Best Brains under 40”  Networks course and book  Duke course 96 Spring 2010  "....Try to keep an open mind about topics and areas going on....It's much easier to make progress on a problem when you are enjoying what you are doing. In addition to finding work that is important, find work that has some personal interest for you....I've benefited from a lot of mentoring throughout my career. I think it's important to pass it on to the next generation and work in a mentoring capacity or a teaching capacity with people entering the field....” ACM Infosys


View Full Document

Duke CPS 006 - abstractions over code

Download abstractions over code
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view abstractions over code and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view abstractions over code 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?