Reston/San Diego, July 25, 2001 1 O'Reilly Open Source Convention 2001 San Diego, CA Python Track Keynote Guido van Rossum Zope Corporation

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Chapter 25 Lists, Stacks, Queues, and Priority Queues
Simplifications of Context-Free Grammars
Variations of the Turing Machine
Adders Used to perform addition, subtraction, multiplication, and division (sometimes) Half-adder adds rightmost (least significant) bit Full-adder.
1
Chapter 6 Writing a Program
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Author: Julia Richards and R. Scott Hawley
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
1 Hyades Command Routing Message flow and data translation.
"The State of the Python Union" Python10 - Alexandria, VA - February 7, 2002 Guido van Rossum Director, PythonLabs at Zope Corporation
Why I Invented Python EuroPython – June 27, 2005 Guido van Rossum Elemental Security, Inc.
EuroPython Keynote June 26, 2002 Guido van Rossum Director of PythonLabs at Zope Corporation
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Chapter 6 File Systems 6.1 Files 6.2 Directories
Programming Language Concepts
For Translators and Translation Editors Note-Taking presents... by Riccardo Schiaffino CTA 3rd Annual Conference Boulder, May © Riccardo Schiaffino,
Intel VTune Yukai Hong Department of Mathematics National Taiwan University July 24, 2008.
Announcements Homework 6 is due on Thursday (Oct 18)
Chapter 11: Models of Computation
Turing Machines.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
PP Test Review Sections 6-1 to 6-6
Chapter 17 Linked Lists.
David Luebke 1 6/7/2014 ITCS 6114 Skip Lists Hashing.
Chapter 24 Lists, Stacks, and Queues
Campaign Overview Mailers Mailing Lists
Modern Programming Languages, 2nd ed.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
User Friendly Price Book Maintenance A Family of Enhancements For iSeries 400 DMAS from Copyright I/O International, 2006, 2007, 2008, 2010 Skip Intro.
Semantic Analysis and Symbol Tables
Chapter 4 Gates and Circuits.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application.
Chapter 5 Plan-Space Planning.
Operating Systems Operating Systems - Winter 2010 Chapter 3 – Input/Output Vrije Universiteit Amsterdam.
Lexical Analysis Arial Font Family.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
 Copyright I/O International, 2013 Visit us at: A Feature Within from Item Class User Friendly Maintenance  Copyright.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Lilian Blot PART III: ITERATIONS Core Elements Autumn 2012 TPOP 1.
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Adding Up In Chunks.
Lilian Blot PART V: FUNCTIONS Core elements Autumn 2013 TPOP 1.
While Loop Lesson CS1313 Spring while Loop Outline 1.while Loop Outline 2.while Loop Example #1 3.while Loop Example #2 4.while Loop Example #3.
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Analyzing Genes and Genomes
Types of selection structures
Lilian Blot CORE ELEMENTS SELECTION & FUNCTIONS Lecture 3 Autumn 2014 TPOP 1.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Pointers and Arrays Chapter 12
Essential Cell Biology
Exponents and Radicals
PSSA Preparation.
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
Essential Cell Biology
9. Two Functions of Two Random Variables
User Defined Functions Lesson 1 CS1313 Fall User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough #1.
CS1022 Computer Programming & Principles
Bruce Beckles University of Cambridge Computing Service
Presentation transcript:

Reston/San Diego, July 25, O'Reilly Open Source Convention 2001 San Diego, CA Python Track Keynote Guido van Rossum Zope Corporation

Reston/San Diego, July 25, Sorry I Couldn't Make It! My wife spent a night in the hospital –Complications with her pregnancy She and our baby are doing fine now –But this is scary stuff! Our due date is November 2nd –I'll disappear for 3-6 weeks around then…

Reston/San Diego, July 25, Where to Start? So much to talk about! –New Python release(s!) –New Python license –New Python logo –New corporate name –Have you flamed me on c.l.py recently?

Reston/San Diego, July 25, New Corporate Name On Monday, Digital Creations officially changed its name to Zope Corporation Also known as Zope Website: Zope.com Zope CVS opened up Little else changes

Reston/San Diego, July 25, New Python Logo Designed by Just van Rossum and Erik van Blokland

Reston/San Diego, July 25, Many Logo Variations

Reston/San Diego, July 25, Python Software Foundation Owns and releases Python software Established in Delaware Bylaws on line: Applying for non-profit status

Reston/San Diego, July 25, Next Python Conference February 4-7, 2002 –Alexandria, VA (near Washington, DC) Four tracks: –Refereed Papers –Zope –Python Tools –Business-to-Business CFP: see

Reston/San Diego, July 25, New Python License At last, Python is GPL-compatible again Which versions are GPL-compatible? –1.5.2 and before, 2.0.1, 2.1.1, 2.2 and later –But not: 1.6, 1.6.1, 2.0, 2.1 Why were those not GPL-compatible? –Mostly, choice of law clause in CNRI license Who cares? –FSF; Debian, other binary release builders

Reston/San Diego, July 25, What Is GPL-compatibility? GPL-compatibility allows release of Python linked with GPL-licensed library –For example, GNU readline Python is Open Source Compliant –A much more liberal requirement Python is not released under the GPL! –No "viral" requirements in license

Reston/San Diego, July 25, Recent Python Releases GPL-compatible bug fix release –June GPL-compatible bug fix release –July a1 - first alpha of new release –July 2001; 2.2 final planned for October

Reston/San Diego, July 25, What's A Bug Fix Release Idea introduced by PEP 6; thanks Aahz! Fix bugs without any incompatibilities Full binary and byte code compatibility No new features I.e. full two-way compatibility; code developed under will run the same under 2.1 (unless it hits a bug in 2.1, obviously); even extensions! Thanks to the release managers! Moshe Zadka (2.0.1), Thomas Wouters (2.1.1)

Reston/San Diego, July 25, About Python 2.2 What's new? –Nested scopes are the law –Iterators and Generators –Type/Class unification –Unicode, UCS-4 –XML-RPC –IPv6 –New division, phase 1

Reston/San Diego, July 25, Nested Scopes: It's The Law! Introduced in 2.1 with future statement: –from __future__ import nested_scopes Future statement is unnecessary in 2.2 –But still allowed Motivating example: def new_adder(n): return lambda x: return x+n

Reston/San Diego, July 25, Iterators: Cool Stuff Generalization of for loop machinery New standard protocols: –'get iterator' protocol on any object: it = iter(x) # returns iterator for x –'next value' protocol on iterator objects: it.next() # returns next value # raises StopIteration when exhausted

Reston/San Diego, July 25, Iterators: For Loops Equivalency between these two: –for el in sequence: print el –__it = iter(sequence) while 1: try: el = __it.next() except StopIteration: break print el

Reston/San Diego, July 25, Iterators: Why No need to fake sequence protocol to support 'for' loop (a common pattern): –for key in dict: … –for line in file: … –for message in mailbox: … –for node in tree: … Lazy generation of sequence values Can do iterator algebra, e.g. zipiter()

Reston/San Diego, July 25, Iterators: More Some non-sequences have iterators: –Dictionaries for k in dict: print key, dict[k] for k, v in dict.iteritems(): print k, v Related feature: if k in dict: print k, dict[k] –Files for line in open("/etc/passwd"): print line, –Class instances Define your own __iter__() method

Reston/San Diego, July 25, Generators: Really Cool Stuff An easy way to write iterators –Thanks to Neil Schemenauer & Tim Peters from __future__ import generators def inorder(t): if t: for x in inorder(t.left): yield x yield t.label for x in inorder(t.right): yield x

Reston/San Diego, July 25, Generator: Example def zipiter(a, b): while 1: yield a.next(), b.next() for x, y in zipiter(range(5), "abcde"): print (x, y), (0, 'a') (1, 'b') (2, 'c') (3, 'd') (4, 'e')

Reston/San Diego, July 25, Generators: Why Often an algorithm that generates a particular sequence uses some local state expressed by a combination of variables and "program counter" For example: tokenizer, tree walker Generating the whole sequence at once is nice but can cost too much memory Saving all the state in instance variables makes the algorithm much less readable Using a callback is cumbersome for the consumer of the values

Reston/San Diego, July 25, Generators: How Presence of yield signals the parser –Implementation "suspends" the frame Calling the generator function: –Creates the frame in suspended mode –Returns a special-purpose iterator Calling the iterator's next(): –Resumes the frame until a yield is reached –Raises StopIteration when upon return Or upon falling off the end

Reston/San Diego, July 25, Type/Class Unification class mydict(dictionary): def __getitem__(self, key): try: return dictionary.__getitem__(self, key) except KeyError: return 0.0 # default value a = range(10) assert a.__class__ is type(a) is list list.append.__doc__ list.append(a, 11) list.__getitem__(a, 4)

Reston/San Diego, July 25, Method Resolution Order Order in which bases are searched for methods Trivial with single inheritance Relevant for multiple inheritance Classic Python rule: left-right depth-first Classic rules makes a lot of sense; natural extension of single inheritance rule for tree- shaped inheritance graph; but… Classic rule breaks down when there is a common base class

Reston/San Diego, July 25, CB D A class A: … def save(self): …save A's state… class C(A): … def save(self): A.save(self) …save C's state… class B(A): … # no save() class D(B,C): … # no save() >>> x = D() >>> x.save() # is C's state saved???

Reston/San Diego, July 25, Proposed New MRO Informal requirements: –Same as classic rule when dependency graph is a tree (no common base classes) –Most derived method wins Algorithm embeds a topological sort in a total ordering In diamond example: [D, B, C, A] Metaclass can override MRO policy

Reston/San Diego, July 25, Pros And Cons Pro: avoids the diamond surprise Pro: matches other languages' rules Con: harder to explain –But: same as classic unless shared base! IMO, classic rule makes common bases too hard to use Neither rule deals with conflicts

Reston/San Diego, July 25, Common Base Class 'object' class: the ultimate base class Defines standard methods: –__repr__, __str__ –__getattr__, __setattr__, __delattr__ –__cmp__, __hash__, __lt__, __eq__, … Override __getattr__ properly: class C(object): def __getattr__(self, name): if name == 'x': return … return object.__getattr__(self, name)

Reston/San Diego, July 25, Conflicts What if both B and C define a save() method? D has to implement a save() that somehow maintains the combined invariant Should the system detect such conflicts? Probably, but maybe not by default, since current practice allows this and so flagging the conflicts as errors would break code. Maybe a warning could be issued, or maybe it could be a metaclass policy

Reston/San Diego, July 25, Unicode, UCS-4./configure --enable-unicode=ucs4 –Not yet on Windows Compiles with Py_UNICODE capable of holding 21 bits –Trades space for capability to handle all 17 Unicode planes Alternative: UTF-16 and surrogates –Indexing characters would be too slow

Reston/San Diego, July 25, XML-RPC XML-RPC: easy, interoperable RPC Code by Fredrik Lundh Client is a library module (xmlrpclib) Server frameworks in Demo/xmlrpc/ See

Reston/San Diego, July 25, IPv6./configure --enable-ipv6 Code by Jun-ichro "itojun" Hagino Integration by Martin von Loewis Modified socket module: –socket.getaddrinfo(host, port, …) –socket.getnameinfo(sockaddr, flags) –socket.AF_INET6 address type, if enabled Supported by httplib

Reston/San Diego, July 25, Have You Flamed Me On C.L.PY Recently? The problem: int and float are not really two types, more one-and-a-half… 1+x == 1.0+x, 2*x == 2.0*x, etc. –x can be int or float –Result has same mathematical value But not: 1/x == 1.0/x –Result depends on type of x

Reston/San Diego, July 25, Why Is This A Problem? def velocity(distance, time): return distance/time velocity(50, 60) # returns 0 Violated principle (only by division): –In an expression involving numerical values of different types, the mathematical value of the result (barring round-off errors) depends only on the mathematical values of the inputs, regardless of their types

Reston/San Diego, July 25, In Other Words… There are really two different operators, "int division" and "float division", both of which make sense for numerical values In expressions yielding float results, int inputs are usually okay, except when division is used

Reston/San Diego, July 25, Why Is This A Problem? Python has no type declarations In statically typed languages, velocity() would have explicit float arguments The work-around is really ugly: –x = float(x) # Broken if x is complex –x = x+0.0 # Broken if x is -0.0 –x = x*1.0 Works, but what if x is a Numeric array…

Reston/San Diego, July 25, Proposed Solution Eventually (in Python 3.0? :-) –Use / for float division, // for int division Transitional phase (at least two years): –Enable // immediately (in Python 2.2) –Use "from __future__ import division" to enable / as float division –Command line switch to override default Will remain for a while after transition –Standard library will work either way

Reston/San Diego, July 25, Variations Spell int division as x div y –New keyword creates additional problems Spell int division as div(x, y) –Hard to do a global substitute

Reston/San Diego, July 25, How About Python <= 2.1? If you have to maintain code that must run correctly under Python 2.1 or older as well as under the eventual scheme, you can't use // or the future statement Use divmod(x,y)[0] for int division Use x*1.0/y for float division But it would be much easier to use the command line switch, if you can

Reston/San Diego, July 25, Alternatives Status quo –Real problems in some application domains Use // for float division –The / operator remains ambivalent Directive for division semantics –Makes the original design bug a permanent wart in the language (violates TOOWTDI) Drop automatic coercion int to float :-)

Reston/San Diego, July 25, Why Not Rational Numbers? Rationals would be a fine solution But there is discussion about the design –To normalize or not; performance Changing int/int to return a rational breaks just as much code, so would require the same transitional measures Switching int/int from float to rational later won't break much code –Mathematical values are the same

Reston/San Diego, July 25, A Proper Numeric Tower Eventually, Python may have a proper numeric tower, like Scheme, where the different numeric types are just representational optimizations int < long < rational < float < complex Implies 1 and 1.0 should act the same Requires int/int to be float or rational Float division switch is enabler!

Reston/San Diego, July 25, Decimal Floating Point An alternative to binary floating point Just as inexact Slower, because emulated in software But no surprises like this: >>> >>>

Reston/San Diego, July 25, Case Insensitivity [ducks :-]

Reston/San Diego, July 25, Some Of My Favorite Apps Jython wxPython PyChecker IDLE fork Pippy (Python on Palm) Python on iPAQ (Linux "familiar" 0.4) PySol