2

Quoting from this source, it mentions that

The name of the directory containing a module’s sources should be equal to the name of the module, e.g. for de.consol.devday.service

Is this a good recommendation consider that folder name is subjected to character limitation of the operating system (eg 255 as the maximum length for Windows ) and that could constraint on how we name the folder and module?

Hoping that someone from Java core team can give insight on this and provide a recommendation.

Quoting another example from here:- enter image description here

The module name follow the folder name and folder name is constraint by 255 character limit, is that scalable?

It may be that in actual code, most likely the folder name may not reach that limit, however such limitation should be mentioned in official Java doc to consider such way ( maybe it has ? or someone can point to that if so ?)

thank

Naman
  • 27,789
  • 26
  • 218
  • 353
Macdevign
  • 286
  • 4
  • 5

3 Answers3

2

Though I am not from the java core team as you might expect but The State of the Module System reads it as this-

A module declaration is compiled, by convention, into a file named module-info.class, placed similarly in the class-file output directory.

The character limitation of the operating system could constraint on how we name the folder and module but ideally, IMHO even 255 characters are more than sufficient to dictate any good naming convention and design.


Just to add to it, the module-info.java declaration is similar(module vs package) to the existing package-info.java declaration except for the fact that the latter was used only for documentation purposes.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • How do we structure the source code to conform to modular way ? Further reading on http://www.baeldung.com/project-jigsaw-java-modularity also follow the same practice as what I have raised. Does IDE like Intellij work that way too ? – Macdevign Sep 28 '17 at 02:36
  • 1
    To confirm to the modular way, you must include the class named `module-info.java` which provides its module declaration, – Naman Sep 28 '17 at 02:57
  • I understand that the module-info.java is essential. But the question is what is the recommended way to layout the modular project structure in term of physical source layout ` – Macdevign Sep 28 '17 at 02:59
  • 1
    The recommended way is as suggested in both the linked articles by you, as well as the linked document by me. The `module-info.java` of module `com.foo.bar` to be defined within `com.foo.bar` directory. – Naman Sep 28 '17 at 03:06
  • the question is how scalable this way is when directory is constraint by the folder name limitation ? what if I have come to a point where the whole name exceed 255 characters ? The point I raising is not so much of just simply following the suggested way but thinking further along the line whether such way is scalable as mention in the post :} . If there is indeed folder & module name sync could be a issue, why are those sites still suggest those way ? – Macdevign Sep 28 '17 at 03:23
  • 1
    Well, I am not sure what scalability issues you see with the naming conventions and believe the syntax of module-info must have been debated in the mailing lists as well, just not able to find one to share with you for now. – Naman Sep 28 '17 at 03:44
  • Why would we expect you to be from the java core team? – Jacob G. Sep 29 '17 at 12:06
2

Naming modules as the top package is a should, not a must. See for example JSL 6.1.

The name of a module should correspond to the name of its principal exported package. If a module does not have such a package, or if for legacy reasons it must have a name that does not correspond to one of its exported packages, then its name should still start with the reversed form of an Internet domain with which its author is associated.

I would consider Windows 7 a legacy reason (MAX_PATH = 260 characters). Workaround: use subst to assign a drive letter to a folder or update to Windows 10, which has an opt-in of 32,767 characters.

A package name with 260 characters rendered in Monaco 13 exceeds the width of my 23'' monitor by 20 characters. It’s common sense that I shouldn’t have to scroll horizontally to read a module name. Note that in the JDK 9 (+20,000 classes) the longest module name is 32 characters:

for file in $(/usr/libexec/java_home -v 9)/jmods/*; do echo -n `basename "$file"` | wc -m; done

Oracle doesn’t even follow the rules. If you want to import java.util.logging.Logger you import java.logging, not java.util.logging. And no, java.logging it’s not the main package, it is java.util.logging:

$ cd $(/usr/libexec/java_home -v 9)/jmods/
$ jar -tf java.logging.jmod 
classes/module-info.class
classes/java/util/logging/ConsoleHandler.class
classes/java/util/logging/ErrorManager.class
classes/java/util/logging/FileHandler$1.class
classes/java/util/logging/FileHandler$InitializationErrorManager.class
...
Jano
  • 62,815
  • 21
  • 164
  • 192
1

While most discussion here focuses on the module name, let me add that the directory layout as shown in the question is mandatory only for what JEP 261 calls multi-module mode. Build tools and IDEs are free to support different directory layouts. Note how JLS 7.3 delegates some decisions to the "host system":

The host system may determine that an observable ordinary compilation unit is associated with a module chosen by the host system ...

Here, every tool used for driving modular compilation can be considered a host system.

With this, it should be no problem to give the folder containing sources for a module any useful, short name you like.

Stephan Herrmann
  • 7,963
  • 2
  • 27
  • 38