Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python as a first language

Python as a first language

This presentation makes the case for Python as a first language in undergraduate computer science programs.

5ff2e2cd70421285fff0e6361354993b?s=128

Yoav Ram

June 12, 2018
Tweet

Transcript

  1. Python as a first language Yoav Ram June 2018

  2. Python is interpreted & dynamic Interpreter is great for novice

    programmers Dynamic type system allows fast prototyping
  3. Python is high-level Design emphasizes code readability “looks like pseudocode”

  4. 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
  5. 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
  6. 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
  7. Python is pluralist Cross-platform Multiple programming paradigms

  8. 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
  9. 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 )
  10. Almost everything is an object • strings, lists, dictionaries, tuples,

    functions, classes, types • Strong polymorphism • Duck typing
  11. 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
  12. Python is “batteries included” Large standard libraries Easy to install

    many 3rd party libraries Domain specific distributions
  13. 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
  14. Many new libraries released every month During 2015, > 1,500

    new packages released every month to PyPI. See more stats at PyGarden/stats.
  15. Python is free Gratis: Free as in Beer Libre: Free

    as in Speech GitHub | Mailing lists
  16. Python is open Open-source software Community-based development Managed by non-profit

    Python Software Foundation
  17. 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
  18. Python is cool Jupyter notebooks, online interpreters, code on your

    phone, Raspberry Pi
  19. 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
  20. 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
  21. Python is popular and has a great community

  22. Easy to find help on the Internet • Python is

    6th most popular tag on StackOverflow stackoverflow.com/tags, May 2018
  23. 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
  24. Demand for Python programmers is high

  25. Coding Dojo

  26. Python is widely-used In academia In industry In education As

    Wikipedia examples…
  27. 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/
  28. 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
  29. Phillip Gou @ CACM, 2014

  30. First language in Israeli departments TAU: Python HUJI: Python Technion:

    C BGU: Java BIU: C Haifa: C Open U: Java 2017-2018
  31. But why Python? Guido was reading some Monty Python's Flying

    Circus sketches and thought Python would be a cool name Python 2 FAQ
  32. Encyclopædia Britannica Online Thanks for listening 32 yoav@yoavram.com @yoavram www.yoavram.com