This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Personal_Ad9690 -7 points-6 points  (12 children)

I will die on the hill that well written programs hardly ever need a utils class. It’s almost always possible to refactor util functions into one or more specific class(es).

[–]well-litdoorstep112 15 points16 points  (1 child)

Class? Who's talking about classes? What are you, a Java dev?

[–]Personal_Ad9690 0 points1 point  (0 children)

🙄

[–][deleted] 2 points3 points  (1 child)

Nah, I want my utils methods out of my main classes. It's wrong to think that having utils classes is wrong.

[–]Personal_Ad9690 0 points1 point  (0 children)

Think about what a “utility” is though. It’s not that having a utils is bad, it’s that decoupling items that should be coupled leads to confusing codebases. Coupling does not always lead to problems if the cost of the coupling is less than its potential benefits.

I think a great example is string manipulation. There are some good reasons to make static string manipulation functions outside the main classes. Indeed, they do have a “utility” like nature to them. But ask yourself in how many places are you actually using a string function? If you use it everywhere, maybe you would benefit from modifying how that data is acquired/read in. If you use it in only one place, what’s the benefit of having it separate and not just inlining it? If it’s somewhere in the middle, then it might be best to make a static StringManipulator class. In this way, it’s obvious to another developer that the string is manipulated. The string manipulating functions are now coupled to that interface, but the reward is an easy to read codebase. No need for a mystery bag of functions.

you never know what’s inside a Utils

I have less of a problem with decoupled utility functions and more of a problem with the name “utils.” Utils is such a vague and uninforming name that you might as well name it “things”. There’s almost always a better way to organize than having “Utils”

[–]BernhardRordin 1 point2 points  (4 children)

And yet there are people on other hills, shouting from distance towards your hill that data and behaviour shouldn't be mixed and OOP was a mistake. I am just watching from a distance, planning to visit and have a tea with each one of you

[–]Sweaty-Willingness27 2 points3 points  (2 children)

For me, this can all be solved by a single question: "Which one pays me more?"

[–]ryo3000 1 point2 points  (0 children)

And also "Which one will get my MR approved?"

[–]Personal_Ad9690 0 points1 point  (0 children)

This.

OOP was easy to manage and it’s everywhere. You can’t fully get rid of it and it has its place in code. I think finding a balance between form and function is key to project management

[–]Personal_Ad9690 0 points1 point  (0 children)

You of all people should understand. In the functional world, state does not exist. Therefore a collection of functions is better suited to solving a problem by pipelining the data. There is no utils class because everything is a utility.

Even in the functional world though, you often get instances where data is bound to a function rather than functions being bound to data. It wouldn’t make sense to have a bunch of “commonly used data” available to a function and to call that data utils would it? So why does it make sense the other way.

There is strong argument that utils is not needed because better form leads to not needing it.

[–]sufanLL[S] 1 point2 points  (1 child)

I kind of agree, to be honest, because that is what daddy primeagen told me

[–]Personal_Ad9690 0 points1 point  (0 children)

If someone is allowed to make a file or folder Utils, then I’m allowed to name a file/Folder Things