4 ms·
> In Java the top level only contains classes and interfaces. This design makes sense from conceptual purity, but Java is never a conceptually pure language. I
by xiaq 8y ago
> In Java the top level only contains classes and interfaces.
This design makes sense from conceptual purity, but Java is never a conceptually pure language. It distinguishes value types and object types, for instance. Not allowing free functions is really just a poor design choice.
Worse, the proliferation of single-method interfaces (which are really just functions) and static methods (which are in most cases really just free functions) really prove that free functions are useful. Java just makes it harder to use them.
- jayd16 8y ago>Not allowing free functions is really just a poor design choice. I don't see why. The verbosity is pretty minimal and you enforce the availability of a privacy scope you wouldn't have had. ie private static methods and members that your public statics can use. Although, pure functions are nice if you can't trust the code you're calling won't surprise you.
- tasuki 8y agoI think this has to do with naming. Naming is generally hard, with free functions you must name the function, in Java you must also name the class. If you could show some examples of single method interfaces whose naming makes sense, I'd be delighted!