Pydon'ts

Write Beautiful Python Code

Rodrigo Girão Serrão

Abstractions Best Practice Clean Code Python Skills Python general

See in schedule

What makes a (Python) program elegant, or beautiful, is often subjective.
However, it is generally well-accepted that idiomatic Python code is elegant, and idiomatic Python code is generally more readable, it can be easier to maintain, and it can help you find bugs in your programs, to name just a few potential benefits.
Therefore, it seems like a no-brainer that people should strive to write idiomatic code!

Sadly, I have heard people say "that is too clever, you can't write that in production" when confronted with Python code that is just making the best use of the core functionalities that Python provides.
Because Python is often used as a glue to put together the amazing functionalities of the many libraries within the Python ecosystem, Python programmers often do not learn how to make the most out of the core features of Python, the features that you can access without having to type "import"... and when they do, they are often next to someone who has not learned how to appreciate Python's expressiveness and power...
The scenario I just painted is the absolute worst-case scenario you could be confronted with, but even well-versed Python programmers do not know all the little idioms and typical use-cases of all the features that Python provides and hence can step-up their programming skills by learning new patterns and use-cases.

In this talk I show what idiomatic Python code looks like and illustrate how the subjective notion of "beautiful", or "elegant" code, can make your code objectively better, regardless of your Python skill level.

To achieve this purpose, we will take a look at some interesting usage patterns of "vanilla" Python and see how those fit in real code written by real people, often drawing examples from the Python Standard Library itself.

There are no prerequisites for this talk, and both advanced users and beginners can benefit from it.

Type: Talk (45 mins); Python level: Beginner; Domain level: Beginner


Rodrigo Girão Serrão

Dyalog Ltd.

Rodrigo has always been fascinated by problem solving and that is why he picked up programming – so that he could solve more problems.
He also loves sharing knowledge, and that is why he spends so much time writing articles @ mathspp.com and giving workshops and courses.

His main areas of scientific interest are mathematics (numerical analysis in particular) and programming in general (with a preference for the Python and APL languages), but Rodrigo also enjoys reading fantasy books, watching silly comedy movies and eating chocolate.