Who Needs Java Modules After All?
Who Needs Java Modules After All?
Everyone. Or most people, at least. Modules' usefulness extends to nearly every facet of development, even to library devs with internal APIs.
Join the DZone community and get the full member experience.Join For Free
Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!
My answer is that X is a human being (minus platform developers, because that was a condition). We all need the module system to have safer code, resulting in more reliable systems, resulting in better performance in the business, resulting in a better economy, resulting in human happiness. Perhaps I went a bit too far with the conclusions, but the point is that the module system is needed by everyone in the industry, whether they’re aware of it or not. You will get it. First of all, we should start with the ob(li)vious answer to the question.
Very true. As a library developer, I want to design my libraries so that I separate the API. I want to separate the public interface from the implementation. This is what we programmers call “encapsulation.” We love to do it! We do it, because it is hilarious! We love it!
On the second thought, though, we do it because it is a tool to create reliable, bug-free (ha ha ha!) software.
It helps developers who use my code write better code. It is a bit like raising children. I, as parent, disallow certain things that they do — eat lots of chocolate, stay up late, and so on. And this is for their own good, even though they do not see or understand it at the moment. Later, of course, when they grow up and become parents themselves, they will understand and do the same. It is not much different with library developers and library-using programmers, except, perhaps, that programmers never grow up.
Similarly, I, as a library developer, need JPMS for the sake of the developers who are going to use my code. My library will not be better or worse just because I encapsulate. (Side note: It will be better, but not because of the fewer number of bugs in it.) I can easily get the implication that I, as a library developer, want JPMS the least. Who cares if you, dear programmer, shoot yourself using my library? It is your responsibility to call only the public API and not some frequently modified internal class and method. Or is it?
Not really. It is also my responsibility to create a library that is easy to use and hard to make mistakes using it. This is what we call usability. This is where JPMS comes into the picture. Without JPMS, I can document which packages are public and which are implementation specific. The contract between my library's users and I is that they will not use the private sections of my library. And for this good behavior, I will keep the public part of the library stable so that they do not need to change their code from release to release. (By the way, has anyone ever realized how literally bloody this name, JPMS, is? What the fly? PMS, really? Not to mention we're currently seeing all the cramps related to it: nomen est omen. It was not a lucky baptism.)
Let’s get back on our rail: Why do we need module system for that? Developers are disciplined people (ha ha ha!) and they do not want to harm themselves. They should not and will not use the internal code of the library. That is not good for them in the long run and they are well-aware of that.
The catch is the long run thingy. In the long run, we are all dead. There will be a point during the development, typically a few days before release date, when some of the internal APIs of a library just seem lucrative to be used. In some weird way, those internal calls are just exactly what you need. You know that you are not supposed to use them, and there is a good, well-mannered solution, but that needs more time to develop. But with the release date approaching, you do not have the time to follow that pattern. Not to mention feeling proud about the “I can do that,” “Look how well I know these tools” thoughts — instead of feeling shame for tampering with the parts of the library that are private.
That is where the Java Module System comes into the picture. You will not be able to do shortcuts. You will sigh remembering the good old days when Java was open to the whole world — whatever there was on the classloader (not to mention FORTRAN programming, am I right or, just the contrary, I am right?) but you will follow the rules because it just will not work otherwise.
You think that you are not vulnerable to such vanity as using the internal parts of a library. Here is a test: Did you recognize that I used the expression “internal APIs of a library”? If not, then feel ashamed, but don’t admit it. No need. The JPMS will help to forget things that do not exist, like internal APIs. Nonsense. The API is public. There is no such thing as internal an API. The resulting code will be better, easier to maintain, less prone to library upgrades, and thus cheaper at the bottom line.
In the long run, when we are all dead while our offspring create better code, having module-level encapsulation will be an obvious thing, just like world peace will be at that time.
So I need the Java Platform Module System. You need it. And everybody else needs it for a better world and for the sake of world peace.
Published at DZone with permission of Peter Verhas , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.