{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec10 A crash course in Python

lec10 A crash course in Python -...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
http://www.cs.ucsd.edu/classes/fa06/cse130/lectures/lec10.txt Lecture 10: A crash course in Python ------------------------------------ Before we say goodbye to ML, I'd like to remind you, that learning to program in ML -- and in general, the functional style, will positively impact how you design and implement software systems. An example of this, is the use of a library called "MapReduce" inside Google. The MapReduce library allows Google programmers (not released yet) to compute complex functions over _all_ the pages indexed by Google. The library has exactly two functions: 1. map : ('a -> key * 'b) -> 'a list -> (key * 'b) list 2. reduce (a.k.a. "fold"): ('b * 'b -> 'b) -> 'b list -> 'b The actual implementation is in C++ and is done by a complex system that: 1. parallelizes across hundreds of machines 2. manages communication, synchronization, failures 3. all the programmer uses are map, reduce # Show slides, show parallelization Hundreds of different tasks programmed using map/reduce library in Google. OK. but, now, speaking of Google, is a language that is used heavily inside Google, and also in a variety of other tools, e.g. BitTorrent: PYTHON. Named after the British TV show: "Monty Python". So why are we studying Python ? The main reason is that its cool, as you will see very soon. But other than that, it fits right into our main goal of seeing what goes into the guts of a PL... ML PYTHON ----------------------------------------------------------------------------------- 1. PL Paradigm Functional Imperative,Object-Oriented 2. Basic Unit everything is a Value everything is an Object 3. Types Static/Compile-time Dynamic/Execution-Time "Duck-typing" 4. Vars,DataModel Env:var -> value Namespace: var -> object No mutation Objects are mutable 5. Scope Static/Lexical Static/Lexical 6. Functions Functions (are values) Functions (are objects) 7. Building Blocks Structures Classes + Modules Hiding w/ Signatures No hiding("convention") http://www.cs.ucsd.edu/classes/fa06/cse130/lectures/lec10.txt (1 of 11) [2/13/2008 5:10:42 PM]
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
http://www.cs.ucsd.edu/classes/fa06/cse130/lectures/lec10.txt ----------------------------------------------------------------------------------- Python has a very relaxed philosophy -- if something "can be done" then it is allowed. Combination of dynamic types + everything is an object makes for very flexible, very intuitive code. --> No static type system to "prohibit" operations --> At runtime, every "operation" is translated to a method call on the appropriate object. If the object supports the method, then the computation proceeds. Duck-typing: if it looks like a duck, quacks like a duck, then it is a duck! --> This loose, comfortable, free-style, philosophy is at the heart of python. --> This comes at a price. ML type discipline catches many bugs early when you are programming. Python would find the same problem much later during execution, which gets annoying, unless you write perfect code. ha ha. Some things similar to ML: --> Everything is an object. A very uniform data model. --> This includes functions. --> Can pass functions (just objects) around, i.e. can send/return functions.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern