DEV Community

Cover image for The Art of doing nothing: Python Edition
Fortune Adekogbe
Fortune Adekogbe

Posted on

The Art of doing nothing: Python Edition

Writing programs can be stressful. As a developer, I have never been one to always pen down pseudo-codes before writing my first lines of code so it happens that at some point I do not know what to write. Also, when writing modular scripts, I define all classes/functions and their doc-strings at the start before completing them one after the other.

This means I had to find ways to make empty classes or functions not raise errors when the script is run. I have discovered a couple of ways to do this and I will be sharing them in this article. Whether you are like me or not, I do not doubt that you will find this interesting and useful.

The package called nothing

The mere fact that a python developer created this is quite fascinating. Here we have a package that contains nothing but a version number and a one-sentence description in its init file. In fact, this is the only description for this package on Github and PyPI, nothing else. Like every other package, it can be installed with pip via the command pip install nothing.

Once it is installed, we can import nothing and then use it as a placeholder as shown below

The pass statement

This is the more popular option. pass is an inbuilt null statement in python that is used to stand in for code that is yet to be written. Its inbuilt nature makes it most python developers goto statement for code blocks that are to do nothing. It is used like the nothing package as we'll see in the image below.

Alt Text

Ellipsis (...)

In the English language, an ellipsis is used when omitting a word, phrase, line, paragraph, or more from a quoted passage. In Python, however, an ellipsis is a single object with no methods that serve a range of functions from multi-dimensional array slicing to type hinting but we will be focusing on its use as a placeholder. This is a personal favourite because I find the similarity between its use case in python and regular English texts interesting. We see it used in the image below as a part of a recursive function with only the base case specified.

Alt Text

The final straw

This last case is quite intriguing. Its something you would have thought of at some point and simply put, it is leaving your editor empty. Why type when you are not ready yet? Finish up that pseudo-code then open your editor and code away. Yes, this is a message to me tooπŸ˜‚

Alt Text

I hope I successfully communicated the art of doing nothing in Python to you all and that this was enjoyable.

Top comments (6)

Collapse
 
wolzcodelife profile image
Joel Adewole

The final straw for meπŸ˜‚πŸ˜‚πŸ€£πŸ˜‚πŸ˜…

Very educational btw, nice job

Collapse
 
enutrof profile image
Fortune Adekogbe

Thankss

Collapse
 
davidsanchez profile image
David N. Sanchez

Thank you! I was not aware of he nothing package. I'll have to check that out.

Collapse
 
enutrof profile image
Fortune Adekogbe

You're welcome

Collapse
 
primadev2 profile image
Primadev

Great jobπŸ˜‚πŸ˜‚

Collapse
 
enutrof profile image
Fortune Adekogbe

πŸ˜‚. Thanks a lot