Affiliate disclosure

Book titles on this page link to Amazon. As an Amazon Associate, DataField.Dev earns from qualifying purchases — at no additional cost to you.

Further Reading: Functions — Writing Reusable Code

Function Design and Clean Code

  • Martin, R. C. (2008). Clean Code: A Handbook of Agile Software Craftsmanship. Prentice Hall. Chapter 3: "Functions." (Tier 1) The definitive guide to writing clean functions in professional software. Martin's rules — functions should be small, do one thing, have descriptive names, and have few arguments — are widely adopted industry standards. The examples are in Java, but the principles apply directly to Python.

  • Hunt, A. & Thomas, D. (1999). The Pragmatic Programmer. Addison-Wesley. Chapter 2: "A Pragmatic Approach." (Tier 1) Introduces the DRY principle ("Don't Repeat Yourself") and the concept of orthogonality — designing components that are independent of each other. Both ideas map directly to function design. The 20th Anniversary Edition (2019) updates the examples for modern development.

Python-Specific Function Topics

  • Lutz, M. (2013). Learning Python, 5th Edition. O'Reilly. Chapters 16-21. (Tier 1) The most comprehensive coverage of Python functions available. Covers everything from basic definitions to advanced topics like closures, decorators, and generator functions. Chapters 16 (basics) and 17 (scopes) are most relevant to this chapter.

  • Python Official Documentation: "Defining Functions" (Tier 1) https://docs.python.org/3/tutorial/controlflow.html#defining-functions Python's official tutorial on functions. Concise, accurate, and authoritative. A good place to check your understanding of def, return, local variables, and None.

  • Python Official Documentation: "More on Defining Functions" (Tier 1) https://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions Covers default argument values (including the "Important warning" about mutable defaults from section 6.10.1), keyword arguments, *args, **kwargs, docstrings, and lambda expressions. Goes slightly beyond what this chapter covers — good for readers who want to go deeper.

The Concept of Abstraction

  • Abelson, H. & Sussman, G. J., with Sussman, J. (1996). Structure and Interpretation of Computer Programs (SICP), 2nd Edition. MIT Press. (Tier 1) The classic computer science textbook that treats functions (procedures) as the fundamental building block of programs. Chapter 1 builds up from simple functions to complex abstractions in a way that permanently changes how you think about programming. The examples use Scheme, not Python, but the ideas carry over. Available free online from MIT Press under a Creative Commons license.

  • Denning, P. J. & Tedre, M. (2019). Computational Thinking. MIT Press. (Tier 1) Places abstraction in the broader context of computational thinking. Shows how the ability to create and use abstractions — functions being the most fundamental — is what makes computer science a distinct intellectual discipline.

Docstrings and Documentation

  • PEP 257 — Docstring Conventions (Tier 1) https://peps.python.org/pep-0257/ The official Python Enhancement Proposal that defines docstring conventions. Short but authoritative — this is the standard that Python's community follows.

  • Google Python Style Guide: "Docstrings" (Tier 2) https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings Google's internal Python style guide has an excellent section on docstrings that balances completeness with readability. Many open-source projects follow this style.

Scope and Namespaces

  • Sweigart, A. (2019). Automate the Boring Stuff with Python, 2nd Edition. No Starch Press. Chapter 3: "Functions." (Tier 1) A practical, example-heavy introduction to functions with good coverage of scope. The scope explanation is particularly clear for beginners. The free online version at automatetheboringstuff.com is now the 3rd edition (2025), where functions are Chapter 4.

For the Curious

  • Ramalho, L. (2022). Fluent Python, 2nd Edition. O'Reilly. Chapter 7: "Functions as First-Class Objects." (Tier 1) Explores the idea that functions in Python are objects — you can pass them as arguments, return them from other functions, and store them in data structures. This goes well beyond the current chapter but previews powerful concepts you'll encounter later. Recommended after you're comfortable with Chapters 6-12 of this textbook.

  • Raymond Hettinger, "Transforming Code into Beautiful, Idiomatic Python." PyCon US 2013 talk. (Tier 2) A widely celebrated conference talk that demonstrates how to refactor Python code into clean, idiomatic patterns. Available on YouTube. Two of its tips connect directly to this chapter: clarify function calls with keyword arguments, and make multiple return values easier to read. Much of the rest covers loop and dictionary idioms you'll appreciate after Chapters 8 and 9.