DEV Community

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

Collapse
cutiko profile image
Erick Navarro

No, just an indicator that better organization is needed.

  • Grab the utils file and put it inside the package were is used
  • If it is used globally then assign its own package for it
  • Do you need utils in the name? Most probably dont, is about text? text/Trimmer? text/Validations? text/Regex? text/Rules? Is it about files? file/InternalStorage? file/Writer? And so on and so on
  • In some languages like in Kotlin or Js, yiu can choose, go simple with a functions file or actually scalate it to a class
  • Add testing for it
Collapse
noway profile image
Ilia Author

I don't really use namespaces, I kinda a fan of just making every exportable symbol in a project to be unique. Sometimes that means you have names which are slightly longer than appropriate, but I deem that an appropriate trade off against using packages in general, which are way more harder to manage/refactor.
So whatever would be in Utils would be global for me. Trimmer, Validations, Regex, Rules. Most likely it would be named TextTrimmer, TextValidations, TextValidationsRegex, TextValidationsRules etc, in order to avoid collisions with other symbols.
In my view, TextValidationsRegex would be quite possible to even publish as a package, even though it probably would be too opinionated for general use to actually do that, therefore it would just reside in Utils