Hacker News new | past | comments | ask | show | jobs | submit login

This was running through my head as well, and means that your software design is bad. If you have such a useful function that you can translate it among classes, it should sit in some sort of static Util class. Think of it as the Swiss Army Knife you carry in your regular toolbox, a go-to tool, when you know you don't need anything specialized.



You can, but the better your standard library, the less you need specialized functions. For instance, instead of something like:

    response.setHeader("X-Foo", "Bar");
In a functional language we'd change the data structure directly:

    (assoc-in response [:headers "X-Foo"] "Bar")
If, for instance, 90% of your application can be factored out into static methods, OOP starts to look like the wrong paradigm.


A lot of static methods on a Util object strikes me as a smell in the context of this discussion. In OO-land it's not a smell per se because often you have no alternative. But functionally your class is a glorified namespace.


What do you mean? I don't believe anyone is suggesting that if you have many static methods or functions, they should all be put in one namespace.


I think that's exactly what dclowd9901 was suggesting, though he may not have fully considered it.


Not necessarily. Of course defining classes is tricky, and there's no such thing as a rule of thumb, and that's more what I was trying to relay with my comment. And I agree with others who are saying that a piece of software where objects are crammed with tons of static classes is bad OOP.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: