By Peter Lovett

The Virtues of Being Lazy

Main Conference Ballroom 3 Saturday at 11:20am - 11:50am

The virtue of being a lazy programmer, understanding lazy evaluation, and understanding lazy imports (3.15)

Your boss wants your program to "run faster". But performance can be a tricky thing. Sometimes we can make a choice of when the program will be slow. This talk will explore the "virtue" of laziness with regards to programmer approach, and lazy evaluation (with generators and yield). But mainly the talk will focus on the new 3.15 keyword lazy and how it can affect module loading times.

This talk will cover briefly the role of “laziness” in being a programmer. I will then examine the role of laziness in evaluation (generators and yield). That will lead us to laziness in imports.

The main focus of this talk will be on lazy (on-demand) imports and the new lazy keyword in 3.15, and how that can significantly improve your program’s start up speed, and lower memory consumption. I will cover detail about the new feature, and how to control whether an import is lazy or eager. Also covering some new terminology, including lazy, eager, elide and reification. Some alternative approaches will also be considered.

Particularly if you have a CLI program that has different behaviours based on switches, this can make a big difference.

Lazy imports are an accepted new feature in 3.15 (final due October 2026), and I will be live demonstrating with pre-release Python.

Peter Lovett

Peter Lovett

Peter Lovett is an accomplished programmer, developer, speaker and educator. He has more than a four decades of paid programming experience, working with many languages, from Assembler and C to Perl, C++, Java and Python. The son of a programmer all three of his sons can program in Python (although the youngest is a musician). He brings wide and diverse experience, deep technical knowledge, an engaging presentation and directly useful information to his audiences. He has spoken at many PyConAu’s, and at LinuxConfAu on Python, and runs training courses through his company, Plus Plus, running courses for some of Australia and New Zealand’s biggest companies. He can be found at www.plusplus.com.au