Home © Rinat Abdullin 🌟 AI Research · Newsletter · ML Labs · About

Utility Classes are Lesser Evils

Generally, code reusability (and Don't Repeat Yourself principle) are a big evil, if used without constraint. They can couple together really distant concepts, while increasing overall complexity of the code.

Did you ever have an utility class, which was introduced for a single purpose, but ended doing up everything at once?

That's why at Lokad we try to avoid utility classes. Especially if they have only a few uses spread across different parts of the project. Such code can be inlined instead.

However, sometimes, utility method is relatively complex and big. Plus, it can be used in too many places inside a single project. In such case we agree to introduce utility class (which is internal for this project) and put it into well-defined location (folder and/or namespace) called "LesserEvils", while adding "Evil" suffix to the class names.

Name somehow allows us to stay more conscious about abuse of common utility classes and potential coupling they can introduce into a project. Lesser of evils is still an evil.

Published: January 25, 2013.

🤗 Check out my newsletter! It is about building products with ChatGPT and LLMs: latest news, technical insights and my journey. Check out it out