Re: A question about OOP in Fortran?
- From: "James Giles" <jamesgiles@xxxxxxxxxxxxxxxx>
- Date: Wed, 18 Jul 2007 02:42:28 GMT
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
.
- Follow-Ups:
- Re: A question about OOP in Fortran?
- From: glen herrmannsfeldt
- Re: A question about OOP in Fortran?
- References:
- Re: A question about OOP in Fortran?
- From: Arjen Markus
- Re: A question about OOP in Fortran?
- From: Colin Paul Gloster
- Re: A question about OOP in Fortran?
- From: glen herrmannsfeldt
- Re: A question about OOP in Fortran?
- From: Colin Paul Gloster
- Re: A question about OOP in Fortran?
- From: glen herrmannsfeldt
- Re: A question about OOP in Fortran?
- From: James Giles
- Re: A question about OOP in Fortran?
- From: glen herrmannsfeldt
- Re: A question about OOP in Fortran?
- From: James Giles
- Re: A question about OOP in Fortran?
- From: glen herrmannsfeldt
- Re: A question about OOP in Fortran?
- Prev by Date: Re: Sun Studio 12 available for download
- Next by Date: Re: A question about OOP in Fortran?
- Previous by thread: Re: A question about OOP in Fortran?
- Next by thread: Re: A question about OOP in Fortran?
- Index(es):
Relevant Pages
|
Loading