Re: A question about OOP in Fortran?



glen herrmannsfeldt wrote:
James Giles wrote:
....
The advantage, though, is that in some cases one can write a
routine that will work with any class. My examples earlier
being a sort routine that can sort any type of object,

Bet it can't. Many types don't have an ordering relation
defined on them. Nor can the concept of ordered types
be placed within a hierarchical type system (for example,
not all numbers are ordered and not all ordered types are
numeric). You *can* write a generic sorting routine with
other types of polymorphism, but not with inheritance
based polymorphism.

or a hash table that can hold any type of object reference.

I can do that in my language as well. No inheritance feature
is needed or appropriate. Like arrays, any collection mechanism
is a non-type attribute, not a type. And you can define and
implement your own attributes. The concept implemented by
such attributes is independent of base type (just like arrays).
So you can declare a hash table with any base type. But any
individual table contains only elements of it's declared base
type. If you want a heterogenous collection (array, string, list,
hash table, etc.) you must declare a variant type to use as the
base type of such a collection. Any hash table of that base type
is still limited to only the types explicitly permitted by the
declaration of the variant type. All testable at compile time.
Can't do that with inheritance.

Once in a very great while I want to have a collection which
can contain heterogenous types. But, I *never* want to allow
the collection to contain just *any* arbitrary elements. I still
want the compiler to check that all values are of the set of
types (two or three usually - never more than about a dozen)
that I want to allow. Fortran (among many other languages)
fails to have that capability - which requires the declaration
of a variant derived type. Evidently Java fails to provide
the feature as well. Allowing heterogenous references or
collections without constraining the allowed varieties is
worse than not having such heterogenous features at all.

Java will check at compile time what can be checked, and
at run time, otherwise. As with bounds checking, it is
not optional.

Fine. But it won't diagnose anything that's legal within the
language. If your array permits *any* type, the language can
hardly refuse assignment to that array no matter what type
is being assigned. How do limit what type is allowed in
a particular array if the mechanism you choose was to declare
an array whose "base type" is the class of all objects?

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare


.



Relevant Pages

  • Re: A question about OOP in Fortran?
    ... being a sort routine that can sort any type of object, ... So you can declare a hash table with any base type. ... If you want a heterogenous collection (array, string, list, ...
    (comp.lang.fortran)
  • Re: Array with unknown number of dimensions
    ... > In your routine, just declare the array to be or rank 1, doing any ... When you pas the array as an actual ... > as the user routine declares the dummy array to be either explicit ... user to declare a large number of extra variables, ...
    (comp.lang.fortran)
  • Re: huge 2-D array
    ... The problem is probably just that it is a big array. ... I'm going to guess further that the OP is trying to declare that array ... allow for local variables. ... clear up the problem for the OP, if the routine is not called recursively. ...
    (comp.lang.c)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)
  • Re: vb.net class
    ... about fixed array lenghts or using ReDim statements. ... code ensures everything in the array is a String because you declare it ... Count can be generated from the time list, not need to store ...
    (microsoft.public.dotnet.languages.vb)

Loading