Share
Embed
Python as a first language
This presentation makes the case for Python as a first language in undergraduate computer science programs.
Yoav Ram
June 12, 2018
Transcript
32 slides
-
Python is interpreted & dynamic Interpreter is great for novice
programmers Dynamic type system allows fast prototyping -
Python design principles • Aims for simplicity and generality •
Semantic whitespaces (newlines, indentation) • English keywords (and, or, not, in, is, as) • Operator overloading (”hello “ + “world”) There should be one—and preferably only one— obvious way to do it Wikipedia -
Example: Hello World! Java public class HelloWorld { public static
void main(String[] args) { System.out.println(“Hello World!”); } } Python print(“Hello World!”) Complex: classes, accessibility, arrays, functions, static, return type (void!), namespaces, standard output… and compilation. Simple. Try in online interpreter : tiny.cc/PyHelloWorl -
Example: simple program def f2c(f=None): if f is None: f
= input(“Enter F degrees: “) f = float(f) return (f – 32) * 5 / 9 def c2f(c=None): if c is None: c = input(”Enter C degrees: “) c = float(c) return 9 / 5 * c + 32 tiny.cc/PyF2C -
Programming paradigms • Object-oriented programming (C++, Java, C#) • Imperative
programming (C) • Functional programming (Haskell) • Event driven & async programming (JavaScript) – Co-routines (async) or callbacks (tornado) Wikipedia -
OOP class Rectangle(Shape): def __init__(self, lower_left, upper_right): self.ll = lower_left
self.ur = upper_right def area(self): width = self.ur.x – self.ll.x height = self.ur.y – self.ll.y return width * height def __contains__(self, point): return ( self.ll.x < point.x < self.ur.x and self.ll.y < point.y < self.ur.y ) -
Almost everything is an object • strings, lists, dictionaries, tuples,
functions, classes, types • Strong polymorphism • Duck typing -
Functional programming generators n = len(numbers) mean = sum(numbers) /
n devs = (x – mean for x in numbers) squared_devs = (x*x for x in numbers) var = sum(squared_devs) / n std = var**0.5 def make_power(a): def power(x): return x**a return power square = make_power(2) square(4) # => 16 closure -
Python is “batteries included” Large standard libraries Easy to install
many 3rd party libraries Domain specific distributions -
Large standard library • Files: zip, gzip, json, csv, tempfile,
linecache, xml, wave • db: sqlite3, dbm • Network: socket, ssl, async • Web: urllib, http.server, email, ftplib, cgi, html, uu • Crypto: hashlib, hmac, secrets • Software: logging, unittest, mock, doctest, curses, sched, queue, getpass, gettext, tk,pdb, profiler • Concurrency: threading, multiprocessing, async, futures, subprocess • collections, functools, itertools… Python docs -
Many new libraries released every month During 2015, > 1,500
new packages released every month to PyPI. See more stats at PyGarden/stats. -
Python is free Gratis: Free as in Beer Libre: Free
as in Speech GitHub | Mailing lists -
Python is open Open-source software Community-based development Managed by non-profit
Python Software Foundation -
History of Python • Developed in 1989-91 by Guido van
Rossum in the Netherlands • Python 2.0 released Oct 2000 • Many major new features: – cycle-detecting garbage collector – support for Unicode – shift to transparent and community-backed development • Python 3.0 released Dec 2008 – major backwards-incompatible release – many of major features backported to Python 2.6 and 2.7 • Python 3.5 released Sep 2015 • Python 3.7 beta available, final expected June 2018 -
Python is cool Jupyter notebooks, online interpreters, code on your
phone, Raspberry Pi -
Python is fast enough Easy to wrap more C Easy
to parallelize Numerical packages implemented in C Cython: transcoder to C Numba: JIT compiler Benchmark Game | NumFocus Benchmarks -
Python for data science & scientific computing With libraries like
NumPy, SciPy, Matplotlib, IPython/Jupyter, Scikit-image, Scikit-learn, and more Replacing MATLAB Pushed by Google, Microsoft, others -
Easy to find help on the Internet • Python is
6th most popular tag on StackOverflow stackoverflow.com/tags, May 2018 -
Active community • 3rd most active repositories on GitHub after
Java (incl. Android) and JavaScript (incl. node.js) • As of May 2018 • See breakdown at githut -
Python is widely-used In academia In industry In education As
Wikipedia examples… -
Python is used at Google, Rackspace, Microsoft, Intel, Walt Disney,
MailChimp, twilio, Bank of America, Facebook, Instagram, HP, Linkedin, Elastic, Mozilla, YouTube, ILM, Thawte, CERN, Yahoo!, NASA, Trac, Civilization IV, reddit, LucasFilms, D-Link, Phillips, AstraZeneca, Applied Materials, KLA-Tencor, Nova, Lam Research, Marvell https://us.pycon.org/2016/sponsors/ https://www.python.org/about/quotes/ https://en.wikipedia.org/wiki/Python_%28programming_language%29#Use https://en.wikipedia.org/wiki/List_of_Python_software https://www.python.org/about/success/ -
First language in US CS departments 1. Carnegie-Mellon: Python, C
2. MIT: Python 3. Stanford: Python, Java, JavaScript 4. Berkeley: Python 5. U Illinois UC: Python, Java, MATLAB, C 6. Cornell: Python, MATLAB 7. U Wash: Python, Java 8. Princeton: Java • Olin: Python Phillip Gou @ CACM -
First language in Israeli departments TAU: Python HUJI: Python Technion:
C BGU: Java BIU: C Haifa: C Open U: Java 2017-2018 -
But why Python? Guido was reading some Monty Python's Flying
Circus sketches and thought Python would be a cool name Python 2 FAQ