Python and the Future of Programming - Guido van Rossum

5 minute read

My summary notes of Python and the Future of Programming by Guido van Rossum in Lex Fridman Podcast.

CPython

  • CPython 3.11 is on average 25% faster than CPython 3.10. Depending on your workload, the speedup could be up to 10-60% faster.

Code Readability

  • Software is a social activity. Code has to be clear and simple as a cookbook recipe for other programmers so people can continuously improving the recipe.

Indentation style

  • There is a possible future of curly braces in Python similar to C++ or Java but it will be extremely hard since Python is currently using curly braces for dictionaries.
  • History of the dollar sign ($) in PHP or Perl
    • The dollar sign ($) is invented since the earliest unix shell had a notion of scripting, but they did not have a notion of parameterizing the scripting. So later on, to make it clear to the script processor, they use the dollar sign ($) to declare this is a variable.

Bugs

  • On average, a developer creates 70 bugs per 1000 lines of codes. 15 bugs find their way to the customer.
  • Fun fact: Guido still types with 2 fingers.

Programming fads

  • Should I hold on to current tools or invest in new modern tools? How do I know if the new tool is not just a new fad?
    • The technology will always be replaced but many concepts that it introduced are preserved in the new one.
    • There’s no right choice: You should try all random stuffs, then maybe you can discover something that is better.

Speed of Python 3.11

  • How does it get a big improvement in performance?
    • Make the interpreter faster by introducing Specializing Adaptive Interpreter.
  • Specializing Adaptive Interpreter
    • Whenever Python check the types of given operations that is “hot” (executed multiple times), it will then use byte codes that are optimized for that specific type, and then this will automatically speed up your code 25%.
    • An example here is the ADD operation.
      • Instead of having a single byte code of a generic ADD operation that needs to check a bunch of error checking and types of 2 inputs, i.e: Integer, String … before adding the 2 bits pattern in the right place. If we can predict the types of these 2 inputs will always be Integer, then use the ADD Integer operation instead of generic ADD operation which is much more efficient.
      • This is a fairly known trick for dynamic typing language compiler: borrow from FB’s hhvm for Hack.

Type hinting

  • Similar to a linter, it is a static type checker to check type annotations.

mypy

  • mypy - Started by Jukka Lehtosalo.
    • Original Static typed checker for Python.
  • Static type checker is like a linter.
    • Do static analysis to point out mistakes.
    • Help developers to catch bugs for compiler.
  • Many big companies has since developed their own Python static type checker
    • pytype - Google
    • pyright - Microsoft
    • pyre - Facebook
      • FB was one of the first to developed their own static type checker for Python due to success of hhvm compiler written in OCaml.

Best IDE for Python

  • Guido started with VIM, then moved to Emacs.
  • Which IDE would you recommend?
    • Doesn’t matter, just pick the one you are most productive with. But if you are just started, PyCharm and VScode are both good options.
      • However, VSCode has great extensibility and package ecosystem while PyCharm is really hard to work with to create an extension.

Parallelism

  • Reviewing concept of Parallelism vs Concurrency
    • Parallelism: multiple tasks run a the same time, e.g., on a multicore processor.
    • Concurrency: Multi-tasking where tasks run and complete in overlapping time period doesn’t mean they both run simultaneously.
  • Why is it hard to implement synchronization primitives?
    • Our brain is not trained to keep track of multiple time at the same time.
    • So the implementation can easily create lots of bugs.
  • asyncio
    • concurrency networking I/O for Python web clients.
    • Hated the original style of callback in Javascript event loop, so pick a different paradigm of Task-based model to develop asyncio.

Global Interpreter Lock (GIL)

  • was developed to solve the problem that Python originally does not support concurrency or parallelism.
    • Didn’t want to rewrite the Interpreter to be thread-safe.
    • Many Operating system at that time can handle the threads for you. Program can pretend there are many CPUs for you since the OS can simulate extra CPUs.
  • Later on when hardware vendors decides to put many CPUs in the machines and expect software to run in parallel, then it won’t work anymore. Since GIL only works with 1 CPU, and all threads run on a single core.
  • Future to remove GIL

Python 4.0

  • Not anytime soon. Painful experience of transition from Python 2 to 3.
  • How about No-GIL as Python 4.0?
    • Even with no syntax or semantic changes, all of the C extensions modules will need to be changed to be No-GIL compatible.
    • This will impact many Python users especially in the Data Science, Machine Learning and scientific community since they are heavily dependent on C extension modules

Machine Learning

  • Why is it most popular for DS, ML community?
    • Because it is better than C, C++ and Fortran for scientists to write, and has the extendability to support the handle large arrays of numbers, multi-dimensional arrays.
    • Matlab by Mathworks is not open source and too expensive.

Benevolent Dictator for Life (BDFL)

  • Step down from the role, become less stressful, and have more freedom to explore other interesting projects.
  • Step out of retirement to join Microsoft because retirement is too boring.
  • Advice for beginners
    • What to do with your computer science career?
      • Depends on your skillsets and what you are aspire and good at, you can choose to work for a big company or build something your own.
    • How to learn Python the right way for beginner?
      • Pick some problem you want to solve that give you the motivation to learn coding in any language.

Github Copilot

  • Use Code generation like Copilot to help you become more efficient.
  • Will AI code generation threaten the job of programmers?
    • Nope, similar to StackOverflow, these tools help programmers with all the boring stuffs so they can focus on more important things.
    • It is a great assistant but depends on the exact thing you ask them to provide.

Future of Python

  • Will probably become a legacy language that people build on top of it and forget about similar to the all the lower layers we have today.

References

Tags:

Categories:

Updated:

Leave a comment