[J3] [EXTERNAL] Elemental type-bound functions not useful

Vipul Parekh parekhvs at gmail.com
Tue Mar 30 00:34:03 UTC 2021


On Mon, Mar 29, 2021 at 5:04 PM Van Snyder via J3 <j3 at mailman.j3-fortran.org>
wrote:

> ..
> Without a type-bound procedure, you can't have a generic binding. So
> instead of
>
> use MyModule, only: MyType
>
> you need
>
> use MyModule, only: MyType, operator(+), operator(-), operator(*),
> operator(/), operator(**), operator(==), &
> operator(/=), operator(>), operator(<), operator(>=), operator(<=), cos,
> sin, exp, log, abs, dot_product, matmul, ....
>
> or just
>
> use MyModule
>
> The advantage of the former, which many organizations' style guides
> require, is that by looking only at the module where it's used, you can see
> where everything comes from, rather than using "grep" to find it. ..
>


Note the "many organizations' style guides" increasingly also refer to code
design *requirements* that stipulate the use of OO design to avoid *deep*
hierarchies and that subclassing, if employed, be limited to one level only.

Thus the code design -  should it involve OO - often follows considerable
OO analysis (OOA) and design (OOD) before commencing to the OOP stage.
Inheritance is increasingly limited to a well-designed ABSTRACT base class
from which various SEALED (or INEXTENSIBLE) types are subclassed, thus 1
level of hierarchy.

For the use case mentioned by Van here involving ELEMENTAL operations of
the type 'A = B + C', I personally think the code design should have the
objects 'A", ''B', 'C' as all nonpolymorphic - they can be
ALLOCATABLE/POINTER - but they can all be of the same dynamic type that is
an extension of an ABSTRACT derived type but which is itself inextensible.

When better 'namespace' management and/or good coding practice involving
the ', ONLY' clause, etc. are to pursued, I think the facility proposed in
https://j3-fortran.org/doc/year/19/19-186.txt can prove to be the solution.

Vipul Parekh


>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210329/b54d6df9/attachment-0003.htm>


More information about the J3 mailing list