Better Programming

Advice for programmers.

Member-only story

3 Things to Consider When You Define Functions

Yong Cui
6 min readJul 11, 2022

--

Photo by Asyrafunk RKTW on Unsplash

The core of any application is data. If you’re building a social networking website, the users and their friendships are the data. If you’re building a game, the graphics and the user operations are the data. If you’re building an online shopping store, the product and client information are the data. These are just a few examples in our daily life.

The data are not very meaningful if they’re presented in their raw form. You must define specific operations to process the data before they can be presented. These specific operations typically take the form of a function — a block of code that accepts input, applies the operations, and generates output. I’d say that functions are the underlying driving force for any programming project.

In this article, I’d like to summarize three things that you can consider as a Python programmer when you write functions.

Please note that I’ll not include some common best practices in defining functions, such as sensible names, dedicated purposes (not mixed concerns), and proper docstrings. Instead, my angle is more from the technical perspective.

Without further ado, let’s get it started.

Using Default Arguments

--

--

Yong Cui
Yong Cui

Written by Yong Cui

Work at the nexus of biomedicine, data science & mobile dev. Author of Python How-to by Manning (https://www.manning.com/books/python-how-to).