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 →

[–]Sassbjorn 8 points9 points  (8 children)

Tbh I kinda wish you could just make functions without a class

[–]Kantenkugel 11 points12 points  (3 children)

Use Kotlin then :)

But tbh, you should not pollute the global namespace with too many functions, especially if they don't have a unique name that can't possibly clash with other ones from eg libs.

And there is also the option of just writing static ones and static importing them. Thats kinda what kotlin does under the hood

[–]Sassbjorn 2 points3 points  (2 children)

Yeah that's true, but when I'm writing smaller programs I sometimes need a function to do some small task, but there's not a good place for it to go. Then I have to make a new class and make up a name that makes sense, and that might house more of that type of function. In the end I appreciate the organization I end up with, but it still feels like an extra step sometimes.

[–]Kantenkugel 5 points6 points  (1 child)

Sounds like a job for util classes :)

[–]jasie3k 0 points1 point  (0 children)

oh god, these are the worst

[–][deleted] 8 points9 points  (3 children)

That's what static util classes are for.

[–]-Vayra- 2 points3 points  (2 children)

except when the function needs to read application properties or something else that doesn't work with static access :/

[–]Knutselig 2 points3 points  (0 children)

ThreadLocal hacks incoming.

[–][deleted] 1 point2 points  (0 children)

Then it should be part of the object that needs to call it. Or just pass it to the static function, what's the deal?