DEV Community

Discussion on: Are utils (folder where you put random stuff you don’t know where to put otherwise) a code smell?

mirroar profile image

For personal projects / tinkering, I'd say it's fine.

If it's more serious code, I think it warrants thinking about the design of every component, coming up with a good name, and having a place to put it. If you spend the time to structure your code well, you save others time when they work with your code.

Basically, I think of it this way: If I come into your project and don't know much about it, but I'm trying to find the source of a bug, I'll start by looking at the directories and files. If I find a file "PdfGenerator", I can pretty safely guess if it's relevant to my problem or not. If I find a file "PdfUtils", I'll be less certain what's in it, and might have to look at it more in depth. If I find a "HelperClass", I have no way of knowing what's in there and will have to look at the source to see if it's even relevant.

noway profile image
Ilia Author • Edited on

GOOD point!! it reduces the code discoverability, now that you mention it I come to think that I felt that too. Yeah, I can imagine that if Utils gets very long and a lot of stuff is put into it, it's a sign of some spaghetti problem.

Come to think of it, in my view, Utils is something more of 'stdlib extensions'. Not some abstractions of your business logic code from all over the place which you didn't have a better judgement to put in the same domain with other business logic, but rather things you missed from your stdlib, something that cross cuts all functional areas of the your app and is more of a platform-needed invention, rather than your business differentiator invention.