programming book

First-Class: Luciano Ramalho’s Fluent Python

Programming languages as feature sets, not paradigms
Luciano Ramalho

code
San Francisco, California
November 11, 2019

IN 2015, A SEMINAL BOOK on programming was released: ‘Fluent Python’1 by Luciano Ramalho2.

Many coding books can feel like remixes, with familiar content simply presented under different chapter titles and with varying code examples. However, ‘Fluent Python’ wasn’t just another of those books. It was both well-written and refreshingly original. The chapters brought to light lesser-known aspects of the Python language and programming at large.

It was the minutiae in the book that truly solidified my admiration.

The term “first-class functions” is widely used as shorthand for “functions as first-class objects.” It’s not perfect because it seems to imply an “elite” among functions. In Python, all functions are first-class. - Chapter 5. First-Class Function

That’s good. “First-class” as an adjective implies a categorization, an “elite” as he calls it. In reality, functions are always first-class in Python. First-class means the function can be assigned to a variable, sent along as arguments to other places, and returned from other functions. They don’t need to be executed immediately to be referenced or manipulated.

Sensitivity to language shows up throughout the book. For example, in another chapter – Chapter 18: Concurrency with Aysncio – Ramalho leads with this quote.

Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once. Not the same, but related. One is about structure, one is about execution. Concurrency provides a way to structure a solution to solve a problem that may (but not necessarily) be parallelizable. - Rob Pike, Co-inventor of the Go language

Ramalho’s first paragraph of that chapter then paraphrases a Hungarian-born Brazilian mathematician and computer scientist named Imre Simon3: "…[he] liked to say there are two major sins in science: using different words to mean the same thing and using one word to mean different things."

So, we see, great books are based on avoiding sins of language.

A few Sundays ago, I attended the last day of a local Python conference, PyBay. The wonderful conference is in its 4th year, and I’ve attended all but one of them.

Ramalho gave a talk called “Beyond Paradigms” at 4pm.4 There was another talk I wanted to attend, but I couldn’t pass up the chance to see the author of such an excellent book. I sat near the front. As expected, the talk was good.

Luciano Ramalho speaking at PyBay 2019

During the question and answer session, a man a couple of rows behind me asked Ramalho for his thoughts on the practicality of learning new programming languages if one doesn’t have time to become an expert. The questioner cited the 10,000-hour rule popularized by Malcolm Gladwell as supposedly necessary to reach expertise.

Ramalho first stated that the 10,000-hour rule is not accurate. I was pleased he began with this. Gladwell popularized the concept without providing enough context, and the leading academic on expertise, Anders Ericsson, from whom Gladwell drew, highlighted this issue.5

Regardless of expertise, Ramalho mentioned that learning new languages illuminates the strengths and weaknesses of the languages we know best. This makes us better programmers in our primary languages. Ramalho himself is currently learning Elixir.6

Here are three more takeaways. Watch his talk7 and access the slides8:

  1. Read only the first 30 pages of the Gang of Four book9. Ramalho suggests there’s no need to read beyond that.
  2. Fixation on design patterns can lead us down the wrong path. Ramalho mentioned he spent many years tracking down a 1996 slide by the renowned computer scientist and director of research at Google, Peter Norvig. The slide states: “In a study of the Design Patterns book, 16 of the 23 patterns have qualitatively simpler implementations in Lisp or Dylan than in C++ for at least some uses of each pattern.”
  3. Learn complementary languages. Engage with languages that offer different feature sets than your favorites. If you’re familiar with Python, it might not be as beneficial to learn Ruby, as these two languages share similar strengths and weaknesses. In contrast, Elixir and Go serve as good complements to Python/Ruby.

  1. On Amazon: Fluent Python: Clear, Concise, and Effective Programming via local bookstores or Amazon ↩︎

  2. Luciano Ramalho profile at Thoughtworks and his two Twitter accounts:@ramalhoorg and @standupdev ↩︎

  3. Direct copy of Ramalho’s footnote: Imre Simon (1943–2009) was a pioneer of computer science in Brazil who made seminal contributions to Automata Theory and started the field of Tropical Mathematics. He was also an advocate of free software and free culture. I was fortunate to study, work, and hang out with him. ↩︎

  4. Talk description: “Java is object oriented and Haskell is functional. How about Python? Is it really OO with free-standing functions and porous encapsulation? Python has lambdas and closures, but is it functional? Are these useful questions? A better approach to learning of programming languages is to focus on features, not paradigms. This delivers practical advice for choosing patterns and understanding idioms." ↩︎

  5. Ericsson’s 2017 book - Peak: Secrets from the New Science of Expertise via local bookstores or Amazon ↩︎

  6. https://elixir-lang.org/ ↩︎

  7. PyBay 2019. If the videos are not up on Youtube yet, they will be soon. ↩︎

  8. Ramalho’s slides↩︎

  9. Design Patterns: Elements of Reusable Object-Oriented Software via local bookstores or Amazon ↩︎