It is that simple. The momentum, which is partially due to the unprecedented AI bubble, is such that it actually became “too big to fail” and too important (for more than one industries) to not be “done right”.
3.14 is getting a proper tail-calls in the interpreter, 3.13 got an initial support for native compilation. It will only continue to get polished by literally millions.
The last fundamentally right addition was the support for the proper sum-types (a tagged union) as dataclasses and the the related pattern-matching syntax.
Now almost any classic FP code could be idiomatically and properly translated into modern (since 3.12 at least) Python.
Optional[X]
is equivalent to X | None
, so one can pattern-match on this “anonymous, in-place sum-type” (or just define and name it).
No type-classes or traits yet, but who knows.
Another well-known advantage is these millions of libraries (of questionable quality) for literally everything.
Because the amount (in LoC) of Python code in public domain (on Github an PyPi) is bigger that all the other languages combined (this is not even a joke), it is not a coincidence that all the LLMs “speak Python”, or at least could generate some Python (of a lowest quality, of course).
So, knowing Python nowadays is just like knowing some high-school algebra.
There is a problem, however (nowadays there is always a problem of this kind) – way too many low quality “teaching materials”, starting from ambitious but grossly unqualified amateurs on YouTube, to plain scam SEO web cites, where they just copy-paste tutorials from each other to run Google ads.
Here is a more or less up to date list of top-tier teaching materials:
- https://www.composingprograms.com/
- https://www.youtube.com/@JohnDeNero/playlists
- https://libgen.li/edition.php?id=138699662
The first two are “spiritual successors” of Brian Harvey, the great (the classic scheme-based CS61A).
The book is by John V. Guttag, the MIT hotshot who used to be a co-author of legendary Barbara Liskov.
There are also several introductory MIT CS courses (in Python) taught by him. Watch these instead of Netflix. I am not kidding.
- https://ocw.mit.edu/courses/6-00sc-introduction-to-computer-science-and-programming-spring-2011/
- https://ocw.mit.edu/courses/6-0002-introduction-to-computational-thinking-and-data-science-fall-2016/
These are on par with the best CS course of all time:
https://www.youtube.com/playlist?list=PLre5AT9JnKShBOPeuiD9b-I4XROIJhkIU
well, second only to the Wizards lectures.
There is a lot more to Python, of course, but this is a decent non-bullshit start.
After that there is a great mini-course by no less than Peter Norvig himself. It is still could be found scattered somewhere on YouTube (the idiots keep removing everything good).
After that there are videos by @karpathy
Notice, in particular, how he uses nothing but the web browser (Jupyter). This means that the language and the APIs are well-designed, so they can be properly used in a REPL.
Very few classic languages can be properly used in a REPL (SML/Ocaml, MATLAB, Scheme). The key aspect here is that high-level APIs are actual layers of DSLs, just like in MATMAB.
This much is more than enough. Pay attention to the details and how these gurus explain the whys and the whats.
Just going through this will make you a way-better-than-average Python coder.
There is one more book:
from dataclasses import dataclass
@dataclass
class Circle:
radius: float
@dataclass
class Rectangle:
width: float
height: float
@dataclass
class Triangle:
base: float
height: float
# this!
Shape = Circle | Rectangle | Triangle
def area(shape: Shape) -> float:
match shape: # and this!
case Circle(radius):
return 3.14159 * radius**2
case Rectangle(width, height):
return width * height
case Triangle(base, height):
return 0.5 * base * height
# Example usage
circle = Circle(radius=5)
print("Area of circle:", area(circle))
rectangle = Rectangle(height=10, width=5)
print("Area of rectangle:", area(rectangle))
triangle = Triangle(base=10, height=5)
print("Area of triangle:", area(triangle))