Member-only story

Having only One Return statement is Better and More Safe

Stefan Schindler
7 min readApr 2, 2021

--

Functions in programming languages are incredibly useful: They are designed to take input parameters, do something with them, and output a result. This conforms to the well-known IPO model (Input, Process, Output). However some developers tend to interrupt that process, making it harder to follow and thus understand a function, and risking evil and nasty bugs.

Let’s see why not always all roads lead to Rome.

Picture by Markus Winkler (text modified by me)

Understanding functions of other developers

Imagine you need to understand the source code of someone else’s function. This is totally not rare, because whenever you add something to a project, or even use an external library, you have to understand what you are going to do (except for some conscience-lacking StackOverflow copy & paste engineers, of course).

With external libraries, documentation is what you usually consult. But in projects, you rather read source code of other people (that includes yourself when the source is older than 2–4 weeks, because that’s literally the same).

Now, there are several things that a developer can consider to make source code readable and thus understandable. Some are well-known and -adopted, like properly naming functions.

--

--

Written by Stefan Schindler

Developer who likes Python, Django, (Neo)Vim, HTML & CSS, DDD, EDD, TDD and everything related to writing good code.

Responses (2)

Write a response