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

You still have to put each method in some class in java, in C++ you can just put it in namespace. It makes more sense, even if in practice the difference is minimal.

> there is still need of standalone functions in OOP

Yes, and that's what I've shown?




It's a syntax issue. Final class with private constructor and all members being static is effectively a namespace.


I think it's more than just syntax - it's culture. In C++, free standing functions has been a part of the culture of the language since the beginning. The design of the language encourages them - there are even cases, such as operator overloading, where it's preferable to implement it as a free standing function rather than a class method. In Java, when I write a class that is a collection of static methods, I feel like I'm fighting against the language and it's culture, even though they are sometimes used.


How much do you write code on Java?

Such functional namespaces were part of Java from the very beginning (Math is a good example and with release of Java 8 now there are many more in standard library). I have not seen an enterprise project yet, in which there's no something ending with Utils or Helper, that is just a collection of functions. Such naming is an anti-pattern, of course, but still, almost every developer in Java world uses this and has it part of it's development culture.


> Such naming is an anti-pattern, of course

This is exactly the cultural problem with too strict adherance to OOP :)

It's like people saying "nails are anti-pattern of course, but people still use them, so we've added hammer-heads to our screwdrivers".


Yes, that was the point I was getting at. It's obviously part of how real Java code is written, but I feel like I'm going against how the language was designed when I do it. (Clearly, everything is not an object, and a class is not always the most appropriate way to group code.)




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

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

Search: