4 ms·
I believe you can achieve the same in Java by static import. EDIT: Also, I think the parent comment was not complaining about the missing possibility of creati
by odabaxok 10y ago
I believe you can achieve the same in Java by static import.
EDIT: Also, I think the parent comment was not complaining about the missing possibility of creating standalone functions, but rather saying that not every functionality can be forced into objects, i.e. there is still need of standalone functions in OOP.
- ajuc 10y agoYou 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?
- ivan_gammel 10y agoIt's a syntax issue. Final class with private constructor and all members being static is effectively a namespace.
- scott_s 10y agoI 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.
- ivan_gammel 10y agoHow 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.
- ajuc 10y ago> 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".
- scott_s 10y agoYes, 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.)