Hacker News new | ask | show | jobs
by kaba0 1068 days ago
How is a class that holds a static method/function any different to simply namespacing? Never understood people’s problem with that. For example, what’s the problem with Java’s Math “class”? It only has stateless math functions like any other language, nothing is forced on you.
1 comments

It does not have to be a problem in terms of it working or not.

The problem is rather, that a class comes with loads of conceptual baggage. It is conceptually not fit for the purpose of merely namespacing.

A good language will have a concept fit for the purpose of namespacing. Either something directly called "namespace" or something that is meant to namespace things, like modules. A class is rather for grouping methods that interact with the state of the objects.

Of course, if you don't have anything else available, you gotta take what you have. It will not serve making the code more readable though, as a potentially new reader of the code will expect a class to be instanced somewhere, as is typical for classes. It can lead to confusion. If there was however a concept "namespace", they will immediately know that it is for grouping a category of things.