I do take your point about the standards committee probably not even contemplating this.
I’ve never programmed in C++ although I am familiar with object-oriented concepts. And it must be said that the FTN95 help (section “Modules”) does make passing reference.
Quote: “A MODULE can also contain the definition of user-defined types together with the definition of procedures that are common to a number of program units. Some of these procedures may be used to create user-defined operators. In this respect, a MODULE can be designed to be 'object oriented'.”
In your example modules A and B, I take your point that module A has to be made available to users of A or B, otherwise they cannot compile their program. However, that doesn’t mean they are forced to put a “USE A” statement in their program if they only need to USE module B.
I agree with you that users can access variable x directly from module A. However, with my interpretation of the PRIVATE statement, they have to explicitly state they are going to USE A. I think that’s only right and proper and, to my mind, does provide some protection of x. With the FTN95 interpretation they can access it without doing USE A and I think there is the increased possibility they could inadvertently corrupt it.
If you want a variable to be private then you should design your modules so that it is defined as private in the base module.
Yes, but that is not quite what we are talking about. We are talking about entities that need to be exported to a higher-level module but no further.
Perhaps I should put all this into some context. I’ve written some, what I regard as, “low level” modules that implement a Stack, a Dictionary, a Buffer, and a few other esoteric things. Then I have “intermediate level” modules implementing a Document and a Notation. These modules are then used in a “top level” module (let’s call it module Top), which is the only module my users will ever need to reference in a USE statement.
So, I tell my users to place the statement, “USE Top”, in every program unit that needs to use my work. I don’t want them to be able to access the low level Stack, Dictionary, etc. stuff so to get round FTN95’s insistence on ignoring the blank PRIVATE statement for imported entities, I explicitly declare these entities as PRIVATE in my intermediate and top level modules. Of course, they could still access these entities after writing USE Stack, for example, but that would be going against my advice – so my back is covered.
But hang on a minute. These low level Stack, Dictionary, etc modules are generic enough that I might want to make use of them in other projects. When I do, I am again unlikely to want these low level esoteric entities to be propagated up any hierarchy of modules. So whenever I use one of these low level modules I must place the following statement in the using module.
PRIVATE :: esoteric_entity_1, &
esoteric_entity_2, &
….
esoteric_entity_n
I think that is a pain but, more importantly, I think it compromises the ease and safety of the module usage.
I suppose this could all be argued and discussed till the cows come home. Perhaps you are right in suggesting that I am thinking in a non-Fortran manner. If that is the case, then I must say I am disappointed in the direction Fortran is taking the Module concept. However, just as you flagged the existence of another compiler that does it the FTN95 way, I can say that I am using a very well known compiler that does it my way.
Regards
Keith