Post AYqsXZIV0ReSU6w2TY by hazz223@mstdn.social
(DIR) More posts by hazz223@mstdn.social
(DIR) Post #AYqsXXJ8P6yIJVDWBk by hazz223@mstdn.social
2023-08-18T09:19:07Z
0 likes, 0 repeats
I really dislike Utils classes in Java. They never age well, tend to make life very difficult to test, and spread all over the code like goo. Avoid them!(Unless you're writing a library like StringUtils - that's a different kettle of fish)#Tech #Code #Programming #Java #Architecture
(DIR) Post #AYqsXYKwZs0rVP4TeC by alexelcu@social.alexn.org
2023-08-18T10:10:15Z
0 likes, 0 repeats
@hazz223 So where do you put functions?
(DIR) Post #AYqsXZIV0ReSU6w2TY by hazz223@mstdn.social
2023-08-18T09:20:05Z
0 likes, 0 repeats
"But, i need to write this as a Utils! Where else would it go" - I've heard that a lot. Break it down. You might end up with a few more classes, but it'll be worth it in the long run - being specific and well tested. I've not written a Utils class in years. It's possible.
(DIR) Post #AYqyBS8HZ051cLzgnI by hazz223@mstdn.social
2023-08-18T11:13:28Z
0 likes, 0 repeats
@alexelcu With Java, usually small and well defined classes that attempt to do one small domain well. Makes them easy to test, highly composable, and friendly to refactor.
(DIR) Post #AYrIEe1xmVQMTFq03M by alexelcu@social.alexn.org
2023-08-18T14:58:12Z
0 likes, 0 repeats
@hazz223 A plain function is always much simpler to compose and test than a class. Forcing a class-based design whenever plain functions would do is what makes Java complicated.An Utils class is just a package of functions. Normally problems happen because we have a hard time with organizing things, and finding them later, but this is an issue with packages in general, and discovery could be greatly helped by conventions or tooling.
(DIR) Post #AYrIX8bipuxeW1NjtY by alexelcu@social.alexn.org
2023-08-18T15:01:32Z
0 likes, 0 repeats
@hazz223 I did feel some pain in our $work projects. Utils classes/packages do need some design coherence, instead of being dumping grounds for whatever doesn't fit elsewhere.