Best Practices (Functions)
January 17th, 2025As we begin the development cycle of our Let’s Launch a Game project, now is a good time to review general guidelines for writing clean code. While we have been working to maintain uniform formatting, informative naming schemes, and explanatory comments, there are other development philosophies that we can focus on to improve our code. Personally I found my research into common code smells the most useful. One design pattern that I think I often fall victim to is having Middle Men functions.
A Middle Man is a function that relies mostly as an intermediary between other functions. Removing Middle Men improves readability and can prevent potential downstream issues in future development cycles. Where I run into this issue most often is when I am contributing to an established codebase and don’t fully grasp the scope of an established function. I will often add additional functions within this function to do the bulk of the work. Paired programming and code reviews are one way to avoid this misunderstanding.
The figure below is an example of a middle man function. Within “Minion”, the main functionality is referencing is_frontline, this could be updated to a single call within action.

Figure 1 via: https://luzkan.github.io/smells/middle-man
Going forward I intend to avoid using Middle Man functions.
Something I would like to start doing more of is writing shorter functions. This may seem to be an opposing issue to writing fewer Middle Man functions, but I think writing shorter functions can actually facilitate a clearer hierarchy. When a function isn’t bloated and sticks to its intended utility, the code becomes much more readable and reusable. In terms of design principles this might often be referred to as using SRP or the Single Responsibility Principle.
References:
https://www.opsera.io/blog/what-is-code-smell
https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988cf8d29