3 ms·
> in the JVM classes are an obligation You're always free to use a final class with a private constructor as a namespace for static methods. Many classes in th
by Twisol 4y ago
> in the JVM classes are an obligation
You're always free to use a final class with a private constructor as a namespace for static methods. Many classes in the standard library are of this kind, including `Math`. It's not ideal (see my next point), but it's a far cry from adding extra object instantiations everywhere.
> E.g. in python functions from imported modules easily litter your namespace
I think this is more a problem with the modularity features in a language than free functions themselves. In Python, Haskell, and Agda, I make sure that every symbol I use is explicitly imported (or defined in the same file). This makes it way easier to trace where each symbol I use is defined.
You're basically forced to do this in Java, too, with exception of wildcard static imports, which I very rarely use.
> if I have a python module universe my colleagues hate it if I import the module and call a function like universe.create() [instead of Universe().create()]
They hate it? I can understand if your colleagues aren't developers by trade, but I expect anyone who maintains code for a living to understand the language they're using. There will always be dark corners, but this ain't one.
- watwut 4y ago> You're always free to use a final class with a private constructor as a namespace for static methods. Many classes in the standard library are of this kind, including `Math`. It's not ideal (see my next point), but it's a far cry from adding extra object instantiations everywhere. And you literally gained nothing. You do exact same thing with slightly different syntax.
- sagarm 4y agoA version of Math that had non-static methods instead of static ones would be strictly worse IMO. Extra allocations, extra line noise from instantiations, very likely many users would start keeping Math objects around as local, member, or even static (lol) variables.