https://kotlinlang.org logo
#getting-started
Title
# getting-started
c

Colton Idle

12/12/2021, 9:15 PM
I had some hidden string formatting in one of my classes, and now that I want to write a test for it, I pulled it out into it's own class. It's your typical "Should I create a StringUtils class?" sort of question. Should I have
Copy code
class StringUtil {
    fun getInitialsFromName(name: String): String {
or just create
Copy code
class InitialGeneratorService {
    fun get(name: String): String {
Or should it be a companion or just make a string extension method (seems easily abused though) I'm definitely overthinking it, but approciate any advice
b

bezrukov

12/12/2021, 9:24 PM
Usually util function in kotlin either a top-level function (remove StringUtil class declaration and move your fun outside) or member of an
object
(use
object StringUtil {
)
a

Adam Powell

12/13/2021, 2:42 AM
in case that's a real example and not a fictional one, https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/
2
2 Views