Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Does Python Itself Follow the Advice

Resource mentioned in this lesson: Chris Neugebauer’s Talk

00:00 Chris Neugebauer delivered an excellent talk at PyCascades in 2023 on the subject of whether or not Python manages to follow the advice found in the Zen of Python.

00:10 Two of the features he examined were decorators and type hints.

00:14 Decorators allow developers to modify functions without changing their code. This can result in very clean code. For example, when using the Adventurelib game library, you can add commands using the @when decorator, which is extremely readable.

00:29 However, this can be considered implicit because the decorator syntax hides the code that is running in the background. It is unclear what effect the decorator is going to have.

00:39 In Python, you do not need to tell a computer what type of data a variable is storing. However, you can optionally label your types using type hints. This makes your code more explicit.

00:50 But trying to be precise with your type hints can get complicated fast. For example, the image parameter in this function is a two-dimensional list of tuples of integer values.

01:01 Now our readability has suffered. This might leave you wondering if type hints are such a good idea. As Chris says in his talk, the response to these points is to consider the boost in productivity and practicality that these features bring in their comparison with the guidelines they are straying from. This is a good reminder that a lot of coding decisions are a balance between convention and practicality. With that note on balance, you’ve arrived at the end of the course.

01:27 In the following summary lesson, you’ll look back on everything you have learned.

Become a Member to join the conversation.